Re: redirect after post caches anchor?
Hi Margie, I misunderstood you first post. What I said is valid, but it doesn't relate to your problem. Now that I get it: FF scrolls back to the same position after a reload. I don't know how to work around this issue unless you return a anchor "#top"(like you did with the another one) and add an attribute id="top" on your "body" tag. HTH, On Sun, Sep 13, 2009 at 1:55 AM, Margiewrote: > > Hi Tiago, > > Thanks very much for your response. So is there a way I can tell the > client that I don't want to retain the same anchor? IE, tell the > client to act as it would act if the client had initiated a new GET? > > Where would I find documentation on this? Or not necessarily doc but > just something that discusses this problem. My googling didn't turn > up much of anything but it seems like it would be a problem that > others have as well. > > Margie > > -- Tiago Serafim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: redirect after post caches anchor?
Hi Tiago, Thanks very much for your response. So is there a way I can tell the client that I don't want to retain the same anchor? IE, tell the client to act as it would act if the client had initiated a new GET? Where would I find documentation on this? Or not necessarily doc but just something that discusses this problem. My googling didn't turn up much of anything but it seems like it would be a problem that others have as well. Margie On Sep 12, 7:26 pm, Tiago Serafimwrote: > Hi, > > This is the expected, as HTTP clients doesn't pass the #anchors to the > server. > > On Sat, Sep 12, 2009 at 10:20 PM, Margie Roginski > wrote: > > > > > > > I'm seeing some strange behavior related to anchors that I can't > > really explain. I'm going to give an example of what I'm seeing and > > I'm hoping that someone can point me in the right direction. > > > Let's say I do a post and my views.py code that services the post > > returns like this: > > > return HttpResponseRedirect('/taskmanager/edit_task/12/ > > #comment_101') > > > (I am of course not hardcoding the redirect address - but have shown > > it explictly here for clarity) > > > This correctly displays my /taskmanager/edit_task/12 page, taking me > > part way down the page due to the #comment_101 anchor. > > > From this url I do a second post. The views.py code associated with > > this second post returns like this: > > > return HttpResponseRedirect('/taskmanager/edit_task/12') # note > > no comment_101 anchor > > > I thought this should take me to the top of my /taskmanager/edit_task/ > > 12 page, but instead it takes me to /taskmanager/edit_task/12/ > > #comment_101. It's like the #comment_101 anchor is cached in some > > way. > > > My runserver printouts from the second post and the get associated > > with its redirect show this: > > > [12/Sep/2009 18:16:51] "POST /taskmanager/edit_task/12/ HTTP/1.1" 302 > > 0 > > [12/Sep/2009 18:16:52] "GET /taskmanager/edit_task/12/ HTTP/1.1" 200 > > 50904 > > > So the #comment_101 is not there, yet it still appears in my firefox > > browser. Anyone know why this is? > > > Thanks, > > Margie > > -- > Tiago Serafim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: docstring format documentation for the admin doc contrib?
Thanks, that is what I was looking for. I also found this: http://docutils.sourceforge.net/docs/user/rst/quickref.html -Andrew On Sep 12, 9:26 pm, Tiago Serafimwrote: > Hi, > > These docs are in ReST (ReStructured Text) format, and each text file > > > corresponds to a Web page on the official Django site. > > source:http://docs.djangoproject.com/en/dev/faq/general/#how-can-i-download-... > > On Sun, Sep 13, 2009 at 12:21 AM, Andrew R > wrote: > > > > > > > The built in templates and filters have formatted docstrings (``, > > ===, etc.). I don't see anywhere where this syntax is documented. > > Where can I find information on this. > > > Example docstring: > > def yesno(value, arg=None): > > """ > > Given a string mapping values for true, false and (optionally) > > None, > > returns one of those strings accoding to the value: > > > == == > > == > > Value Argument Outputs > > == == > > == > > ``True`` ``"yeah,no,maybe"`` ``yeah`` > > ``False`` ``"yeah,no,maybe"`` ``no`` > > ``None`` ``"yeah,no,maybe"`` ``maybe`` > > ``None`` ``"yeah,no"`` ``"no"`` (converts None to > > False > > if no mapping for None is > > given. > > == == > > == > > """ > > > I would like to document my own filters and would like to understand > > the available syntax. Thanks. > > -- > Tiago Serafim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: docstring format documentation for the admin doc contrib?
Hi, These docs are in ReST (ReStructured Text) format, and each text file > corresponds to a Web page on the official Django site. > source: http://docs.djangoproject.com/en/dev/faq/general/#how-can-i-download-the-django-documentation-to-read-it-offline On Sun, Sep 13, 2009 at 12:21 AM, Andrew Rwrote: > > The built in templates and filters have formatted docstrings (``, > ===, etc.). I don't see anywhere where this syntax is documented. > Where can I find information on this. > > Example docstring: > def yesno(value, arg=None): >""" >Given a string mapping values for true, false and (optionally) > None, >returns one of those strings accoding to the value: > >== == > == >Value ArgumentOutputs >== == > == >``True````"yeah,no,maybe"`` ``yeah`` >``False`` ``"yeah,no,maybe"`` ``no`` >``None````"yeah,no,maybe"`` ``maybe`` >``None````"yeah,no"`` ``"no"`` (converts None to > False >if no mapping for None is > given. >== == > == >""" > > I would like to document my own filters and would like to understand > the available syntax. Thanks. > > > > -- Tiago Serafim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
docstring format documentation for the admin doc contrib?
The built in templates and filters have formatted docstrings (``, ===, etc.). I don't see anywhere where this syntax is documented. Where can I find information on this. Example docstring: def yesno(value, arg=None): """ Given a string mapping values for true, false and (optionally) None, returns one of those strings accoding to the value: == == == Value ArgumentOutputs == == == ``True````"yeah,no,maybe"`` ``yeah`` ``False`` ``"yeah,no,maybe"`` ``no`` ``None````"yeah,no,maybe"`` ``maybe`` ``None````"yeah,no"`` ``"no"`` (converts None to False if no mapping for None is given. == == == """ I would like to document my own filters and would like to understand the available syntax. 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-users@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: ImageField anti-duplication
I had not considered writing a custom Storage class. I may try that if there are no other alternatives. Any other ideas/solutions? On Sep 12, 5:31 am, vinilioswrote: > Have you read this ? > > http://docs.djangoproject.com/en/dev/howto/custom-file-storage/ > > haven't used any custom file storage yet but maybe using a custom file- > storage with a dummy save method when file exists is what you need. > > On Sep 12, 1:43 pm, "A. Rossi" wrote: > > > I have an application where users can upload images, then the image is > > renamed to a SHA256 hash of the file's contents. > > Here is the relevant snippet of the model > > > class ImagePost(Post): > > def imgurl(self, filename): > > import hashlib, os.path > > extension = os.path.splitext(filename) > > self.image.seek(0) > > return "images/%s%s" % (hashlib.sha256(self.image.read > > (self.image.size)).hexdigest(), extension[1]) > > > image = models.ImageField(upload_to=imgurl, blank=True) > > > what I am attempting to do is, if a user uploads an image that already > > exists (i.e. the two files have the exact same SHA256 hash) I want to > > have the ImageField point to the already existing file, rather than > > save the newly uploaded one. I have tried a couple things that didn't > > work, and the default behavior when dealing with files of the same > > name is to append an extra _ to the end of the name, before the > > extension. > > > I feel like I'm on the cusp of figuring this out, but I'm stuck. Also, > > would I put the code for this into the imgurl() function, create a > > custom storage object, in the view(s) directly? > > > Thank you for your help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: redirect after post caches anchor?
Hi, This is the expected, as HTTP clients doesn't pass the #anchors to the server. On Sat, Sep 12, 2009 at 10:20 PM, Margie Roginskiwrote: > > I'm seeing some strange behavior related to anchors that I can't > really explain. I'm going to give an example of what I'm seeing and > I'm hoping that someone can point me in the right direction. > > Let's say I do a post and my views.py code that services the post > returns like this: > > return HttpResponseRedirect('/taskmanager/edit_task/12/ > #comment_101') > > (I am of course not hardcoding the redirect address - but have shown > it explictly here for clarity) > > This correctly displays my /taskmanager/edit_task/12 page, taking me > part way down the page due to the #comment_101 anchor. > > From this url I do a second post. The views.py code associated with > this second post returns like this: > >return HttpResponseRedirect('/taskmanager/edit_task/12') # note > no comment_101 anchor > > I thought this should take me to the top of my /taskmanager/edit_task/ > 12 page, but instead it takes me to /taskmanager/edit_task/12/ > #comment_101. It's like the #comment_101 anchor is cached in some > way. > > My runserver printouts from the second post and the get associated > with its redirect show this: > > [12/Sep/2009 18:16:51] "POST /taskmanager/edit_task/12/ HTTP/1.1" 302 > 0 > [12/Sep/2009 18:16:52] "GET /taskmanager/edit_task/12/ HTTP/1.1" 200 > 50904 > > So the #comment_101 is not there, yet it still appears in my firefox > browser. Anyone know why this is? > > Thanks, > Margie > > > > > > > -- Tiago Serafim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Query with left join?
On Sat, Sep 12, 2009 at 8:55 PM, Daniel Rosemanwrote: > > On Sep 12, 9:53 pm, tom wrote: > > Hi, > > > > i want to produce a left-join query with the django orm. Can anybody > > help howto do the following query? > > > > SELECT S.value, D.value from data as S left join data as D on > > S.entry_id=D.entry_id; > > > > Cheers tom > > What's the point of this query? What are you trying to achieve? > > I believe Django will automatically do a left-join query if your > ForeignKey has null=False. But your question doesn't seem to be about > left join queries in general, it's about the specific case where you > join a table to itself. But without understanding why you'd want to do > what you're doing here, I can't answer. I believe the general reason for performing a query like this is to minimize the number of queries that have to be performed. What I think you want is select_related(). The docs don't mention ManyToMany fields but for ForeignKey fields it looks like it does what you are looking for. It's documented here: http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
Updating request.POST
Hi, I have the following scenario. I am creating a custom admin page for one of the models. I am adding few extra fields. If the extra fields are set, then the user does not need to set the model fields. An example is given below: Model A: val1 models.ForeignKey(A1) val2 models.ForeignKey(A2) val3 models.CharField() Form F: val_x_1 forms.CharField() Now, on the add/change page for Model A, I am giving an option. It would look like the following: Add A: -- val_x_1:[] val2: [] OR val1: [] val2: [] val3: [] [Save] [Save and Add Another] The user can either type in val1, val2 and val3 or he can put in values in val_x_1 and val2 only, and my custom add_view should take care of everything. Now, the whole page is working fine. But, I am unable to update request.POST to set up values for val1, val2 and val3 based on the values val_x_1 and val2. I created a mutable copy and tried putting that copy back to request.POST, but everytime I am getting the 'cant adapt' error. The backend is PostgreSQL. If I dont update request.POST, the form.validate would fail inside the proper add_view. I cannot make it as blank=True straightaway because if the val_x_1 and val2 is not updated by the user, he needs to update mandatorily val1, val2 and val3. Can anyone help me on 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-users@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 -~--~~~~--~~--~--~---
redirect after post caches anchor?
I'm seeing some strange behavior related to anchors that I can't really explain. I'm going to give an example of what I'm seeing and I'm hoping that someone can point me in the right direction. Let's say I do a post and my views.py code that services the post returns like this: return HttpResponseRedirect('/taskmanager/edit_task/12/ #comment_101') (I am of course not hardcoding the redirect address - but have shown it explictly here for clarity) This correctly displays my /taskmanager/edit_task/12 page, taking me part way down the page due to the #comment_101 anchor. >From this url I do a second post. The views.py code associated with this second post returns like this: return HttpResponseRedirect('/taskmanager/edit_task/12') # note no comment_101 anchor I thought this should take me to the top of my /taskmanager/edit_task/ 12 page, but instead it takes me to /taskmanager/edit_task/12/ #comment_101. It's like the #comment_101 anchor is cached in some way. My runserver printouts from the second post and the get associated with its redirect show this: [12/Sep/2009 18:16:51] "POST /taskmanager/edit_task/12/ HTTP/1.1" 302 0 [12/Sep/2009 18:16:52] "GET /taskmanager/edit_task/12/ HTTP/1.1" 200 50904 So the #comment_101 is not there, yet it still appears in my firefox browser. Anyone know why this is? Thanks, Margie --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: html template usage
I mean like one HTML template like the ones you download from monstertemplates. On Sat, 2009-09-12 at 13:59 -0700, tom wrote: > What do you mean with "existing HTML template" ? > > > On 12 Sep., 21:19, aftalaverawrote: > > Hi there, > > > > All I need is a sample (if available) or a working example on how to use > > an existing HTML template into the Django template system. Am I on the > > wrong track integrating both? > > > > 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-users@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 server static media secured by Django authentication
On Sep 13, 2:30 am, Jim Myerswrote: > I had looked at that page before, but had thought it only applied to > mod_python. > Does it also apply to mod_wsgi? If so, the page could be made > clearer. It doesn't. Read instead: http://code.google.com/p/modwsgi/wiki/AccessControlMechanisms This still will not help if wanting to secure pages using form/session based login. Use the X-Accel-Redirect/X-Sendfile/Location response headers instead as described elsewhere related to that future Django patch. Graham > On Sep 11, 10:49 pm, Gabriel Gunderson wrote: > > > > > On Fri, Sep 11, 2009 at 3:03 PM, Jim Myers wrote: > > > I have a requirement to serve static files only to users authenticated > > > through Django secure login. > > >http://docs.djangoproject.com/en/dev/howto/apache-auth/ > > > Gabe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Load Templates from outside TEMPLATE_DIRS
The template in question is to format my test results, and I didn't want to have lump it in with the production templates, or have the template directory permanently attached to the TEMPLATE_DIR So instead I've just loaded a new settings file with a modified TEMPLATE_DIR before I do my tests. Works pretty well. Thanks. On Sep 11, 8:58 pm, Kenneth Gonsalveswrote: > On Saturday 12 Sep 2009 9:26:15 ammviamariwrote: > > > I'm trying to load a template file from outside of TEMPLATE_DIRS, i.e. > > the template file does not reside in any of the template directories > > specified in TEMPLATE_DIRS. > > > Does anyone know if this is possible? I tried just specifying a path: > > i.e.'../../new_dir/template.html' but that doesn't seem to be working. > > > Any suggestions? > > what is the problem in specifying the directory in TEMPLATE_DIRS? > -- > regards > kghttp://lawgon.livejournal.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
Complex Query Optimization
I am trying to minimize the database hits. Take this example... from django.contrib.auth.models import User class Group(models.Model): # a bunch of fields here user = models.ForeignKey(User, related_name="groups") class Member(models.Model): # a bunch of fields here user = models.ForeignKey(User, related_name="members") groups= models.ForeignKey(Invitation, related_name="members") Basically the idea of the above is that given a user, you can fetch a list of members. Or, given a group, you can fetch a list of members belonging to that group. In one of my templates, I would like to paginate based on the groups, lets say 10 groups per page. But for each group displayed, I want to also display each member. The groups will be small enough so this won't be ridiculous. I feel confident than this can be done _without_ having to perform 11 queries per page (one for the groups, and then 1 for getting the members of each group). Am I correct? If so, how? Mildly off topic, I am trying to figure out what exactly happens when using MyModel.objects.all(). I understand that it is just an iterable but, using the example of pagination, when you do Paginator (MyModel.objects.all(), 10), is there no database hit until you get a specific page, where it will only fetch the 10 for the page it needs? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Query with left join?
On Sep 12, 9:53 pm, tomwrote: > Hi, > > i want to produce a left-join query with the django orm. Can anybody > help howto do the following query? > > SELECT S.value, D.value from data as S left join data as D on > S.entry_id=D.entry_id; > > Cheers tom What's the point of this query? What are you trying to achieve? I believe Django will automatically do a left-join query if your ForeignKey has null=False. But your question doesn't seem to be about left join queries in general, it's about the specific case where you join a table to itself. But without understanding why you'd want to do what you're doing here, I can't answer. -- 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-users@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: Return something specific on 404's on a particular path
> If they upload the image, you likely have the name of the file in your > database. Put a little IF statement in your templates. If you find > the name of the image in the db/context, serve it up. If you don't > find it, server up your default/placeholder image. Does that not > work? Yup. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Can I dereference a field in the output of a filter?
The with tag worked. Thanks. On Sep 12, 12:10 pm, Daniel Rosemanwrote: > On Sep 12, 8:08 pm, "W.P. McNeill" wrote: > > > > > > > I have a view that renders a table. The "table" object is a list > > rows, which are themselves lists of model objects. These objects have > > a parameter called label. > > > Inside the template > > > {{ object.label }} > > > render's an objects label and > > > {{ row|first }} > > > renders the first object in the row. > > > I want to be able to render the label of the first object in the row. > > I want to write something like this > > > {{ row|first.label }} > > > but that doesn't work. Is there equivalent syntax that does work > > within the template markup language? > > You might be able to use the {% with %} tag to assign the first row to > another variable, and use that. Untested: > > {% with row|first as first_row %} > {{ first_row.label }} > {% endwith %} > > Otherwise, you'll need a custom template tag - luckily these are very > easy to write. > -- > 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-users@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: html template usage
What do you mean with "existing HTML template" ? On 12 Sep., 21:19, aftalaverawrote: > Hi there, > > All I need is a sample (if available) or a working example on how to use > an existing HTML template into the Django template system. Am I on the > wrong track integrating both? > > 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-users@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 -~--~~~~--~~--~--~---
Query with left join?
Hi, i want to produce a left-join query with the django orm. Can anybody help howto do the following query? SELECT S.value, D.value from data as S left join data as D on S.entry_id=D.entry_id; Cheers tom --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
html template usage
Hi there, All I need is a sample (if available) or a working example on how to use an existing HTML template into the Django template system. Am I on the wrong track integrating both? 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-users@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: Can I dereference a field in the output of a filter?
On Sep 12, 8:08 pm, "W.P. McNeill"wrote: > I have a view that renders a table. The "table" object is a list > rows, which are themselves lists of model objects. These objects have > a parameter called label. > > Inside the template > > {{ object.label }} > > render's an objects label and > > {{ row|first }} > > renders the first object in the row. > > I want to be able to render the label of the first object in the row. > I want to write something like this > > {{ row|first.label }} > > but that doesn't work. Is there equivalent syntax that does work > within the template markup language? You might be able to use the {% with %} tag to assign the first row to another variable, and use that. Untested: {% with row|first as first_row %} {{ first_row.label }} {% endwith %} Otherwise, you'll need a custom template tag - luckily these are very easy to write. -- 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-users@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 invoke hasNoProfanities?
On Sep 12, 5:26 pm, Angel Cruzwrote: > I use the contribs.comments module, and in its clean_comment method: > > if settings.COMMENTS_ALLOW_PROFANITIES == False: > bad_words = [w for w in settings.PROFANITIES_LIST if w in > comment.lower()] > if bad_words: > > > The file is in: > Python25\Lib\site-packages\django\contrib\comment\forms.py > > It came for free, so I never stepped through this code. My mistake, you're right it's used in the comments framework. Brandon, if you're using the built-in comments form, then set COMMENTS_ALLOW_PROFANITIES to False and it should 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-users@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 -~--~~~~--~~--~--~---
Can I dereference a field in the output of a filter?
I have a view that renders a table. The "table" object is a list rows, which are themselves lists of model objects. These objects have a parameter called label. Inside the template {{ object.label }} render's an objects label and {{ row|first }} renders the first object in the row. I want to be able to render the label of the first object in the row. I want to write something like this {{ row|first.label }} but that doesn't work. Is there equivalent syntax that does work within the template markup language? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Editors of choice
I, like Nicolay, am using emacs too, with some nice packages that I've found along the way. Rope is installed in my ubuntu, but I don't know how to really use it yet. I hope I do. Learning Emacs pays a lot , especially since Emacs 23.1 ... , some of my packages are new versions of CEDET, etc. best, haroldo 2009/9/10 Nikolay Panov> > Emacs + ropemacs. > > Have a nice day, >Nikolay. > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Make a bold row in a table
On Sep 12, 3:12 pm, adelaide_mikewrote: > Django 1.0.2 In the following template I intend to make rows that > have an empty second column bold. Hence trying 2 in row. My syntax > is wrong due to inexperience with Python, and possibly my methodology > also. > > {% extends "base.html" %} > {% block content %} > > > Agent summary report > The most recent listing for each property listed within the past > 12 weeks > > > > > Address > Date > Price > Method > Agent > > Mobile > > > {% for row in listings %} > endifequal %} > > {% for item in row %} > {{ item }} > {% endfor %} > > > {% endfor %} > > > > > > > {% endblock %} > > Is there a way to do this? > > Mike Your methodology seems to be "guess the syntax". Looking in the documentation would be more fruitful. Or, do a search of this group, as this question comes up regularly. There are two ways of doing it - either use the {% cycle %} tag or use {% if forloop.counter|divisible_by:2 %} -- 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-users@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 -~--~~~~--~~--~--~---
app for user statistics of submissions/ activity/ etc ? app for geotagging?
is there an app out there that keeps track of user submissions / activity related to your models ? we want some sort of way of giving user feedback. whats the status of geotagging ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 server static media secured by Django authentication
I had looked at that page before, but had thought it only applied to mod_python. Does it also apply to mod_wsgi? If so, the page could be made clearer. On Sep 11, 10:49 pm, Gabriel Gundersonwrote: > On Fri, Sep 11, 2009 at 3:03 PM, Jim Myers wrote: > > I have a requirement to serve static files only to users authenticated > > through Django secure login. > > http://docs.djangoproject.com/en/dev/howto/apache-auth/ > > Gabe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 invoke hasNoProfanities?
I use the contribs.comments module, and in its clean_comment method: if settings.COMMENTS_ALLOW_PROFANITIES == False: bad_words = [w for w in settings.PROFANITIES_LIST if w in comment.lower()] if bad_words: The file is in: Python25\Lib\site-packages\django\contrib\comment\forms.py It came for free, so I never stepped through this code. On Sat, Sep 12, 2009 at 1:18 AM, Daniel Rosemanwrote: > > On Sep 11, 10:40 pm, Brandon wrote: > > Uh, where? I see the definition in settings.py, but I can certainly > > enter any of the words on the profanities list in: > > django.conf.global_settings.py into a text field and it will not throw > > an exception. > > > > I actually think that this is a left-over setting from old code that > has since been removed. The profanities checker was one of the > oldforms validators, which were removed before version 1.0. So the > setting is probably deprecated. > -- > 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-users@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: Make a bold row in a table
On Sat, Sep 12, 2009 at 4:12 PM, adelaide_mikewrote: > > Django 1.0.2 In the following template I intend to make rows that > have an empty second column bold. Hence trying 2 in row. My syntax > is wrong due to inexperience with Python, and possibly my methodology > also. > > {% extends "base.html" %} > {% block content %} > > > Agent summary report > The most recent listing for each property listed within the past > 12 weeks > > > > > Address > Date > Price > Method > Agent > > Mobile > > > {% for row in listings %} > endifequal %} >> > {% for item in row %} > {{ item }} > {% endfor %} > > > {% endfor %} > > > > > > > {% endblock %} > > Is there a way to do this? > > Mike add method to your model like should_be_bold which return boolean and use it in template like {% if row.should_be_bold %}class="bold"{%endif %} --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
Make a bold row in a table
Django 1.0.2 In the following template I intend to make rows that have an empty second column bold. Hence trying 2 in row. My syntax is wrong due to inexperience with Python, and possibly my methodology also. {% extends "base.html" %} {% block content %} Agent summary report The most recent listing for each property listed within the past 12 weeks Address Date Price Method Agent Mobile {% for row in listings %} {% for item in row %} {{ item }} {% endfor %} {% endfor %} {% endblock %} Is there a way to do this? Mike --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Editors of choice
Mostly Netbeans for me, however I do tend to use VIM quite a bit. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Couple of basic Django questions
Dan, this link helped me a lot for using my stylesheet and images on the test server. http://docs.djangoproject.com/en/dev/howto/static-files/ Mark --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 and CouchDB
Hi folks, I am too very fond of non-SQL databases (no fixed schema, built-in replication, built-in webserver, RESTful API, etc.). So far, in order to use Django with CouchDB here is what I have come across so far - http://lethain.com/entry/2008/aug/18/an-introduction-to-using-couchdb-with-django/ - http://couchdbkit.org/docs/formalchemy.html - http://couchdbkit.org/docs/django-extension.html >From my pov, having native support for non-SQL databases with Django would totally rock! Initially I was very skeptical too (I have been using MySQL/PostgreSQL/Oracle for more than five years now) but after I got to know CouchDB, I am convinced that using a non-SQL database is often a lot better (save me lot of time, easier data modeling, way better for web apps than SQL databases, etc.). --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: ImageField anti-duplication
Have you read this ? http://docs.djangoproject.com/en/dev/howto/custom-file-storage/ haven't used any custom file storage yet but maybe using a custom file- storage with a dummy save method when file exists is what you need. On Sep 12, 1:43 pm, "A. Rossi"wrote: > I have an application where users can upload images, then the image is > renamed to a SHA256 hash of the file's contents. > Here is the relevant snippet of the model > > class ImagePost(Post): > def imgurl(self, filename): > import hashlib, os.path > extension = os.path.splitext(filename) > self.image.seek(0) > return "images/%s%s" % (hashlib.sha256(self.image.read > (self.image.size)).hexdigest(), extension[1]) > > image = models.ImageField(upload_to=imgurl, blank=True) > > what I am attempting to do is, if a user uploads an image that already > exists (i.e. the two files have the exact same SHA256 hash) I want to > have the ImageField point to the already existing file, rather than > save the newly uploaded one. I have tried a couple things that didn't > work, and the default behavior when dealing with files of the same > name is to append an extra _ to the end of the name, before the > extension. > > I feel like I'm on the cusp of figuring this out, but I'm stuck. Also, > would I put the code for this into the imgurl() function, create a > custom storage object, in the view(s) directly? > > Thank you for your help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Generic view 'archive_year' not working
See thread http://groups.google.com/group/django-users/browse_thread/thread/f6f78545989cfbab On Aug 9, 1:31 pm, Matthewwrote: > I am using Django's generic views to create a blog site. The > templates I created, entry_archive_day, entry_archive_month, > entry_archive, and entry_detail all work perfectly, but > entry_archive_year does not. > > Instead, it is simply a blank page. It looks like it sees no objects > in 'object_list'. > > Details are included below: > > > urls.py > > > entry_info_dict = { > 'queryset': Entry.objects.all(), > 'date_field': 'pub_date', > } > > ... > > (r'^weblog/$', > 'django.views.generic.date_based.archive_index', # works with > 'latest', not 'object_list' > entry_info_dict), > # Weblog by year > (r'^weblog/(?P\d{4})/$', > 'django.views.generic.date_based.archive_year', # doesn't work > entry_info_dict), > # Weblog by month > (r'^weblog/(?P\d{4})/(?P\w{3})/$', > 'django.views.generic.date_based.archive_month', > entry_info_dict), > # Weblog by day > (r'^weblog/(?P\d{4})/(?P\w{3})/(?P\d{2})/$', > 'django.views.generic.date_based.archive_day', > ... > > > entry_archive_year: > > > > > > Entry Archive {{ year }} > > > {% for object in object_list %} > {{ object.title }} > > Published on {{ object.pub_date|date:"F j, Y" }} > > {% if object.excerpt_html %} > {{ object.excerpt_html|safe }} > {% else %} > {{ object.body_html|truncatewords_html:"50"|safe }} > {% endif %} > > Read full > entry > > {% endfor %} > > > > == > Output forhttp://localhost:8000/weblog/2009/aug/(notice 3 entries > for August): > == > > Latest! > > Published on August 9, 2009 > > Specific areas for enhancement: > > * Adding related objects should be easier. Now you have to "save and > continue" to get an extra set of fields to add a new related object. > You should be able to click "add new object" to add another set of > blank fields inline on the page ... > > Read full Entry > Practical Django Projects > > Published on August 9, 2009 > > It also will keep track of open tags and close them if it cuts off the > text before a closing tag. (A sep- arate filter, truncatewords, simply > cuts off at the specified number of words and pays no attention to > HTML.) > > Read full Entry > Star Wars > > Published on August 6, 2009 > > Star Wars used to be a great movie series. > > Read full Entry > > === > Output forhttp://localhost:8000/weblog/2009/is a blank page (no > errors). There should be at least 3 entries, demonstrated by > August. > === > > Thanks, > Matthew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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: Generic view 'archive_year' produces blank HTML page
Here is more information: http://stackoverflow.com/questions/1257943/generic-view-archiveyear-produces-blank-page On Aug 10, 8:35 pm, Alasdairwrote: > archive_year doesn't add a list of objects to the context by default. > Instead, it adds date_list, a list of months that have objects > available in the given year. > > To add object_list to the context, use the optional argument > make_object_list=True when calling archive_year. > > For more info, look at the docs > athttp://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-... > > Alasdair > > On Aug 11, 1:27 am, Matthew wrote: > > > I am using Django's generic views to create a blog site. The > > templates I created, entry_archive_day, entry_archive_month, > > entry_archive, and entry_detail all work perfectly, but > > entry_archive_year does not. > > > Instead, it is simply a blank page. It looks like it sees no objects > > in 'object_list'. > > > I know that 'archive' uses a 'latest' list instead of 'object_list', > > but that's not the case with 'archive_year', correct? > > > Thanks, > > Matthew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~--~~~~--~~--~--~---
ImageField anti-duplication
I have an application where users can upload images, then the image is renamed to a SHA256 hash of the file's contents. Here is the relevant snippet of the model class ImagePost(Post): def imgurl(self, filename): import hashlib, os.path extension = os.path.splitext(filename) self.image.seek(0) return "images/%s%s" % (hashlib.sha256(self.image.read (self.image.size)).hexdigest(), extension[1]) image = models.ImageField(upload_to=imgurl, blank=True) what I am attempting to do is, if a user uploads an image that already exists (i.e. the two files have the exact same SHA256 hash) I want to have the ImageField point to the already existing file, rather than save the newly uploaded one. I have tried a couple things that didn't work, and the default behavior when dealing with files of the same name is to append an extra _ to the end of the name, before the extension. I feel like I'm on the cusp of figuring this out, but I'm stuck. Also, would I put the code for this into the imgurl() function, create a custom storage object, in the view(s) directly? Thank you for your help. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 invoke hasNoProfanities?
On Sep 11, 10:40 pm, Brandonwrote: > Uh, where? I see the definition in settings.py, but I can certainly > enter any of the words on the profanities list in: > django.conf.global_settings.py into a text field and it will not throw > an exception. > I actually think that this is a left-over setting from old code that has since been removed. The profanities checker was one of the oldforms validators, which were removed before version 1.0. So the setting is probably deprecated. -- 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-users@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 -~--~~~~--~~--~--~---