Re: Custom widget for a modelform field

2010-03-08 Thread Daniel Roseman
On Mar 9, 7:20 am, Odd  wrote:
> It works fine if I'm not using a modelform, i.e.
>
> class MyForm(forms.Form):
>    data=forms.CharField(widget=MySelect())
>
> Can one not use a custom widget in a modelform?
>
> Thanks.

The 'widgets' argument is new in the development version, it's not in
1.1. (I raised a documentation bug ages ago to mark this, but it has
never been applied.)

However, the syntax you give above works just as well for modelforms,
so you can use that.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom widget for a modelform field

2010-03-08 Thread andreas schmid
i have customized multiselect widget on a model field and it works like
this:

class MyModelForm(ModelForm):
field  = ModelMultipleChoiceField(MyOtherModel.objects,
required=False, widget=MultipleSelectWithPop)
class Meta:
model = MyModel

let me know!

Odd wrote:
> It works fine if I'm not using a modelform, i.e.
>
> class MyForm(forms.Form):
>data=forms.CharField(widget=MySelect())
>
> Can one not use a custom widget in a modelform?
>
> Thanks.
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom widget for a modelform field

2010-03-08 Thread Odd
It works fine if I'm not using a modelform, i.e.

class MyForm(forms.Form):
   data=forms.CharField(widget=MySelect())

Can one not use a custom widget in a modelform?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django registration not showing logged in on all pages

2010-03-08 Thread Kenneth Gonsalves
On Tuesday 09 Mar 2010 11:01:59 am Duvalfan23 wrote:
> Not that Im aware of. Im using the built in auth methods as of now for
> login and logout. Im kind of a django newbie. Im not quite sure what
> you mean by that. Ill try to go look up some documentation on it But
> if you have any great info on that please let me know. Thanks!!
> 

http://docs.djangoproject.com/en/dev/ref/templates/api/#id1
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Extending a custom built API

2010-03-08 Thread Nick
Thanks, I did a little changing around but what you recommended was
spot on. Here is the final view

def slideshowAPI2(request):
error = False
if 'id' in request.GET and request.GET['id']:
id = request.GET.get('id')
ids = id.split(',')
object = slideshow.objects.filter(id__in=ids)
return render_to_response('slideshow.json', {'object':
object})
if 'year' in request.GET and request.GET['year']:
year = request.GET['year']
object = serializers.serialize("json",
slideshow.objects.filter(publishdate__year=year))
html = "%s" % object
return HttpResponse(html)
else:
error = True
return render_to_response('slideshow.json', {'error': True})


On Mar 8, 5:18 pm, felix  wrote:
> you are already basically there
>
> id = request.GET.get('id')
> if id:
>   ids = id.split(',')
>   slideshows = slideshow.objects.filter(id__in=ids)
>
> then returns that as json however you like
>
> On Mar 8, 11:41 pm, Nick  wrote:
>
> > I am working on an api that outputs a list of JSON based on certain
> > criteria.  Currently if someone 
> > entershttp://example.mysite/slideshows/api?id=1
> > it returns a JSON serialized output of the slideshow with that ID.
>
> > What I would like to do is allow for multiple ids, 
> > sohttp://example.mysite/slideshows/api?id=1,2,5,9,10willpull in JSON
> > values for each of those slideshows.
>
> > I'd like to keep from using a third party API solution, I have checked
> > them out and I like the customization with the hand built process
>
> > I am doing everything through a get process in a view, here it is:
>
> > def slideshowAPI2(request):
> >     error = False
> >     if 'id' in request.GET and request.GET['id']:
> >         id = request.GET['id']
> >         object = slideshow.objects.get(pk=id)
> >         return render_to_response('slideshow.json',
> >             {'object': object, 'id':id})
> >     if 'year' in request.GET and request.GET['year']:
> >         year = request.GET['year']
> >         object = serializers.serialize("json",
> > slideshow.objects.filter(publishdate__year=year))
> >         html = "%s" % object
> >         return HttpResponse(html)
> >     else:
> >         error = True
> >         return render_to_response('slideshow.json', {'error': True})

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django registration not showing logged in on all pages

2010-03-08 Thread Duvalfan23
Not that Im aware of. Im using the built in auth methods as of now for
login and logout. Im kind of a django newbie. Im not quite sure what
you mean by that. Ill try to go look up some documentation on it But
if you have any great info on that please let me know. Thanks!!

On Mar 9, 12:23 am, Kenneth Gonsalves  wrote:
> On Tuesday 09 Mar 2010 7:23:35 am Duvalfan23 wrote:
>
> > I have started a Django application with the Django Registration from
> > GoogleCode included also. I built a menu that has certain menu items
> > only viewable by logged in users. My login page is ~/login/ and
> > register page is ~/register/. Whenever I log in, the logged in menu
> > shows up on the Login and Register pages, but no other pages. Why
> > would this happen? My session cookie is set as default which the path
> > is '/'.. Any help would be appreciated. Thanks!
>
> are you using RequestContext and do you have the appropriate
> TEMPLATE_CONTEXT_PROCESSORS loaded in settings.py?
>
> --
> regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSShttp://certificate.nrcfoss.au-kbc.org.in

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django registration not showing logged in on all pages

2010-03-08 Thread Kenneth Gonsalves
On Tuesday 09 Mar 2010 7:23:35 am Duvalfan23 wrote:
> I have started a Django application with the Django Registration from
> GoogleCode included also. I built a menu that has certain menu items
> only viewable by logged in users. My login page is ~/login/ and
> register page is ~/register/. Whenever I log in, the logged in menu
> shows up on the Login and Register pages, but no other pages. Why
> would this happen? My session cookie is set as default which the path
> is '/'.. Any help would be appreciated. Thanks!
> 

are you using RequestContext and do you have the appropriate 
TEMPLATE_CONTEXT_PROCESSORS loaded in settings.py?

-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modes.ManyToManyField and Users

2010-03-08 Thread krayel
Nevermind, figured it out.

On Mar 8, 2:22 pm, krayel  wrote:
> Right now I have model which is basically:
>
> class Student(models.Model):
>   name = models.CharField(max_length=150)
>   id = models.IntegerField(primary_key=True)
>
> and another model which refers to it:
>
> class ServiceHours(models.Model):
>   students = models.ManyToManyField(Student)
>   category = models.ForeignKey(Category)
>   hours = models.IntegerField()
>   date = models.DateTimeField(auto_now_add=True)
>
> Since every Student will also have their own User account, the student
> object is pretty much redundant as it only holds a name and id.
> Secondly, since the only thing that will eventually relate the two
> objects together is a student id/name match, and not an actual
> reference, the whole process may easily fail from human error
> (misspelling a name or id). Is there a way to create a ManyToManyField
> that refers to all Users? That way there would be less redundancy and
> names/ids need only be entered once thereby reducing the risk of a
> mistake in data entry.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to use pre-built HTML forms in Django

2010-03-08 Thread MMRUser
Thanks another doubt,what about the css mappings class="field text
medium" do they also need to include in the class definition in
Django.

On Mar 9, 9:21 am, rebus_  wrote:
> On 9 March 2010 05:04, MMRUser  wrote:
>
>
>
> > I have an pre-built HTML form (means I design the HTML form
> > separately) and I need to reuse it with Django form class
> > (django.forms), So how do I incorporate my HTML form with Django form
> > class. for example
>
> > HTML:
>
> > 
> >  
> >  Username
> >  *
> >  
> >  
> >  
> >  
> > 
>
> > How do I map this HTML in to Django form definition, I know that it
> > can be done by modifying Django form fields according to this HTML.
> > But I guess it's a time consuming approach,so I would like to know
> > that is there any easy and time saving solutions for this issue.
>
> > Thanks.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> Well usually you first create a form in django and use its instance to
> generate the HTML.
>
> You can also write the HTML by yourself and all you need to be careful
> of is that name and id attributes of you inputs and input type are
> same as in the class you define.
>
> Your HTML corresponds to:
>
> class MyForm(forms.Form):
>    Field11 = forms.CharField(label="Username",  max_length=255)
>
> I highly recommend to first setup a form class then write HTML and
> making form fields have more sensible names then Field11.
>
> Also i suggest these links as further reading:
>
> http://docs.djangoproject.com/en/dev/topics/forms/http://docs.djangoproject.com/en/dev/ref/forms/api/http://docs.djangoproject.com/en/dev/ref/forms/fields/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How to use pre-built HTML forms in Django

2010-03-08 Thread rebus_
On 9 March 2010 05:04, MMRUser  wrote:
> I have an pre-built HTML form (means I design the HTML form
> separately) and I need to reuse it with Django form class
> (django.forms), So how do I incorporate my HTML form with Django form
> class. for example
>
> HTML:
>
> 
>  
>  Username
>  *
>  
>  
>  
>  
> 
>
> How do I map this HTML in to Django form definition, I know that it
> can be done by modifying Django form fields according to this HTML.
> But I guess it's a time consuming approach,so I would like to know
> that is there any easy and time saving solutions for this issue.
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

Well usually you first create a form in django and use its instance to
generate the HTML.

You can also write the HTML by yourself and all you need to be careful
of is that name and id attributes of you inputs and input type are
same as in the class you define.

Your HTML corresponds to:

class MyForm(forms.Form):
   Field11 = forms.CharField(label="Username",  max_length=255)


I highly recommend to first setup a form class then write HTML and
making form fields have more sensible names then Field11.

Also i suggest these links as further reading:

http://docs.djangoproject.com/en/dev/topics/forms/
http://docs.djangoproject.com/en/dev/ref/forms/api/
http://docs.djangoproject.com/en/dev/ref/forms/fields/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: join channel #django

2010-03-08 Thread rebus_
On 9 March 2010 05:02, sajuptpm  wrote:
> I cant join #django,
>
> [09:20] [Channel] Cannot join channel (+r) - you need to be identified
> with services
>
> What is the problem?. How join this channel?. What are the other
> popular django channels?.
>
> Please help me.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

Maybe this could help

http://freenode.net/faq.shtml#nicksetup

The error message says you need to be registered before joining the channel.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



join channel #django

2010-03-08 Thread sajuptpm
I cant join #django,

[09:20] [Channel] Cannot join channel (+r) - you need to be identified
with services

What is the problem?. How join this channel?. What are the other
popular django channels?.

Please help me.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How to use pre-built HTML forms in Django

2010-03-08 Thread MMRUser
I have an pre-built HTML form (means I design the HTML form
separately) and I need to reuse it with Django form class
(django.forms), So how do I incorporate my HTML form with Django form
class. for example

HTML:


 
  Username
 *
 
 
  
 


How do I map this HTML in to Django form definition, I know that it
can be done by modifying Django form fields according to this HTML.
But I guess it's a time consuming approach,so I would like to know
that is there any easy and time saving solutions for this issue.

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Django registration not showing logged in on all pages

2010-03-08 Thread Duvalfan23
I have started a Django application with the Django Registration from
GoogleCode included also. I built a menu that has certain menu items
only viewable by logged in users. My login page is ~/login/ and
register page is ~/register/. Whenever I log in, the logged in menu
shows up on the Login and Register pages, but no other pages. Why
would this happen? My session cookie is set as default which the path
is '/'.. Any help would be appreciated. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



multipart/form-data and HttpResponse

2010-03-08 Thread inna
Hi,

How can I return both an image file and some text fields with
HttpResponse?  It seems that the image file gets stripped under my
current method. Here is an excerpt:

photofile = open(photo_filepath, "rb")

data = {}
data['msg1'] = 'testmsg'
data['msg2'] = 'testmsg2'
data['msg3'] = 'testmsg3'
json = simplejson.dumps(data)

myContent = {}
myContent['json'] = json
myContent['photofile'] = photofile

return HttpResponse(content = myContent, mimetype='multipart/
form-data')

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Adding a new convenience filter 'contains_any'

2010-03-08 Thread Russell Keith-Magee
On Tue, Mar 9, 2010 at 3:24 AM, Phlip  wrote:
>> > And if the PEP8 told you to ... just jump off a cliff... would you?
>>
>> Sounds like you might benefit from actually reading it:
>
> This thread arc is about me lamenting the positive value of style
> guides, even those with wrong line-items.
>
> Nobody here has said to get creative with any style guideline, or
> disobey it.

No - seriously: Have you read PEP8? The opening paragraphs of PEP8
address this exact point.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Extending a custom built API

2010-03-08 Thread felix

you are already basically there

id = request.GET.get('id')
if id:
  ids = id.split(',')
  slideshows = slideshow.objects.filter(id__in=ids)

then returns that as json however you like



On Mar 8, 11:41 pm, Nick  wrote:
> I am working on an api that outputs a list of JSON based on certain
> criteria.  Currently if someone 
> entershttp://example.mysite/slideshows/api?id=1
> it returns a JSON serialized output of the slideshow with that ID.
>
> What I would like to do is allow for multiple ids, 
> sohttp://example.mysite/slideshows/api?id=1,2,5,9,10will pull in JSON
> values for each of those slideshows.
>
> I'd like to keep from using a third party API solution, I have checked
> them out and I like the customization with the hand built process
>
> I am doing everything through a get process in a view, here it is:
>
> def slideshowAPI2(request):
>     error = False
>     if 'id' in request.GET and request.GET['id']:
>         id = request.GET['id']
>         object = slideshow.objects.get(pk=id)
>         return render_to_response('slideshow.json',
>             {'object': object, 'id':id})
>     if 'year' in request.GET and request.GET['year']:
>         year = request.GET['year']
>         object = serializers.serialize("json",
> slideshow.objects.filter(publishdate__year=year))
>         html = "%s" % object
>         return HttpResponse(html)
>     else:
>         error = True
>         return render_to_response('slideshow.json', {'error': True})

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import errors when starting django on staging server, no errors on local dev server

2010-03-08 Thread Graham Dumpleton


On Mar 9, 9:50 am, felix  wrote:
> thanks for the offer, but as I said : the problem is long since
> solved.  it was a circular import problem.
> I reworked the imports and its gone.
>
> my question was:  how could it have happened on the staging server and
> not on the dev server ?

As I said before, it is impossible to say as you provided insufficient
detail.

> I was just asking around to see if anybody had seen that kind of
> behavior before and knew a likely explanation.
>
> and primarily how I can detect such problems in the future before I've
> deployed it to a live site.

As I suggested before, consider doing some measure of development on
the same hosting mechanism as you intend to deploy with. The Django
runserver does magic stuff which other hosting mechanisms don't,
including preloading and special importing of modules before any
requests arrive. It is arguable that it should not do this, or that
Django should provide a better WSGI entry point for WSGI hosting
mechanisms, that ensures that the same level of presetup is done to
mirror what runserver does. If this isn't done, you are always going
to end up with subtle differences that have to be dealt with.

Graham

> On Mar 8, 10:39 pm, Graham Dumpleton 
> wrote:
>
>
>
> > It is almost impossible to suggest anything about your problem as you
> > don't post the complete details of the actual errors you are getting.
> > If you want solutions, you need to provide that extra information so
> > we don't have to imagine what the Python exception and traceback you
> > are getting is.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import errors when starting django on staging server, no errors on local dev server

2010-03-08 Thread felix

thanks for the offer, but as I said : the problem is long since
solved.  it was a circular import problem.
I reworked the imports and its gone.

my question was:  how could it have happened on the staging server and
not on the dev server ?

I was just asking around to see if anybody had seen that kind of
behavior before and knew a likely explanation.

and primarily how I can detect such problems in the future before I've
deployed it to a live site.




On Mar 8, 10:39 pm, Graham Dumpleton 
wrote:
> It is almost impossible to suggest anything about your problem as you
> don't post the complete details of the actual errors you are getting.
> If you want solutions, you need to provide that extra information so
> we don't have to imagine what the Python exception and traceback you
> are getting is.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Extending a custom built API

2010-03-08 Thread Nick
I am working on an api that outputs a list of JSON based on certain
criteria.  Currently if someone enters http://example.mysite/slideshows/api?id=1
it returns a JSON serialized output of the slideshow with that ID.

What I would like to do is allow for multiple ids, so
http://example.mysite/slideshows/api?id=1,2,5,9,10 will pull in JSON
values for each of those slideshows.

I'd like to keep from using a third party API solution, I have checked
them out and I like the customization with the hand built process

I am doing everything through a get process in a view, here it is:


def slideshowAPI2(request):
error = False
if 'id' in request.GET and request.GET['id']:
id = request.GET['id']
object = slideshow.objects.get(pk=id)
return render_to_response('slideshow.json',
{'object': object, 'id':id})
if 'year' in request.GET and request.GET['year']:
year = request.GET['year']
object = serializers.serialize("json",
slideshow.objects.filter(publishdate__year=year))
html = "%s" % object
return HttpResponse(html)
else:
error = True
return render_to_response('slideshow.json', {'error': True})

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modify date in django twitter app

2010-03-08 Thread Nick
I think this may help

http://www.magpiebrain.com/2005/08/21/formatting-dates-with-django/

try using strftime and formatting from there.

On Mar 8, 3:16 pm, "het.oosten"  wrote:
> I forgot to mention that my desired output of the date is:
> 2010-02-22 20:46:03
>
> On 8 mrt, 22:13, "het.oosten"  wrote:
>
> > I am getting somewhere now:
>
> > import datetime
> > import time
> > import twitter
>
> > tweet  = twitter.Api().GetUserTimeline('username', count=3)
> > for s in tweet:
> >         s.date = datetime.datetime(*(time.strptime( s.created_at,"%a
> > %b %d %H:%M:%S + %Y" )[0:6]))
> > print [x.text for x in tweet]
> > print [y.date for y in tweet]
>
> > However the output is now:
> > [datetime.datetime(2010, 3, 1, 16, 51, 55), datetime.datetime(2010, 2,
> > 22, 20, 46, 3), datetime.datetime(2010, 2, 20, 10, 16, 2)]
>
> > I still miss a little thing to completeanybody a little hint?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to QuerySet.add(multiple objects)

2010-03-08 Thread Sentenza
my_fruit.apple_plant.fruit_set.all().update(weird_plant = weird_plant)

cheers.

On Mar 8, 7:22 pm, Sentenza wrote:
> Hi,
>
> i'd like to hang some fruits belonging to an 'apple plant' also onto
> another 'weird plant' -- for this i'm iterating over all fruits on the
> apple plant, like this (i'm starting with one apple as my_fruit):
>
> for more_fruit in my_fruit.apple_plant.fruit_set.all():
>     weird_plant.fruit_set.add(more_fruit)
>
> unfortunately i cannot add them in one go:
>
> weird_plant.fruit_set.add(my_fruit.apple_plant.fruit_set.all())
>
> i also tried .add(list(..))
>
> in raw sql this would be done as in:
> UPDATE fruit SET weird_plant_id = %s WHERE apple_plant_id = %s,
> [weird_plant.id, my_fruit.apple_plant_id]
>
> do i really have to loop over the items in _set?
>
> thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import errors when starting django on staging server, no errors on local dev server

2010-03-08 Thread Graham Dumpleton
It is almost impossible to suggest anything about your problem as you
don't post the complete details of the actual errors you are getting.
If you want solutions, you need to provide that extra information so
we don't have to imagine what the Python exception and traceback you
are getting is.

FWIW, you can use Apache/mod_wsgi as a development server. The only
significant thing you miss in its default configuration is automatic
restarts when code is changed. For that, you either manually touch the
WSGI script file to trigger a restart (in daemon mode) when you have
completed a set of changes, or employ the additional recipe to Apache/
mod_wsgi to have it reload code automatically. By doing development
under Apache/mod_wsgi your almost certain to come across the problems
before deployment.

Have a read of:

  http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
  http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django.html
  http://blog.dscpl.com.au/2009/02/source-code-reloading-with-modwsgi-on.html

Graham

On Mar 9, 12:30 am, felix  wrote:
> On Mar 8, 1:25 am, Graham Dumpleton 
> wrote:
>
> > You don't say anything about what hosting mechanisms you are using for
> > each.
>
> local: django's runserver
> staging: mod_wsgi apache
>
> one thing I should do is test locally using wsgi
>
> Do you have any suggestions regarding question 2:
>
> how can I do a quick test on the deployment environment to trigger
> these import errors ?
>
> I opened a manage.py shell and ran the same code as in my .wsgi
> ...
> application = django.core.handlers.wsgi.WSGIHandler()
>
> no problems.
>
> earlier I said it was during start up. that's wrong, it was after
> loading some pages.
>
> specifically if I loaded one page as the first load, then it triggered
> the import error.
> if I loaded the front page it did not.  that would be hell on a live
> site.
>
> this is of course a clue to the problem, but I'm not trying to solve
> the problem.  I already solved that one.
>
> I'm trying to find a way to detect Unknown Unknowns.
>
> so probably I need to do a few requests using that test WSGIHandler
>
> I also saw it returning a 404 for an admin page, but only for 1 out of
> every 4 requests !  yep, I have 4 threads on the WSGIDaemonProcess.
> and one of them loaded up the admin wrong.  a restart fixed it.
>
> another thing I'm thinking about is a way to notify me by email when
> an exception escapes django's grasp and gives that black and white
> apache 500 notification.
>
> it should be possible to just wrap that WSGIHandler with a simple wsgi
> app, catch any exceptions, email quickly and then return a simple html
> display.
>
> there needs to be one more line of defense.
>
>
>
> > The Django runserver does extra automagic setup steps which aren't by
> > default going to be done by other hosting mechanisms. Part of this is
> > solved by manual setup of sys.path, but not necessarily all that is
> > necessary.
>
> > Graham

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modify date in django twitter app

2010-03-08 Thread het.oosten
I forgot to mention that my desired output of the date is:
2010-02-22 20:46:03

On 8 mrt, 22:13, "het.oosten"  wrote:
> I am getting somewhere now:
>
> import datetime
> import time
> import twitter
>
> tweet  = twitter.Api().GetUserTimeline('username', count=3)
> for s in tweet:
>         s.date = datetime.datetime(*(time.strptime( s.created_at,"%a
> %b %d %H:%M:%S + %Y" )[0:6]))
> print [x.text for x in tweet]
> print [y.date for y in tweet]
>
> However the output is now:
> [datetime.datetime(2010, 3, 1, 16, 51, 55), datetime.datetime(2010, 2,
> 22, 20, 46, 3), datetime.datetime(2010, 2, 20, 10, 16, 2)]
>
> I still miss a little thing to completeanybody a little hint?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modify date in django twitter app

2010-03-08 Thread het.oosten
I am getting somewhere now:

import datetime
import time
import twitter

tweet  = twitter.Api().GetUserTimeline('username', count=3)
for s in tweet:
s.date = datetime.datetime(*(time.strptime( s.created_at,"%a
%b %d %H:%M:%S + %Y" )[0:6]))
print [x.text for x in tweet]
print [y.date for y in tweet]

However the output is now:
[datetime.datetime(2010, 3, 1, 16, 51, 55), datetime.datetime(2010, 2,
22, 20, 46, 3), datetime.datetime(2010, 2, 20, 10, 16, 2)]

I still miss a little thing to completeanybody a little hint?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



modes.ManyToManyField and Users

2010-03-08 Thread krayel
Right now I have model which is basically:

class Student(models.Model):
  name = models.CharField(max_length=150)
  id = models.IntegerField(primary_key=True)

and another model which refers to it:

class ServiceHours(models.Model):
  students = models.ManyToManyField(Student)
  category = models.ForeignKey(Category)
  hours = models.IntegerField()
  date = models.DateTimeField(auto_now_add=True)

Since every Student will also have their own User account, the student
object is pretty much redundant as it only holds a name and id.
Secondly, since the only thing that will eventually relate the two
objects together is a student id/name match, and not an actual
reference, the whole process may easily fail from human error
(misspelling a name or id). Is there a way to create a ManyToManyField
that refers to all Users? That way there would be less redundancy and
names/ids need only be entered once thereby reducing the risk of a
mistake in data entry.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Adding a new convenience filter 'contains_any'

2010-03-08 Thread Phlip
> > And if the PEP8 told you to ... just jump off a cliff... would you?
>
> Sounds like you might benefit from actually reading it:

This thread arc is about me lamenting the positive value of style
guides, even those with wrong line-items.

Nobody here has said to get creative with any style guideline, or
disobey it.

> http://www.python.org/dev/peps/pep-0008/

> "Bureaucrat Conrad, you are technically correct -- the best kind of correct."

(-:

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Problems with django-ajax-filtered-fields and ManyToManyByRelatedField

2010-03-08 Thread Sandra Django
Hi friends, someone has worked with django-ajax-filtered-fields? I'm having
problems with ManyToManyByRelatedField. The syntax is very simple, I think
that it isn't the problem.
I have an "Author" class that it has a ForeignKey field named "type", and I
want to filter for this field in the form.
In my forms.py I wrote: author = ManyToManyByRelatedField(Author, "type")
and I'm using ajax_filtered_fields.js and jquery.js files.
Two boxes displays in the form (Availables and Selected), and on the top of
"Available" box, I can see the values that the "type" field could take (in
this case, Individual and Corporative). But when I select one of options,
the "Availables" box is empty, it couldn't filter. Why? Missing any file to
include? There is a syntax error in my forms.py?
Thanks,
Sandra

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Odd behaviour with forms and i18n

2010-03-08 Thread Martin Ostrovsky
Perhaps somebody could explain exactly what's going on.

I have a form whose labels are translatable strings:

class MyForm(forms.Form):

   field1 = forms.CharField(label=_('Label 1'), max_length=20)

I generated the .po files, supplied the translations, generated
the .mo files, added the proper middleware etc. All of the necessary
bits for i18n are turned on and working. The odd behaviour I'll see is
that after the first translation takes place by POSTing to /i18n/
setlang/ (for example, to french) all subsequent page loads will
render the french translation instead of the language code currently
defined in request.session['django_language']. So if I switch to
spanish, I still see french labels. If I restart apache and load the
page with spanish set as the language, now the spanish translation
comes through properly, but again, from here on in, even when I switch
to french, the spanish one always shows.

I'm guessing this has to do with how python modules are loaded and the
form class is loaded once the first time, translation takes place and
that's it (until server reload). I've got around this by setting the
label in an overloaded __init__ call. For example:

def __init__(self, *args, **args):
self.fields['field1'].label = _(self.fields['field1'].label)

Anybody else seen this before? Is my intuition right?

FWIW, django is version 1.2-pre alpha r11616, apache2/mod_wsgi.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



validation on many2many fields

2010-03-08 Thread Alessandro Pasotti
Hello,

I need to do both form level  and model level validation (my app will be
called by XML-RPC and it will also be used with the normal admin GUI) on a
m2m relation.

The problem is that I have a m2m between "Items" and "Categories",
"Categories" are organized in a tree with MPTT django-mptt. I want to avoid
that "Items" are assigned to non-leaf "Categories".

It seems like "save_m2m" (for forms) and "add" (for models) are created at
runtime and it's not easy to override them.

I'm using latest trunk and google'd searching for a solution, before going
down to the DB level with some triggers and checks, does anybody have any
idea or suggestion about if and how this could be done?


-- 
Alessandro Pasotti
w3:   www.itopen.it

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Scrape a file, then put it in the django database

2010-03-08 Thread Michael Lissner
Thanks Daniel. I guess that part makes sense, but what I'd really like
to do is use the FileField itself to place the file in the right place.
I thought that with a file that was submitted from a form field, that
this was possible (and indeed the intended purpose). I'm confused why it
seems like I have to reverse engineer my design to put the file where
the FileField expects it, and then give FileField a value that
corresponds to that location.

Isn't that the whole idea of the FileField itself?


Daniel Hilton wrote on 03/08/2010 01:35 AM:
> On 8 March 2010 07:45, mjlissner  wrote:
>   
>> I'm trying to write a program that scrapes all the pdfs off of this
>> page:
>> http://www.ca3.uscourts.gov/recentop/week/recprec.htm
>>
>> And then puts them onto my hard drive, with the reference to their
>> location in a FileField.
>>
>> I've defined a FileField in my model, and I believe I can scrape the
>> site OK (though my code needs improvement), but I can't for the life
>> of me figure out how to go from "here's my file" to "I've placed my
>> file in the right directory, and there's a reference in my database to
>> it - awesome."
>>
>> I could give more details, but I'm not entirely sure they'd be
>> helpful. Essentially, I just want to know how to download a PDF, and
>> store it locally, while updating the django db to point to it
>> appropriately.
>>
>> So far, I've been very much unable to pull this off...
>>
>> Thanks,
>>
>> Mike
>> 
> I'd write a management command that wraps around a couple of functions:
>
>
> * One that gets the file and stores it locally using urllib2
> * One that then takes the file and saves it in your model. (Have a
> google for using django orm without the full django stack)
>
> The thing to remember is to be nice when scraping and check that your
> use of the data is legal.
>
> You could break out the two parts and have one script that downloads
> all teh files to a folder, then another that imports them all.
>
> HTH
> Dan
>
>
>
>
>
>
>
>
>
>
>
>   
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>> 
>
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



how to QuerySet.add(multiple objects)

2010-03-08 Thread Sentenza
Hi,

i'd like to hang some fruits belonging to an 'apple plant' also onto
another 'weird plant' -- for this i'm iterating over all fruits on the
apple plant, like this (i'm starting with one apple as my_fruit):

for more_fruit in my_fruit.apple_plant.fruit_set.all():
weird_plant.fruit_set.add(more_fruit)

unfortunately i cannot add them in one go:

weird_plant.fruit_set.add(my_fruit.apple_plant.fruit_set.all())

i also tried .add(list(..))

in raw sql this would be done as in:
UPDATE fruit SET weird_plant_id = %s WHERE apple_plant_id = %s,
[weird_plant.id, my_fruit.apple_plant_id]

do i really have to loop over the items in _set?

thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



verbose_name for ManyToManyField

2010-03-08 Thread summea
I'm working my way through the Django Book and creating a simple books
app inside the tutorial project.  I have the following class:

class Book(models.Model):
...
def get_authors(self):
return self.authors.all()


And I am using that get_authors() method to find all authors for a
particular book.  All of that works fine... but in all my searching, I
haven't been able to find a clue as to how to use something like
verbose_name to set the column name of this get_authors method.

For example, I have a table that lists all of the Book(s) in the
database.  So naturally I have a table with labels at the top of each
table column:

Title  /  Get authors  /  Publisher


But I would like the table columns to look something like this:

Title  /  Authors  /  Publisher


But verbose_name='authors' doesn't seem to work in this case.  Is
there something I'm missing?

Thanks for any pointers.
Andy

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Migration sqlite3 (localhost) to MySQL (Shared-Hosting)

2010-03-08 Thread Daniel Roseman
On Mar 8, 5:10 pm, Egon Frerich  wrote:

> Daniel Roseman schrieb:
> | On Mar 8, 3:02 pm, Egon Frerich  wrote:
> |> Hello,
> |>
> |> is there a HowTo for migrating a working test environment on localhost
> |> with sqlite3 to a shared-hosting provider on Apache with MySQL? Chapter
> |> 12 of the books tells nothing about migrating the database. I cannot
> |> find something in the documentation.
> |>
> |> What is the equivalence to python manage.py syncdb for the production on
> |> Apache?
> |>
> |> Egon
> |
> | It's not really clear what you are asking here. Are you hoping to copy
> | actual data from an sqlite database to a MySQL one?
> | --
> | DR.
> |
>
> python manage.py syncdb creates the tables (and the superuser if I
> want). But I cannot use this command if I use a shared-hosting provider.
> Have I to create the MySQL tables manually by phpAdmin? Or should/can I
> export sqlite3 (maybe inclusive data) and import into MySQL?
>
> Egon

Why can't you use this command with a shared-hosting provider? I have
several sites on Webfaction, and have no problem using manage.py.

If you don't have any shell access at all, you are going to have more
problems than just this, and should consider switching provider.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django & wsgi: what is the preferred webserver?

2010-03-08 Thread Javier Guerra Giraldez
On Sun, Mar 7, 2010 at 4:21 PM, Shawn Milochik  wrote:
> Have a look here:
>
> http://code.djangoproject.com/wiki/ServerArrangements
>
> In general, you should have two Web servers (e.g. Apache and nginx or
> lighttpd). Apache (with mod_wsgi) to serve Django and nginx or lighttpd to
> serve the static files (CSS, JavaScript, images, etc.).

AFAICT, mod_wsgi can be 'separate enough', leaving Apache free to host
static files.

another setup is a light and fast server (lighttpd, nginx, cherokee)
plus Django on FastCGI.  again, it's two separate processes (web
server / FastCGI server).

in short, it seems that these days the main thing to avoid is
mod_python and static files on the same Apache instance.


-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Adding a new convenience filter 'contains_any'

2010-03-08 Thread James Bennett
On Mon, Mar 8, 2010 at 11:11 AM, Phlip  wrote:
> And if the PEP8 told you to ... just jump off a cliff... would you?

Sounds like you might benefit from actually reading it:

http://www.python.org/dev/peps/pep-0008/


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Adding a new convenience filter 'contains_any'

2010-03-08 Thread Phlip
> In this case, it's not just a team style guide - it's PEP8, which clearly 
> says:

And if the PEP8 told you to ... just jump off a cliff... would you?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Migration sqlite3 (localhost) to MySQL (Shared-Hosting)

2010-03-08 Thread Egon Frerich

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Daniel Roseman schrieb:
| On Mar 8, 3:02 pm, Egon Frerich  wrote:
|> Hello,
|>
|> is there a HowTo for migrating a working test environment on localhost
|> with sqlite3 to a shared-hosting provider on Apache with MySQL? Chapter
|> 12 of the books tells nothing about migrating the database. I cannot
|> find something in the documentation.
|>
|> What is the equivalence to python manage.py syncdb for the production on
|> Apache?
|>
|> Egon
|
| It's not really clear what you are asking here. Are you hoping to copy
| actual data from an sqlite database to a MySQL one?
| --
| DR.
|

python manage.py syncdb creates the tables (and the superuser if I
want). But I cannot use this command if I use a shared-hosting provider.
Have I to create the MySQL tables manually by phpAdmin? Or should/can I
export sqlite3 (maybe inclusive data) and import into MySQL?

Egon
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFLlS9oZRiDo9Iq4qIRAvDeAJ9W4aBL5gnIp0f08AEEc3zKHHYClACfQItH
2KT3RK6SOcw1JLDAdaM2Zyg=
=bQpa
-END PGP SIGNATURE-

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Python's Class members ...

2010-03-08 Thread JF Simon
Thanks for your *really* interesting explanations.
It seems more clear to me and I'm going to read all about
derscriptors !
Python is a facinating language ...


On 8 mar, 09:16, Masklinn  wrote:
> On 8 Mar 2010, at 09:01 , JF Simon wrote:
>
>
>
> > Hi dudes,
>
> > My object seems mysterious, as is my problem ... I'd like to
> > understand something (it's much more related to Python than Django).
>
> > Take an example :
>
> > class Image(models.Model):
> >    email = models.ForeignKey('Email', verbose_name=_(u'Email'))
> >    name = models.CharField(_(u'Name'), max_lenth=50,
> > help_text=_(u'Must be unique for a given email'))
> >    content_id = models.CharField(_(u'Content ID'), max_length=25,
> > db_index=True, default=self.slugify_name())
> >    [...]
>
> > "self" is not defined in the "default" kwarg for "content_id" field,
> > it's because I'm not in an instance method (with self as first
> > parameter). So what are those members, are they static for the class ?
> > What is the difference between them and a member instantiated in the
> > __init__ method whith self.field = [...] ?
>
> > If I replace the last field definition with :
>
> > from django.template.defaultfilters import slugify
> > [...]
> >    content_id = models.CharField(_(u'Content ID'), max_length=25,
> > db_index=True, default=slugify(name))
>
> > Eclipse don't show me an error ... will it work ? Why (not) ? I'm not
> > sure to understand what I'm doing and it's weird.
>
> It will 'work', but I doubt it's going to do what you want.
>
> Here are how python class definitions work:
>
> 1. The body of the class (anything after class YourName:) is parsed and 
> executed sequentially, as if it were module-level Python code (which is why 
> you can have a class inside a class, for instance)
> 2. *After* the body of the class has executed, all of its content (the 
> variables local to that body, which you can see by writing `print locals()` 
> at the end of the class body) is collected and set as *class attributes*, 
> with functions turned into methods.
>
> Because a class body is "just code", you can:
> 1. Use things defined outside the class body (models or slugify, in your 
> second snippet)
> 2. *Reference things previously defined in the body* (such as `name`).
>
> Finally, you might very well be doing unnecessary work: Django already 
> provides a SlugField 
> (http://docs.djangoproject.com/en/dev/ref/models/fields/#slugfield) which — 
> in the admin — can be prepopulated from your name using prepopulate_field 
> (http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...).
>
> If you want to set it in any case, you'll have to use __init__ I believe, but 
> I'm sure others will be able to infirm that and show a better way.
>
> But in this case, `slugify` is going to get passed a CharField, which 
> probably isn't what you want.
>
> Finally,
>
> > So what are those members, are they static for the class ?
>
> Well they are class attributes, but they're also instance attributes. They're 
> one of those very-useful-but-not-necessaril-super-clear features: 
> descriptors. Seehttp://users.rcn.com/python/download/Descriptor.htmfor a very 
> good howto by Raymond Hettinger. Note that you could just as well go with 
> "magic, gotcha" for now on that subject. They're basically class attributes 
> which do special stuff when you invoke them from an instance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Erro ao tentar importar DjangoGateway

2010-03-08 Thread Edgard Matos
Obrigado pela resposta Jorge!
Eu instalei o Django através da seguinte instrução:

python setup.py install --disable-ext

Não instalei através do easy_install por não estar com o compilador do c
aqui meu OSX.
O engraçado é que se eu for no console do python e realizar o import, o
import é feito sem problemas.

Mesmo assim, será que é porque o PyAMF ainda não estar no PYTHON_PATH ?
Como eu faço pra colocá-lo lá?

Obrigado!

2010/3/8 Jorge Silva 

> Esse erro indica que o módulo PyAMF não está na PYTHON_PATH. Podes tentar
> adicioná-lo manualmente mas o ideal é usar o método easy_install que está
> descrito em  http://pyamf.org/install.html
>
> Podes descrever o modo como instalaste o PyAMF?
>
> 2010/3/8 Edgard Matos 
>
>> Caros,
>>
>> Estou tentando fazer uns testes com o PyAmf. Instalei a biblioteca
>> normamente.
>> Sendo que quando tento importar seus pacotes, não consigo.
>>
>> . Error was: cannot import name DjangoGateway
>>
>>
>> O meu gateway está assim:
>> from pyamf.remoting.gateway import DjangoGateway
>> import TesteAMF.cadastros.models as models
>>
>> services = {
>> 'Clientes': models
>> }
>>
>> echoGateway = DjangoGateway(services)
>>
>> Alguém sabe se eu tenho que configurar mais alguma coisa?
>> Obrigado!!!
>>
>> --
>> Atenciosamente,
>>
>> Edgard Matos
>> Direção de Projetos
>>
>> Deway - Inovação Digital
>> http://www.deway.com.br
>> Celular: (85) 8106 8252
>> Fortaleza: (85) 4062-9094
>> São Paulo: (11) 3522-9094
>> Skype: edgardmatos
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>
> --
> Com os melhores cumprimentos / Best regards,
>
> Jorge Rodrigues Silva
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Atenciosamente,

Edgard Matos
Direção de Projetos

Deway - Inovação Digital
http://www.deway.com.br
Celular: (85) 8106 8252
Fortaleza: (85) 4062-9094
São Paulo: (11) 3522-9094
Skype: edgardmatos

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: radio on admin

2010-03-08 Thread gustavo
Sure Daniel,

I have the admin showing only the "tipo"s label, not the choices!

On 8 mar, 13:23, Daniel Roseman  wrote:
> On Mar 8, 4:12 pm, gustavo  wrote:
>
>
>
> > Hello folks,
>
> > I am having a hard time trying to use a radio button field on admin.
>
> > I am using:
>
> > tipo = models.IntegerField(
> >                                max_length=1,
> >                                choices = IMAGEM_TIPOS_CHOICES,
> >                                )
>
> > where IMAGEM_TIPOS_CHOICES is a list of tuples.
>
> > Any light please?
>
> > Thanks a lot!
>
> And what is your problem? What is happening? What should be happening?
> What error are you getting? Give us some clues here.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: ValueError, The view django_bookmarks.bookmarks.views.user_page didn't return an HttpResponse object.

2010-03-08 Thread Naveen Reddy
heres my code, but still its not working:

from django.http import HttpResponse, Http404
from django.contrib.auth.models import User
from django.template import Context
from django.template.loader import get_template

def main_page(request):
template = get_template('main_page.html')
variables = Context({
'head_title': 'Django Bookmarks',
'page_title': 'Welcome to Django Bookmarks',
'page_body': 'Where you can store and share bookmarks!'
})
output = template.render(variables)
return HttpResponse(output)

def user_page(request, username):
try:
user = User.objects.get(username=username)
except:
raise Http404('Requested user not found.')
bookmarks = user.bookmark_set.all()
template = get_template('user_page.html')
variables = Context({
'username': username,
'bookmarks': bookmarks
})
output = template.render(variables)
return HttpResponse(output)


On Sun, Mar 7, 2010 at 11:19 PM, Daniel Roseman wrote:

> On Mar 7, 2:42 pm, Naveen Reddy  wrote:
> > Why am i getting this error:
> > ValueError at /user/naveen_admin/
> > The view django_bookmarks.bookmarks.views.user_page didn't return an
> > HttpResponse object.
> > Request Method: GET
> > Request URL:http://localhost:8000/user/naveen_admin/
> > Exception Type: ValueError
> > Exception Value:
> > The view django_bookmarks.bookmarks.views.user_page didn't return an
> > HttpResponse object.
> > Exception Location:
> C:\Python26\lib\site-packages\django\core\handlers
> > \base.py in get_response, line 109
> > Python Executable:  C:\Python26\python.exe
> > Python Version: 2.6.4
> > Python Path:['D:\\django_workspace\\django_bookmarks', 'C:\
> > \Python26', 'C:\\WINDOWS\\system32\\python26.zip', 'C:\\Python26\
> > \DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\
> > \Python26\\lib\\lib-tk', 'C:\\Python26\\lib\\site-packages']
> > Server time:Sun, 7 Mar 2010 20:07:27 +0530
> >
> > Here's my views code:
> > from django.http import HttpResponse, Http404
> > from django.contrib.auth.models import User
> > from django.template import Context
> > from django.template.loader import get_template
> >
> > def main_page(request):
> > template = get_template('main_page.html')
> > variables = Context({
> > 'head_title': 'Django Bookmarks',
> > 'page_title': 'Welcome to Django Bookmarks',
> > 'page_body': 'Where you can store and share bookmarks!'
> > })
> > output = template.render(variables)
> > return HttpResponse(output)
> >
> > def user_page(request, username):
> > try:
> > user = User.objects.get(username=username)
> > except:
> > raise Http404('Requested user not found.')
> > bookmarks = user.bookmark_set.all()
> > template = get_template('user_page.html')
> > variables = Context({
> > 'username': username,
> > 'bookmarks': bookmarks
> > })
> > output = template.render(variables)
> > return HttpResponse(output)
> > Please guide me through this. I am absolute beginner to django. Thaks
> > in advance
>
> Looks like an indentation problem in user_page. The lines after 'raise
> Http404` should be one indentation level to the left.
>
> If you don't understand this, you'll need to follow a beginner's
> Python tutorial.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Pain is temporary. It may last a minute, or an hour, or a day, or a year,
but eventually it will subside and something else will take its place. But,
quitting, however, lasts forever.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: radio on admin

2010-03-08 Thread Daniel Roseman
On Mar 8, 4:12 pm, gustavo  wrote:
> Hello folks,
>
> I am having a hard time trying to use a radio button field on admin.
>
> I am using:
>
> tipo = models.IntegerField(
>                                max_length=1,
>                                choices = IMAGEM_TIPOS_CHOICES,
>                                )
>
> where IMAGEM_TIPOS_CHOICES is a list of tuples.
>
> Any light please?
>
> Thanks a lot!

And what is your problem? What is happening? What should be happening?
What error are you getting? Give us some clues here.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: gintare

2010-03-08 Thread Simon Brunning
On 7 March 2010 09:45, gintare  wrote:
> Hello,
>
> Is it possible in python access name of variable?

"The same way as you get the name of that cat you found on your porch:
the cat (object) itself cannot tell you its name, and it doesn't
really care -- so the only way to find out what it's called is to ask
all your neighbours (namespaces) if it's their cat (object) ... and
don't be surprised if you'll find that it's known by many names, or no
name at all!" - Fredrik Lundh.

-- 
Cheers,
Simon B.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



radio on admin

2010-03-08 Thread gustavo
Hello folks,

I am having a hard time trying to use a radio button field on admin.

I am using:

tipo = models.IntegerField(
   max_length=1,
   choices = IMAGEM_TIPOS_CHOICES,
   )

where IMAGEM_TIPOS_CHOICES is a list of tuples.

Any light please?

Thanks a lot!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Migration sqlite3 (localhost) to MySQL (Shared-Hosting)

2010-03-08 Thread Daniel Roseman
On Mar 8, 3:02 pm, Egon Frerich  wrote:
> Hello,
>
> is there a HowTo for migrating a working test environment on localhost
> with sqlite3 to a shared-hosting provider on Apache with MySQL? Chapter
> 12 of the books tells nothing about migrating the database. I cannot
> find something in the documentation.
>
> What is the equivalence to python manage.py syncdb for the production on
> Apache?
>
> Egon

It's not really clear what you are asking here. Are you hoping to copy
actual data from an sqlite database to a MySQL one?
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Database redesign for "user" table

2010-03-08 Thread Daniel Roseman
On Mar 8, 3:01 pm, Derek  wrote:
> I am working with a legacy database and would appreciate some advice.
>
> I have an existing "user" table, with some fields that overlap with the
> design of Django's "user" table, and some fields that are "extra" to it.  I
> understand that I can use Django's "user" table and extend it to include
> these extra fields.
>
> However, the problem lies with the user's "id" field.  In the legacy
> database, this id appears in numerous tables (to identify the person who
> last edited the record) but is a short character string, NOT an
> auto-increment numeric value.  I am wondering what is the best/possible
> approach in order to use all the features of Django admin without any code
> changes.  I assume I will need to convert all the existing users into the
> Django user table, but then do I:
>
> a. leave the id field in the other tables "as is"?  In which case, is it
> possible to somehow adapt Django's numeric id field to become alpha-numeric?
>
> b. carry-out a mass update and convert all existing user id's in all tables
> to the Django numeric format?
>
> I think (b) might be better in the long run (although I am partial to the
> idea of "human readable" id string when browsing the raw data), but I would
> welcome other opinions (or options).
>
> Thanks
> Derek

A Django ForeignKey field doesn't have to point at the related table's
id column - you can use the 'to_field' attribute of the ForeignKey to
point it at a different field. So I would suggest keeping your non-
numeric key as (eg) 'legacy_key', and in your related models use:
 user = ForeignKey(UserProfile, to_field='legacy_key').

Would that work?
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Prefixing an argument to date-based generic views

2010-03-08 Thread GJCGJC
Okay, here's where I've got so far. My problem with this is that, as
will be immediately apparent, There's an awful lot being repeated
here:

from django.conf.urls.defaults import *

from newssite.models import Entry, Category

def story_archive(request, cat):

# Look up the category (and raise a 404 if it can't be found).
category = get_object_or_404(Category, slug__iexact=cat)

# Use the object_list view for the heavy lifting.
return date_based.archive_index(
request,
queryset = Entry.live.filter(navigation_parent=category),
date_field = 'pub_date'
template_name = 'newssite/story_archive.html',
template_object_name = 'latest_stories',
extra_context = {...}
)

def stories_archive_year(request, cat, year):

# Look up the category (and raise a 404 if it can't be found).
category = get_object_or_404(Category, slug__iexact=cat)

# Use the object_list view for the heavy lifting.
return date_based.archive_year(
request,
queryset = Entry.live.filter(navigation_parent=category),
date_field = 'pub_date'
year,
template_name = 'newssite/story_archive_year.html',
template_object_name = 'story',
extra_context = {...}
)

def stories_archive_month(request, cat, year, month):

# Look up the category (and raise a 404 if it can't be found).
category = get_object_or_404(Category, slug__iexact=cat)

# Use the object_list view for the heavy lifting.
return date_based.archive_month(
request,
queryset = Entry.live.filter(navigation_parent=category),
date_field = 'pub_date'
year,
month,
template_name = 'newssite/story_archive_month.html',
template_object_name = 'story',
extra_context = {...}
)

def stories_archive_day(request, cat, year, month, day):

# Look up the category (and raise a 404 if it can't be found).
category = get_object_or_404(Category, slug__iexact=cat)

# Use the object_list view for the heavy lifting.
return date_based.archive_year(
request,
queryset = Entry.live.filter(navigation_parent=category),
date_field = 'pub_date'
year,
month,
day,
template_name = 'newssite/story_archive_day.html',
template_object_name = 'story',
extra_context = {...}
)

def story_detail(request, cat, year, month, day, slug):

# Look up the category (and raise a 404 if it can't be found).
category = get_object_or_404(Category, slug__iexact=cat)

# Use the object_list view for the heavy lifting.
return date_based.object_detail(
request,
queryset = Entry.live.filter(navigation_parent=category),
date_field = 'pub_date'
year,
month,
day,
slug,
template_name = 'newssite/story_archive_day.html',
template_object_name = 'story',
extra_context = {...}
)

Is there an accepted way to make this more DRY that I'm missing?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Migration sqlite3 (localhost) to MySQL (Shared-Hosting)

2010-03-08 Thread Egon Frerich

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


Hello,

is there a HowTo for migrating a working test environment on localhost
with sqlite3 to a shared-hosting provider on Apache with MySQL? Chapter
12 of the books tells nothing about migrating the database. I cannot
find something in the documentation.

What is the equivalence to python manage.py syncdb for the production on
Apache?

Egon
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFLlRGhZRiDo9Iq4qIRAhy9AKCJkPotRVuqseuQcI5Dbo5SuAFCtACePF+n
Jx+L5k4jjx8CRRL+bH9lPr0=
=xGFe
-END PGP SIGNATURE-

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Database redesign for "user" table

2010-03-08 Thread Derek
I am working with a legacy database and would appreciate some advice.

I have an existing "user" table, with some fields that overlap with the
design of Django's "user" table, and some fields that are "extra" to it.  I
understand that I can use Django's "user" table and extend it to include
these extra fields.

However, the problem lies with the user's "id" field.  In the legacy
database, this id appears in numerous tables (to identify the person who
last edited the record) but is a short character string, NOT an
auto-increment numeric value.  I am wondering what is the best/possible
approach in order to use all the features of Django admin without any code
changes.  I assume I will need to convert all the existing users into the
Django user table, but then do I:

a. leave the id field in the other tables "as is"?  In which case, is it
possible to somehow adapt Django's numeric id field to become alpha-numeric?

b. carry-out a mass update and convert all existing user id's in all tables
to the Django numeric format?

I think (b) might be better in the long run (although I am partial to the
idea of "human readable" id string when browsing the raw data), but I would
welcome other opinions (or options).

Thanks
Derek

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Erro ao tentar importar DjangoGateway

2010-03-08 Thread Jorge Silva
Esse erro indica que o módulo PyAMF não está na PYTHON_PATH. Podes tentar
adicioná-lo manualmente mas o ideal é usar o método easy_install que está
descrito em  http://pyamf.org/install.html

Podes descrever o modo como instalaste o PyAMF?

2010/3/8 Edgard Matos 

> Caros,
>
> Estou tentando fazer uns testes com o PyAmf. Instalei a biblioteca
> normamente.
> Sendo que quando tento importar seus pacotes, não consigo.
>
> . Error was: cannot import name DjangoGateway
>
>
> O meu gateway está assim:
> from pyamf.remoting.gateway import DjangoGateway
> import TesteAMF.cadastros.models as models
>
> services = {
> 'Clientes': models
> }
>
> echoGateway = DjangoGateway(services)
>
> Alguém sabe se eu tenho que configurar mais alguma coisa?
> Obrigado!!!
>
> --
> Atenciosamente,
>
> Edgard Matos
> Direção de Projetos
>
> Deway - Inovação Digital
> http://www.deway.com.br
> Celular: (85) 8106 8252
> Fortaleza: (85) 4062-9094
> São Paulo: (11) 3522-9094
> Skype: edgardmatos
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Com os melhores cumprimentos / Best regards,

Jorge Rodrigues Silva

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to start with django

2010-03-08 Thread Shawn Milochik
It all depends. Do you have a specific project you would like to  
develop with Django, or do you just want to generally learn how to use  
it for projects you haven't thought of yet?


If you know exactly what you want to do, read "The Definitive Guide to  
Django, Second Edition" (cover to cover). After that you'll be all set.


If you don't know what you want to do with Django, read "Practical  
Django Projects, Second Edition." This will walk you through creating  
useful Django projects from scratch and give you some experience with  
advanced features as well. If you do this, I still recommend reading  
the "Definitive Guide" afterwards, since it covers a lot more.


Shawn

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Erro ao tentar importar DjangoGateway

2010-03-08 Thread Edgard Matos
Caros,

Estou tentando fazer uns testes com o PyAmf. Instalei a biblioteca
normamente.
Sendo que quando tento importar seus pacotes, não consigo.

. Error was: cannot import name DjangoGateway

O meu gateway está assim:
from pyamf.remoting.gateway import DjangoGateway
import TesteAMF.cadastros.models as models

services = {
'Clientes': models
}

echoGateway = DjangoGateway(services)

Alguém sabe se eu tenho que configurar mais alguma coisa?
Obrigado!!!

-- 
Atenciosamente,

Edgard Matos
Direção de Projetos

Deway - Inovação Digital
http://www.deway.com.br
Celular: (85) 8106 8252
Fortaleza: (85) 4062-9094
São Paulo: (11) 3522-9094
Skype: edgardmatos

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: unique slug creation and check

2010-03-08 Thread andreas schmid
it looks like what i want to do. did you set the slug field as
blank=True or null=True?

adamalton wrote:
> Here's some code that I wrote a few days ago:
>
> class MyModel(models.Model):
> #various fields and stuff here
>
> def save(self, *args, **kwargs):
> if not self.slug:
> self.slug = self.make_slug()
> super(Project, self).save(*args, **kwargs)
>
> def make_slug(self):
> """ Create a (unique) slug from self.name. """
> sanitized = re.sub("(?i)[^a-z0-9_-]", "_", self.name).lower()
> #remove non-alpha-numeric-underscore-hyphen chars
> sanitized = re.sub("^_|_$", "", sanitized) #remove underscores
> from start/end cos they look dumb
> while(re.search("__", sanitized)): #remove double underscores
> cos they look dumb
> sanitized = re.sub("__", "_", sanitized)
> #now make sure that it's unique:
> while(Project.objects.filter(slug__iexact=sanitized).count()):
> #if it's not unique
> current_number_suffix_match = re.search("\d+$", sanitized)
> #get the current number suffix if there is one
> current_number_suffix = current_number_suffix_match and
> current_number_suffix_match.group() or 0
> next = str(int(current_number_suffix) +1) #increment it,
> and turn back to string so re.sub doesn't die
> sanitized = re.sub("(\d+)?$", next, sanitized) #replace
> current number suffix with incremented suffix, try again...
> return sanitized
>
> That should do exactly what you're after.
> Adam Alton
>
>   

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: is there any possibility for two settings.py

2010-03-08 Thread Gustavo Narea
Have a look at:
http://packages.python.org/twod.wsgi/manual/paste-factory.html#multiple-configuration-files

On Mar 8, 7:06 am, chiranjeevi muttoju 
wrote:
> Hi friends,
> i have two apps in my project, and i want to use two different settings for
> each app. it means same project but i sud run those two apps separately. is
> it possible..? if anyone of u guys know please reply me. And if u want any
> further information regarding this post please ask me.
>
> --
> Thanks & Regards,
> Chiranjeevi.Muttoju

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: is there any possibility for two settings.py

2010-03-08 Thread Shawn Milochik
You can definitely do this. Say you have a project called myproject,  
and apps named app1 and app2.


You can do this (development example -- don't use runserver in  
production):


./manage.py runserver --settings=myproject.app1.settings 127.0.0.1:8080
./manage.py runserver --settings=myproject.app2.settings 127.0.0.1:8085

Then you have two separate processes.

Shawn

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: unique slug creation and check

2010-03-08 Thread adamalton
Here's some code that I wrote a few days ago:

class MyModel(models.Model):
#various fields and stuff here

def save(self, *args, **kwargs):
if not self.slug:
self.slug = self.make_slug()
super(Project, self).save(*args, **kwargs)

def make_slug(self):
""" Create a (unique) slug from self.name. """
sanitized = re.sub("(?i)[^a-z0-9_-]", "_", self.name).lower()
#remove non-alpha-numeric-underscore-hyphen chars
sanitized = re.sub("^_|_$", "", sanitized) #remove underscores
from start/end cos they look dumb
while(re.search("__", sanitized)): #remove double underscores
cos they look dumb
sanitized = re.sub("__", "_", sanitized)
#now make sure that it's unique:
while(Project.objects.filter(slug__iexact=sanitized).count()):
#if it's not unique
current_number_suffix_match = re.search("\d+$", sanitized)
#get the current number suffix if there is one
current_number_suffix = current_number_suffix_match and
current_number_suffix_match.group() or 0
next = str(int(current_number_suffix) +1) #increment it,
and turn back to string so re.sub doesn't die
sanitized = re.sub("(\d+)?$", next, sanitized) #replace
current number suffix with incremented suffix, try again...
return sanitized

That should do exactly what you're after.
Adam Alton

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: admin rows aren't ordered as expected

2010-03-08 Thread derek
On Mar 8, 2:46 pm, Wim Feijen  wrote:
> Hello,
>
> In my admin interface, the data isn't ordered as expected. What I get
> is:
> Provincie/Land   Type
> Limburg     Provincie
> Groningen  Provincie
> Utrecht      Provincie
> etc.
> which clearly isn't alphabetical order, while I do specify that
> provinces should be ordered that way. In my python manage.py shell the
> provinces are ordered alphabetically. What could be wrong?
>
> admin.py:
> class ProvinceAdmin(admin.ModelAdmin):
>     list_display = ('name', 'type')
>     actions = None
>
> admin.site.register(Province, ProvinceAdmin)
>
> models.py:
> class Province(models.Model):
>     TYPES = (
>         ('c', 'Land'),
>         ('p', 'Provincie'),
>     )
>     name = models.CharField(max_length=200, verbose_name="Provincie/
> Land")
>     type = models.CharField(max_length=1, choices=TYPES, default='c')
>
>     def __unicode__(self):
>         return self.name
>
>     class Meta:
>         ordering = ('-type', 'name',)
>         verbose_name = 'Provincie/Land'
>         verbose_name_plural = 'Provincies/Landen'
>
> For the record, I am using django trunk revision 12295 .
>
> - Wim

The Django documentation:
http://docs.djangoproject.com/en/dev/ref/models/options/#ordering
mentions that ... "Regardless of how many fields are in ordering, the
admin site uses only the first field."

"""
Minor observation:  shouldn't the format be
ordering = [-type', 'name',]
"""

Derek

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to start with django

2010-03-08 Thread David Talbot
I would recommend the tutorial at 
http://docs.djangoproject.com/en/1.1/intro/tutorial01/
if you are just beginning - it gives a very good overview of the main
features and programming ideas.

On Mar 8, 7:47 am, Subhransu Sekhar Mishra 
wrote:
> hi,i am subhransu and new to django . i want to know how to start
> django ?i have not done any project before.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Maintaining Continuity (after editing) in the Admin interface?

2010-03-08 Thread derek
On Mar 8, 8:58 am, Russell Keith-Magee  wrote:
> On Mon, Mar 8, 2010 at 2:24 PM, Derek  wrote:
> > I have noticed that, if a change list has been filtered before a record is
> > edited, the filter is not restored after the editing operation is complete.
>
> > a. Is there a way to automatically restore the filtered view and, if so,
> > how?
>
> > b. If there is not a way to automatically restore it, what other options are
> > possible?
>
> > c. Is there a reason why the continuity of the interface is not maintained
> > as "default", and would it make sense to add this suggestion as a new
> > ticket?  (Probably getting too far ahead here...)
>
> What you're describing is the subject of ticket #6903. It's a known
> defect in the current admin interface. There is a patch attached to
> the ticket, but I can't comment on how stable that patch is.
>
> http://code.djangoproject.com/ticket/6903
>
> Yours,
> Russ Magee %-)

Thanks Russ - Next time I will try and search the ticket list as
well...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: import errors when starting django on staging server, no errors on local dev server

2010-03-08 Thread felix


On Mar 8, 1:25 am, Graham Dumpleton 
wrote:
> You don't say anything about what hosting mechanisms you are using for
> each.

local: django's runserver
staging: mod_wsgi apache

one thing I should do is test locally using wsgi

Do you have any suggestions regarding question 2:

how can I do a quick test on the deployment environment to trigger
these import errors ?

I opened a manage.py shell and ran the same code as in my .wsgi
...
application = django.core.handlers.wsgi.WSGIHandler()

no problems.

earlier I said it was during start up. that's wrong, it was after
loading some pages.

specifically if I loaded one page as the first load, then it triggered
the import error.
if I loaded the front page it did not.  that would be hell on a live
site.

this is of course a clue to the problem, but I'm not trying to solve
the problem.  I already solved that one.

I'm trying to find a way to detect Unknown Unknowns.

so probably I need to do a few requests using that test WSGIHandler

I also saw it returning a 404 for an admin page, but only for 1 out of
every 4 requests !  yep, I have 4 threads on the WSGIDaemonProcess.
and one of them loaded up the admin wrong.  a restart fixed it.

another thing I'm thinking about is a way to notify me by email when
an exception escapes django's grasp and gives that black and white
apache 500 notification.

it should be possible to just wrap that WSGIHandler with a simple wsgi
app, catch any exceptions, email quickly and then return a simple html
display.

there needs to be one more line of defense.



> The Django runserver does extra automagic setup steps which aren't by
> default going to be done by other hosting mechanisms. Part of this is
> solved by manual setup of sys.path, but not necessarily all that is
> necessary.



>
> Graham
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Thread safe language switching?

2010-03-08 Thread Plovarna
Hello,
I just developing my first aplication with internationalization. I need to get 
all verbose_name values of the model for each language defined in 
settings.LANGUAGES. I do it by this code defined inside model method :

   current_lang = get_language()
   names = {}
   for lang in settings.LANGUAGES:
   activate(lang[0])
   class_name = unicode(self.__class__._meta.verbose_name)
   names.append(class_name)
   deactivate()
   activate(current_lang)

My question is: Is this approach thread safe? Is there any other way how to get 
verbose_name of the model for each defined language?

Thank you for any advice
Michal

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: relative links to css, images, javascript -> problem

2010-03-08 Thread Dylan Evans
I use a STATIC variable in templates which i set in settings.py which points
to the appropriate server or path.
So the link is

and STATIC is something like
STATIC="192.168.1.5:8001"
Of course i use lighttpd for static files

On Mon, Mar 8, 2010 at 10:05 PM, Martin N.  wrote:

> I encountered problems when I try to adopt HTML page layouts into
> django templates.
>
> These HTML files often reference their CSS files like
> 
> or
> 
> because they expect these files (and images, javascript, ...) in a
> location relative to the current HTML document.
>
> Can I use such HTML and CSS in django without searching them for each
> and every link to static content and change it to something like
> http://myserver.com/media/css/base.css;>?
> The relative links in the above example don't work for me in django
> templates. Absolute links are a nuisance when the templates are used
> on different hostnames and when CSS files must be included from a
> number of subdirectories.
>
> What is the easiest solution?
>
> Thanks
> Martin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



admin rows aren't ordered as expected

2010-03-08 Thread Wim Feijen
Hello,

In my admin interface, the data isn't ordered as expected. What I get
is:
Provincie/Land   Type
Limburg Provincie
Groningen  Provincie
Utrecht  Provincie
etc.
which clearly isn't alphabetical order, while I do specify that
provinces should be ordered that way. In my python manage.py shell the
provinces are ordered alphabetically. What could be wrong?

admin.py:
class ProvinceAdmin(admin.ModelAdmin):
list_display = ('name', 'type')
actions = None

admin.site.register(Province, ProvinceAdmin)

models.py:
class Province(models.Model):
TYPES = (
('c', 'Land'),
('p', 'Provincie'),
)
name = models.CharField(max_length=200, verbose_name="Provincie/
Land")
type = models.CharField(max_length=1, choices=TYPES, default='c')

def __unicode__(self):
return self.name

class Meta:
ordering = ('-type', 'name',)
verbose_name = 'Provincie/Land'
verbose_name_plural = 'Provincies/Landen'

For the record, I am using django trunk revision 12295 .

- Wim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to start with django

2010-03-08 Thread jimgardener
grab the  ebook written by James Bennet, one of the best ever written

Subhransu Sekhar Mishra wrote:
> hi,i am subhransu and new to django . i want to know how to start
> django ?i have not done any project before.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: relative links to css, images, javascript -> problem

2010-03-08 Thread Carlos Ricardo Santos
I Just add a "site_media" path to urls.py

*site_media = os.path.join( os.path.dirname(__file__), 'site_media' )*
*(r'^site_media/(?P.*)$', 'django.views.static.serve', {
'document_root': site_media }),*

Add to settings.py:

*MEDIA_URL = '/site_media/'*

and then:

**
*
*
*
*

On 8 March 2010 12:05, Martin N.  wrote:

> I encountered problems when I try to adopt HTML page layouts into
> django templates.
>
> These HTML files often reference their CSS files like
> 
> or
> 
> because they expect these files (and images, javascript, ...) in a
> location relative to the current HTML document.
>
> Can I use such HTML and CSS in django without searching them for each
> and every link to static content and change it to something like
> http://myserver.com/media/css/base.css;>?
> The relative links in the above example don't work for me in django
> templates. Absolute links are a nuisance when the templates are used
> on different hostnames and when CSS files must be included from a
> number of subdirectories.
>
> What is the easiest solution?
>
> Thanks
> Martin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Cumprimentos,
Carlos Ricardo Santos

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



relative links to css, images, javascript -> problem

2010-03-08 Thread Martin N.
I encountered problems when I try to adopt HTML page layouts into
django templates.

These HTML files often reference their CSS files like

or

because they expect these files (and images, javascript, ...) in a
location relative to the current HTML document.

Can I use such HTML and CSS in django without searching them for each
and every link to static content and change it to something like
http://myserver.com/media/css/base.css;>?
The relative links in the above example don't work for me in django
templates. Absolute links are a nuisance when the templates are used
on different hostnames and when CSS files must be included from a
number of subdirectories.

What is the easiest solution?

Thanks
Martin

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django vs tornado

2010-03-08 Thread Kenneth Gonsalves
On Monday 08 Mar 2010 3:09:51 pm Kenneth Gonsalves wrote:
> > I'm testing django on tornado and didn't find any issue using the
> > admin interface
> > which uses csrf_token. I'm using latest django from svn and latest
> > tornado from git.
> > 
> 
> I last used the latest django and tornado about a month back. I cannot
>  explain  more than say that I got randomn errors with the csrf_token
>  stuff. Both in admin and outside admin, it would work at times and not
>  work at times. And each time with a different csrf_token error. If I have
>  time today, I will try again and report back.
> 

I tried it with just a simple model and two views - works fine. Also tried it 
with two simple sites and opened 4 tabs, two each for admin and two each for 
the site - works. But in none of the more complex sites does it work.
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



ANN: twod.wsgi -- Better WSGI support for Django

2010-03-08 Thread Gustavo Narea
Hello, everybody.

I'm very pleased to announce the first alpha release of twod.wsgi, a
library to make WSGI a first-class citizen in Django applications.

twod.wsgi allows Django developers to take advantage of the huge array
of existing WSGI software, to integrate 3rd party components which
suit your needs or just to improve things which are not within the
scope of a Web application framework.

To learn more about what it can do for you, you can check our
presentation at the Django User Group in London:
http://gustavonarea.net/files/talks/twodwsgi-djugl.pdf

This project is based on the patches we provided to improve WSGI
support in Django itself [1], which unfortunately was not possible in
v1.2. We hope to see these improvements in a future Django release
(1.3), and we'd love to help make it possible.

Here's the Web site:
http://packages.python.org/twod.wsgi/

And the full announcement is available at:
http://dev.2degreesnetwork.com/2010/03/announcing-twodwsgi-better-wsgi-support.html

Cheers,

 - Gustavo.
http://dev.2degreesnetwork.com

[1] 
http://groups.google.com/group/django-developers/browse_thread/thread/08c7ffeee7b9343c

PS: I've cross-posted this announcement in some relevant mailing
lists, so I'm sorry if you received this multiple times! I won't do it
again, so you may want to keep an eye on our blog if you're interested
in twod.wsgi.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



how to add author to entry,newbie doubt about IntegrityError

2010-03-08 Thread jimgardener
hi,
I am more or less a beginner with django and databases.I was trying to
set the author field  of an entry from the request.user instead of
letting the user select from a drop down list of users.I designed the
models like

class Entry(models.Model):
pub_date=models.DateField(default=date.today)
description=models.TextField()
author=models.ForeignKey(User)

class EntryForm(ModelForm):
class Meta:
model=Entry
exclude = ('author',)

In views.py I created an add_entry function,

def add_entry(request,template_name,page_title):
form_data=get_form_data(request)
form=EntryForm(form_data)
if request.method=='POST' and form.is_valid() :
newentry=form.save()
some other ops...
newentry.author=request.user
newentry.save()


However ,when I tried a testcase using

def test_add_entry(self):
self.client.login(username='me',password='mypass')
self.post_data={
 
'pub_date':'2010-03-08',
'description':'my new
entry'
}
 
response=self.client.post(reverse('myapp_add_entry'),self.post_data)

I get this IntegrityError, saying that 'null value in column
"author_id" violates not-null constraint'
The error occurs at  the first occurrence of line
newentry=form.save() in the add_entry()method

Can someone help me figure out how to add the author value correctly?
since I am using client.login() shouldn't the author field be taken
from the logged in user thru request.user?

thanks
jim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modify date in django twitter app

2010-03-08 Thread het.oosten
Thank you for the reply. When i add the [0] to tweet, the date
conversion is only applied to the last tweet

On 7 mrt, 23:24, Daniel Roseman  wrote:
> On Mar 7, 9:57 pm, "het.oosten"  wrote:
>
>
>
> > I am almost done implementing tweets on my site using a tutorial which
> > a found 
> > here:http://www.omh.cc/blog/2008/aug/4/adding-your-twitter-status-django-s...
>
> > The problem is that i want to modify the date output when i retrieve
> > multiple tweets. The example above is written for retrieving only one
> > most recent tweet from twitter.
>
> > The context_preprocessor i have now is (mostly taken from the site
> > above):
>
> > import datetime
> > import time
> > from django.conf import settings
> > from django.core.cache import cache
> > import twitter
>
> > def latest_tweet( request ):
> >     tweet = cache.get( 'tweet' )
>
> >     if tweet:
> >         return {"tweet": tweet}
>
> >     tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER,
> > count=3 )
> >     tweet.date = datetime.datetime(*(time.strptime( tweet.created_at,
> > "%a %b %d %H:%M:%S + %Y" )[0:6]))
> >     cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT )
>
> >     return {"tweet": tweet}
>
> > This results in the following error:
> > AttributeError: 'list' object has no attribute 'created_at'
>
> > The twitter api let me call a human readable date in the template
> > using relative_created_at. Unfortunately the output is in English.
>
> > Any idea how i get an easy readable date?
>
> > The output is now:
> > Fri Oct 30 10:18:53 + 2009
>
> > Or:
> > about 6 days ago
> > When i use relative_created_at
>
> I don't know the Twitter API, but you're calling GetUserTimeline with
> a count of 3, which presumably returns a list of 3 items. The list
> itself doesn't have a 'created_at' attribute, hence the error. Perhaps
> if you did:
>
>     tweet = twitter.Api().GetUserTimeline(settings.TWITTER_USER,
> count=3) [0]
>
> you would have better luck.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: is there any possibility for two settings.py

2010-03-08 Thread chiranjeevi muttoju
ya but i want to run both app separately means like different servers. we
sud b able to stop one while other is still running. finally like two
different projects. ok. is it possible..?

On Mon, Mar 8, 2010 at 4:50 PM, Atamert Ölçgen  wrote:

> On Monday 08 March 2010 13:08:23 chiranjeevi muttoju wrote:
> > we have two applications, what we want to do is, one app should run at
> one
> > address and other app should run at different address. this is my
> > requirement. is it possible to put those two apps in the same
> > project...?(different apps but same project, we sud be able to run both
> >  apps separately with the different settings.)
> Each instance of a project running has a single set of settings.
>
> What do you mean by ``address`` exactly? If you mean URL locactions like
> "/app1/view1/" and "/app2/view2/" it has nothing to do with the settings,
> you
> configure it in your URLconf.
>
>
> --
> Saygılarımla,
> Atamert Ölçgen
>
>  -+-
>  --+
>  +++
>
> www.muhuk.com
> mu...@jabber.org
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Thanks & Regards,
Chiranjeevi.Muttoju

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: is there any possibility for two settings.py

2010-03-08 Thread Atamert Ölçgen
On Monday 08 March 2010 13:08:23 chiranjeevi muttoju wrote:
> we have two applications, what we want to do is, one app should run at one
> address and other app should run at different address. this is my
> requirement. is it possible to put those two apps in the same
> project...?(different apps but same project, we sud be able to run both
>  apps separately with the different settings.)
Each instance of a project running has a single set of settings.

What do you mean by ``address`` exactly? If you mean URL locactions like 
"/app1/view1/" and "/app2/view2/" it has nothing to do with the settings, you 
configure it in your URLconf.


-- 
Saygılarımla,
Atamert Ölçgen

 -+-
 --+
 +++

www.muhuk.com
mu...@jabber.org

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: is there any possibility for two settings.py

2010-03-08 Thread chiranjeevi muttoju
we have two applications, what we want to do is, one app should run at one
address and other app should run at different address. this is my
requirement. is it possible to put those two apps in the same
project...?(different apps but same project, we sud be able to run both apps
separately with the different settings.)

On Mon, Mar 8, 2010 at 3:39 PM, Atamert Ölçgen  wrote:

> On Monday 08 March 2010 09:06:05 chiranjeevi muttoju wrote:
> > Hi friends,
> > i have two apps in my project, and i want to use two different settings
> for
> > each app. it means same project but i sud run those two apps separately.
> is
> > it possible..? if anyone of u guys know please reply me. And if u want
> any
> > further information regarding this post please ask me.
> No. But if you tell us which settings you want different and why, someone
> might offer an alternative solution.
>
>
> --
> Saygılarımla,
> Atamert Ölçgen
>
>  -+-
>  --+
>  +++
>
> www.muhuk.com
> mu...@jabber.org
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Thanks & Regards,
Chiranjeevi.Muttoju

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to start with django

2010-03-08 Thread schms
I found the following link useful:
http://www.djangobook.com/


There is a nice tutorial:
http://docs.djangoproject.com/en/dev/intro/tutorial01/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to start with django

2010-03-08 Thread Jorge Silva
Read the Django Documentation. It is very well writen and contains a lot of
useful examples.

On Mon, Mar 8, 2010 at 7:47 AM, Subhransu Sekhar Mishra <
sanu.innovat...@gmail.com> wrote:

> hi,i am subhransu and new to django . i want to know how to start
> django ?i have not done any project before.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Com os melhores cumprimentos / Best regards,

Jorge Rodrigues Silva

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Using Cheetah Templates in django

2010-03-08 Thread srini
hi all,

do anybody think that Using Cheetah Templates in django is more than
any normal Html

Thank you,

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Custom widget for a modelform field

2010-03-08 Thread Odd
I'm trying to write a custom select widget for a modelform field, but
the render method of the widget doesn't seem to get called.

This is how I define the modelform:

class MyForm(ModelForm):
class Meta:
model=MyModel
fields=('data',)
widgets = {
'data': MySelect(),
}

This is my MySelect:

class MySelect(Select):
def __init__(self, attrs=None, choices=()):
print "in init"
super(MySelect, self).__init__(attrs)
self.choices = list(choices)
print "leaving init"

def render(self, name, value, attrs=None, choices=()):
 print "entering render"
 return mark_safe("Yuhuu")

The debug in __init__ gets called ok, but not in render. I have also
tried to subclass widget, but without any luck. I'm guessing there is
an error in how I define the widget. Any Ideas what might be wrong?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



unique slug creation and check

2010-03-08 Thread andreas schmid
hi,

im thinking about how to make my slug generation a bit more functional.

I dont want my users to think or write their slugs so they have to be
generated by a field in the model. usually this is the title field.
Now the problem is that there is the possibility that a slug could be
the same as one of another object in my app.
Of couse because i dont want the users to edit or write their slugfields
a 'unique=True' doesnt help because it would invalidate the form
and the user wouldnt understand why.

i was thinking to put a bit of logic in the models save or use the
pre_save signal.

def save(self):
if not self.slug:
genslug = slugify(self.title)
obj = MyModel.objects.filter(slug=genslug)
if not obj:
self.slug = slug
else:
#do something to generate an unique slug
super(MyModel, self).save()

would something like this work?
when does the field validation happen?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: writing a webmail service

2010-03-08 Thread Dylan Evans
It is, but so is almost anything else.

On Mon, Mar 8, 2010 at 8:01 PM, chels  wrote:

>
> I am planning to (or atleast attempting to) write a webmail service
> (like gmail, hotmail etc) using Python. I would like to know if Django
> would be suitable for this.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
"The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



writing a webmail service

2010-03-08 Thread chels

I am planning to (or atleast attempting to) write a webmail service
(like gmail, hotmail etc) using Python. I would like to know if Django
would be suitable for this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django & wsgi: what is the preferred webserver?

2010-03-08 Thread Kenneth Gonsalves
On Monday 08 Mar 2010 1:26:12 pm Rolando Espinoza La Fuente wrote:
> Somebody else thinks that django on tornado could be a winning combination?
> 
 I used to - but have you tried it with the csrf_token? my server broke on 
that and I stopped using tornado.
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django vs tornado

2010-03-08 Thread Kenneth Gonsalves
On Monday 08 Mar 2010 1:53:50 pm Rolando Espinoza La Fuente wrote:
> > I have stopped using it and till I can get something else up am using
> > nginx proxied to runserver - which is faster than tornado and handles the
> > latest django svn ok.
> 
> Could you explain more about the csrf_token issue?
> 
> I'm testing django on tornado and didn't find any issue using the
> admin interface
> which uses csrf_token. I'm using latest django from svn and latest
> tornado from git.
> 

I last used the latest django and tornado about a month back. I cannot explain 
more than say that I got randomn errors with the csrf_token stuff. Both in 
admin and outside admin, it would work at times and not work at times. And 
each time with a different csrf_token error. If I have time today, I will try 
again and report back.
-- 
regards
Kenneth Gonsalves
Senior Associate
NRC-FOSS
http://certificate.nrcfoss.au-kbc.org.in

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Filtering manager, customized by user

2010-03-08 Thread Valentin Golev
Hi there!

I have a model, smth like this:

class Action(models.Model):
def can_be_applied(self, user):
#whatever
return True

and I want to override its default Manager. But I don't know how to pass the
current user variable to the manager, so I have to do smth like this:

[act for act in Action.objects.all() if act.can_be_applied(user)]

How do I get rid of it by just overriding the manager?

Thanks.
- Valentin Golev
- http://valyagolev.net/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



how to start with django

2010-03-08 Thread Subhransu Sekhar Mishra
hi,i am subhransu and new to django . i want to know how to start
django ?i have not done any project before.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: is there any possibility for two settings.py

2010-03-08 Thread Atamert Ölçgen
On Monday 08 March 2010 09:06:05 chiranjeevi muttoju wrote:
> Hi friends,
> i have two apps in my project, and i want to use two different settings for
> each app. it means same project but i sud run those two apps separately. is
> it possible..? if anyone of u guys know please reply me. And if u want any
> further information regarding this post please ask me.
No. But if you tell us which settings you want different and why, someone 
might offer an alternative solution.


-- 
Saygılarımla,
Atamert Ölçgen

 -+-
 --+
 +++

www.muhuk.com
mu...@jabber.org

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: is there any possibility for two settings.py

2010-03-08 Thread chiranjeevi muttoju
Hi swan thanks for ur reply. If we do like that shall we run those
applications separately..?! i mean as different servers..?(like different
projects)

On Mon, Mar 8, 2010 at 12:45 PM, Shawn Milochik  wrote:

> Just specify an argument for --settings when you launch the server for each
> instance.
>
> example (development):
>./manage.py runserver --settings=myproject.myapp.special_settings
>
> Sawn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Thanks & Regards,
Chiranjeevi.Muttoju

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Scrape a file, then put it in the django database

2010-03-08 Thread Daniel Hilton
On 8 March 2010 07:45, mjlissner  wrote:
> I'm trying to write a program that scrapes all the pdfs off of this
> page:
> http://www.ca3.uscourts.gov/recentop/week/recprec.htm
>
> And then puts them onto my hard drive, with the reference to their
> location in a FileField.
>
> I've defined a FileField in my model, and I believe I can scrape the
> site OK (though my code needs improvement), but I can't for the life
> of me figure out how to go from "here's my file" to "I've placed my
> file in the right directory, and there's a reference in my database to
> it - awesome."
>
> I could give more details, but I'm not entirely sure they'd be
> helpful. Essentially, I just want to know how to download a PDF, and
> store it locally, while updating the django db to point to it
> appropriately.
>
> So far, I've been very much unable to pull this off...
>
> Thanks,
>
> Mike

I'd write a management command that wraps around a couple of functions:


* One that gets the file and stores it locally using urllib2
* One that then takes the file and saves it in your model. (Have a
google for using django orm without the full django stack)

The thing to remember is to be nice when scraping and check that your
use of the data is legal.

You could break out the two parts and have one script that downloads
all teh files to a folder, then another that imports them all.

HTH
Dan











> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>



-- 
Dan Hilton

www.twitter.com/danhilton
www.DanHilton.co.uk


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: [Django] Error (EXTERNAL IP): /xml/cat/da-vinci-games

2010-03-08 Thread Alessandro Ronchi
This is the complete traceback of the error with the details of the http
request. Maybe it can help to understand why it gives error only with some
browsers and only sometimes. I can't debug it because it works with my
browsers...

http://dpaste.com/169364/

Any help? What can I check?

2010/3/3 Alessandro Ronchi 

> I have a lot of this unicode error I didn't get before use varnish:
> http://dpaste.com/167139/
>
> ~~~
> handler.addQuickElement(u"pubDate",
> rfc2822_date(item['pubdate']).decode('utf-8'))
>
>  File "/usr/lib/python2.4/encodings/utf_8.py", line 16, in decode
>   return codecs.utf_8_decode(input, errors, True)
>
> UnicodeDecodeError: 'utf8' codec can't decode bytes in position 2-4:
> invalid data
> ~~~
>
> It's strange because I made HTTP_ACCEPT_CHARSET header to only utf-8,
> and I have only unicode.
>
> as you can see here:
> http://hobbygiochi.com/xml/cat/da-vinci-games
>
> the page works, but not always.
>
> Any hint?
>
> Thanks in advance.
>



-- 
Alessandro Ronchi

http://www.soasi.com
SOASI - Sviluppo Software e Sistemi Open Source

http://hobbygiochi.com
Hobby & Giochi, l'e-commerce del divertimento

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django vs tornado

2010-03-08 Thread Rolando Espinoza La Fuente
On Thu, Mar 4, 2010 at 2:08 AM, Kenneth Gonsalves  wrote:
[...]
>
> I have stopped using it and till I can get something else up am using nginx
> proxied to runserver - which is faster than tornado and handles the latest
> django svn ok.

Could you explain more about the csrf_token issue?

I'm testing django on tornado and didn't find any issue using the
admin interface
which uses csrf_token. I'm using latest django from svn and latest
tornado from git.

You can check the source that I'm using here:
http://github.com/darkrho/django-on-tornado

Regards,

Rolando

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Python's Class members ...

2010-03-08 Thread Masklinn
On 8 Mar 2010, at 09:01 , JF Simon wrote:
> 
> Hi dudes,
> 
> My object seems mysterious, as is my problem ... I'd like to
> understand something (it's much more related to Python than Django).
> 
> Take an example :
> 
> class Image(models.Model):
>email = models.ForeignKey('Email', verbose_name=_(u'Email'))
>name = models.CharField(_(u'Name'), max_lenth=50,
> help_text=_(u'Must be unique for a given email'))
>content_id = models.CharField(_(u'Content ID'), max_length=25,
> db_index=True, default=self.slugify_name())
>[...]
> 
> "self" is not defined in the "default" kwarg for "content_id" field,
> it's because I'm not in an instance method (with self as first
> parameter). So what are those members, are they static for the class ?
> What is the difference between them and a member instantiated in the
> __init__ method whith self.field = [...] ?
> 
> If I replace the last field definition with :
> 
> from django.template.defaultfilters import slugify
> [...]
>content_id = models.CharField(_(u'Content ID'), max_length=25,
> db_index=True, default=slugify(name))
> 
> Eclipse don't show me an error ... will it work ? Why (not) ? I'm not
> sure to understand what I'm doing and it's weird.
It will 'work', but I doubt it's going to do what you want.

Here are how python class definitions work:

1. The body of the class (anything after class YourName:) is parsed and 
executed sequentially, as if it were module-level Python code (which is why you 
can have a class inside a class, for instance)
2. *After* the body of the class has executed, all of its content (the 
variables local to that body, which you can see by writing `print locals()` at 
the end of the class body) is collected and set as *class attributes*, with 
functions turned into methods.

Because a class body is "just code", you can:
1. Use things defined outside the class body (models or slugify, in your second 
snippet)
2. *Reference things previously defined in the body* (such as `name`).

Finally, you might very well be doing unnecessary work: Django already provides 
a SlugField (http://docs.djangoproject.com/en/dev/ref/models/fields/#slugfield) 
which — in the admin — can be prepopulated from your name using 
prepopulate_field 
(http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.prepopulated_fields).

If you want to set it in any case, you'll have to use __init__ I believe, but 
I'm sure others will be able to infirm that and show a better way.

But in this case, `slugify` is going to get passed a CharField, which probably 
isn't what you want.

Finally,

> So what are those members, are they static for the class ?

Well they are class attributes, but they're also instance attributes. They're 
one of those very-useful-but-not-necessaril-super-clear features: descriptors. 
See http://users.rcn.com/python/download/Descriptor.htm for a very good howto 
by Raymond Hettinger. Note that you could just as well go with "magic, gotcha" 
for now on that subject. They're basically class attributes which do special 
stuff when you invoke them from an instance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Python's Class members ...

2010-03-08 Thread JF Simon
Hi dudes,

My object seems mysterious, as is my problem ... I'd like to
understand something (it's much more related to Python than Django).

Take an example :

class Image(models.Model):
email = models.ForeignKey('Email', verbose_name=_(u'Email'))
name = models.CharField(_(u'Name'), max_lenth=50,
help_text=_(u'Must be unique for a given email'))
content_id = models.CharField(_(u'Content ID'), max_length=25,
db_index=True, default=self.slugify_name())
[...]

"self" is not defined in the "default" kwarg for "content_id" field,
it's because I'm not in an instance method (with self as first
parameter). So what are those members, are they static for the class ?
What is the difference between them and a member instantiated in the
__init__ method whith self.field = [...] ?

If I replace the last field definition with :

from django.template.defaultfilters import slugify
[...]
content_id = models.CharField(_(u'Content ID'), max_length=25,
db_index=True, default=slugify(name))

Eclipse don't show me an error ... will it work ? Why (not) ? I'm not
sure to understand what I'm doing and it's weird.

Thanks you for reading, I hope I'll understand !

PS : Sorry for my poor English.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.