Easy way to include Request Context always?
I'm still struggling a bit with template contexts What I want to do is put a code snippet in the header of my site base template that either presents the user with a small login form if they aren't authenticated or display a "Welcome! user" where user is linked to their profile. It seems I have to pass RequestContext(request) everytime I call render_to_response but I'm sure there's an easier way I'm missing. I've read through the docs and apologize if I'm missing it but can someone help with some advice? Thanks in advance. --~--~-~--~~~---~--~~ 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: Easy way to include Request Context always?
Thanks for the reply. I thought that might be the case but wanted to check. There is a very good blogpost about this very topic at Liconln Loop http://lincolnloop.com/blog/2008/may/10/getting-requestcontext-your-templates/ but it was made last year and I hoped there was a setting we could change or set to make it global. Thanks again. On Jul 5, 5:23 am, Ronghui Yu wrote: > I had the same problem. I didn't find a built-in way to solve this. But > I think you can implement a custom render_to_response, which calls the > built-in one in turn. > Then what you need to do is just importing your custome one. > > Streamweaver ??: > > > > > I'm still struggling a bit with template contexts > > > What I want to do is put a code snippet in the header of my site base > > template that either presents the user with a small login form if they > > aren't authenticated or display a "Welcome! user" where user is linked > > to their profile. > > > It seems I have to pass RequestContext(request) everytime I call > > render_to_response but I'm sure there's an easier way I'm missing. > > I've read through the docs and apologize if I'm missing it but can > > someone help with some advice? > > > Thanks in advance. > > -- > Ronghui Yu <mailto:stone...@163.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 -~--~~~~--~~--~--~---
user passes test or is owner
I'm new to decorators but using them in their basic form fine in Django so far. My problem is this. I have two model edit forms, each has an owner field that is a FK to a user. I also have some groups with permissions to edit the models. What I want to do is setup a 'is_owner_or_has_perm' decorator but I'm not sure how to handle the OR part of it all. It seems like I'd have to pass the decorator both the user and the object I wanted to edit and I"m not sure how to do that. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Queries for Related Objects wonky
I'm using Django 1.0.2 and having some problems with Related Object queries. For example I have a model called Project with a ForeignKey to a Django User. class Project(models.Model): ... owner = models.ForeignKey(User) ... by the documentation I would expect the following to give me a list of all Users who are owners of projects but it does not. User.objects.filter(project__owner__isnull=False) Instead it's returning a queryset of all users. Anyone have any insight into 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 -~--~~~~--~~--~--~---
Re: Design Tools any suggestions?
I use netbeans and there is a UML plugin that you can download and use for free. On Jul 10, 10:43 pm, dartdog wrote: > Starting to noodle out some system design stuff for Django > implementation does anyone have good ideas suggestions for useful > tools to encompass db (model) business logic and presentation > components, flow and how to tie them together. It seems that the most > obvious solution in freeware is dia? It would be nice to be able to > tie the result to lifecycle documentation? > > Thoughts?? Ideas, I'll run them down, with pointers! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Saving with unchanged value by default in ModelForm
When using a ModelForm object to edit data is there any way to tell Django to save only data included in the ModelForm object and keep whatever was in the other fields in the model? I find it a big barrier to have to explicitly define fields after commit=False just so they don't get nulled out, is there any easy way around this that anyone knows of? --~--~-~--~~~---~--~~ 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: Queries for Related Objects wonky
Filed a bug report about this. We'll see if they accept it. On Jul 10, 5:29 pm, Streamweaver wrote: > I'm using Django 1.0.2 and having some problems with Related Object > queries. > > For example I have a model called Project with a ForeignKey to a > Django User. > > class Project(models.Model): > ... > owner = models.ForeignKey(User) > ... > > by the documentation I would expect the following to give me a list of > all Users who are owners of projects but it does not. > > User.objects.filter(project__owner__isnull=False) > > Instead it's returning a queryset of all users. > > Anyone have any insight into 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 -~--~~~~--~~--~--~---
Re: Queries for Related Objects wonky
"They" are apparently people who read the documentation and understand better then "me". Sigh, and I thought I uncovered somethign, ah well. Simple error and thanks for clarifying. On Jul 13, 11:13 pm, Russell Keith-Magee wrote: > On Tue, Jul 14, 2009 at 10:31 AM, Streamweaver wrote: > >> For example I have a model called Project with a ForeignKey to a > >> Django User. > > >> class Project(models.Model): > >> ... > >> owner = models.ForeignKey(User) > >> ... > > >> by the documentation I would expect the following to give me a list of > >> all Users who are owners of projects but it does not. > > >> User.objects.filter(project__owner__isnull=False) > > >> Instead it's returning a queryset of all users. > > >> Anyone have any insight into this? > ... > > Filed a bug report about this. We'll see if they accept it. > > I'm not sure who "they" are supposed to be, but "they" won't accept > this ticket, because this isn't a bug. > > The query: > > User.objects.filter(project__owner__isnull=False) > > Querying on project__owner is essentially asking Django to traverse to > the project table so that it can query an attribute that is already > present on the user table - the ID. Django optimizes this query, and > doesn't do the join, since it already has the data locally. So, your > reduces to 'User.objects.filter(id__isnull=False)' - which is the same > as "User.objects.all()" > > What you need to do is query for the non-existence of a project > associated with a user: > > User.objects.filter(project__isnull=False) > > 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-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: Separate QuerySet into different lists inside templates
Why do it inside the template? Do it inside the view and pass each resultant queryset to the template. On Jul 16, 1:59 am, ZebraShaSha wrote: > This seems like a simple question, but it's been bugging me for days > now. I have two models, Events and Categories, where Events has a FKF > to Categories. I'm using django-Agenda, an add-on that I've modified > with the categories model, so all the views/urls are perfect in every > other way except they don't take into account this new model. > > That means that right now, the info_dict that's supplying all the > views is essentially Events.objects.all(). What I want to do, inside > of a template, is reorder the list of events into two lists, ordered > by events.categories.title or whatever. > > I've tried the reorder filter (didn't really work) and I've tried > multiple For and Ifequal loops, which was cumbersome and didn't scale > at all. I know this has to be a pretty common problem, but I can't > find any solutions. Suggestions? Any ideas? > > 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 -~--~~~~--~~--~--~---
Handling Varying Number of Fields in Model Form
I have a model with a number of attributes (some included as example below): class Release(models.Model): project_fk = models.ForeignKey(Project) title = models.CharField(max_length=30) summary = models.TextField() owner = models.ForeignKey(User) planning_status = models.CharField(max_length=1, choices=PS_CHOICES, default=PS_CHOICES[0][0]) development_status = models.CharField(max_length=1, choices=DEV_CHOICES, default=DEV_CHOICES[0][0]) point_estimate = models.IntegerField(choices=ESTIMATE_CHOICES, default=0) staffing_level = models.FloatField(default=0, choices=STAFF_CHOICES) internal_priority = models.IntegerField(default=0) created_on = models.DateField(auto_now=False, auto_now_add=True) last_updated = models.DateField(auto_now=True, auto_now_add=True) I want a varying number of these fields to appear in an edit form depending on the group a user belongs to. I was thinking I would have seperat form objects and specify the fields I need in each return, returning them in the view after testing for the proper user group. class ReleaseBasicForm(forms.ModelForm): """Form for basic release information.""" class Meta: model = Release fields = ( 'title', 'summary', 'owner' ) class ReleasePlanningForm(forms.ModelForm): """Form for release planning details.""" class Meta: model = Release fields = ( 'planning_status', 'staffing_level' ) class ReleaseDevelopmentForm(forms.ModelForm): """Form for release development details.""" class Meta: model = Release fields = ( 'development_status', 'point_estimate' ) I'm having trouble though understanding how I would process this form data. In a normal model form I'd have to save a form with 'commit=false' and then add back in whatever fields I excluded or it will save those as null. Since what fields will appear will change by user role though I'm not sure how best to approach this. Any help would be appreciated. --~--~-~--~~~---~--~~ 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: Handling Varying Number of Fields in Model Form
This seems hacky but it's something I've come up with so far that seems to do what I need it to. I have some issues with permissiosn to display still but I'm working on it. My veiw method is as follows: @login_required @has_perm_or_owner_of('can change release', Release) def update_release(request, project_fk, id): ''' Method for updating releases based on user group. This builds forms for display based on user permissions and roles and loads partial releae editing forms as appropriate. The actual validation and submission happens through a meta release form object and this saves me from having to explicitly define undeclaired fields. This is useful since those fields will changed based on user role. ''' release = get_object_or_404(Release, pk=id) forms = {} if request.method == 'POST': # Bind data to an all encompasing model form. baseform = ReleaseForm(request.POST, instance=release) # If the data is valid then save it. if baseform.is_valid(): form_instance = baseform.save(commit=False) form_instance.save() return HttpResponseRedirect('/project/%s/release/%s/' % (project_fk, release.id)) else: # If the data is not valid then return the individual forms and errors if request.user.has_perms('project.can_update_release') | request.user.id == release.owner.id: forms['basic'] = ReleaseBasicForm(request.POST, instance=release) if request.user.has_perms('project.can_update_plan'): forms['planning'] = ReleasePlanningForm(request.POST, instance=release) if request.user.has_perms ('project.can_update_development'): forms['development'] = ReleaseDevelopmentForm (request.POST, instance=release) else: baseform = ReleaseForm(instance=release) if request.user.has_perm('project.can_change_release') | request.user.id == release.owner.id: forms['basic'] = ReleaseBasicForm(instance=release) if request.user.has_perm('project.can_update_plan'): forms['planning'] = ReleasePlanningForm(instance=release) if request.user.has_perm('project.can_update_development'): forms['development'] = ReleaseDevelopmentForm (instance=release) return render_with_context(request, 'project/releaseedit.xhtml', { 'baseform': baseform, 'forms': forms, 'action': '%s/release/%s/edit/' % (release.project_fk.id, release.id), 'button': 'Update Release', 'title': 'Edit Release (%s)' % release.project_fk.title, }) On Jul 16, 4:05 pm, Streamweaver wrote: > I have a model with a number of attributes (some included as example > below): > > class Release(models.Model): > project_fk = models.ForeignKey(Project) > title = models.CharField(max_length=30) > summary = models.TextField() > owner = models.ForeignKey(User) > planning_status = models.CharField(max_length=1, > choices=PS_CHOICES, default=PS_CHOICES[0][0]) > development_status = models.CharField(max_length=1, > choices=DEV_CHOICES, default=DEV_CHOICES[0][0]) > point_estimate = models.IntegerField(choices=ESTIMATE_CHOICES, > default=0) > staffing_level = models.FloatField(default=0, > choices=STAFF_CHOICES) > internal_priority = models.IntegerField(default=0) > created_on = models.DateField(auto_now=False, auto_now_add=True) > last_updated = models.DateField(auto_now=True, auto_now_add=True) > > I want a varying number of these fields to appear in an edit form > depending on the group a user belongs to. > > I was thinking I would have seperat form objects and specify the > fields I need in each return, returning them in the view after testing > for the proper user group. > > class ReleaseBasicForm(forms.ModelForm): > """Form for basic release information.""" > class Meta: > model = Release > fields = ( > 'title', 'summary', 'owner' > ) > > class ReleasePlanningForm(forms.ModelForm): > """Form for release planning details.""" > class Meta: > model = Release > fields = ( > 'planning_status', 'staffing_level' > ) > > class ReleaseDevelopmentForm(forms.ModelForm): > &quo
ModelForm and saving with excluded Fields
I have been struggling with this for a few weeks without resolution and hope someone can help me. I have a model that I edit via a form but the field returned for editing vary depending on the user permissions and group. When I bind a form to POST data some fields may or may not be included in that post. All I really want to do is take the model I'm editing, change anything submitted by the POST data and leave the rest as is but I don't seem to be able to find a way to do this without having to explicitly declare each field. Is there a way around this or something I'm missing. Thanks in advance for any 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: ModelForm and saving with excluded Fields
To be clear. Essentially I just want to merge the object instance and POST data with the POST data overwriting the instance where it's supplied. Right now if I don't supply a field in my POST data it just submits null values. Thanks again and sorry for any repetition or frustration. On Jul 28, 5:25 pm, Streamweaver wrote: > I have been struggling with this for a few weeks without resolution > and hope someone can help me. > > I have a model that I edit via a form but the field returned for > editing vary depending on the user permissions and group. > > When I bind a form to POST data some fields may or may not be included > in that post. All I really want to do is take the model I'm editing, > change anything submitted by the POST data and leave the rest as is > but I don't seem to be able to find a way to do this without having to > explicitly declare each field. Is there a way around this or > something I'm missing. > > Thanks in advance for any 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 -~--~~~~--~~--~--~---
Template links when Django not domain root
I have a django project that has worked just fine in development but I'm trying to move it to a demo site and the application is not on a root domain or sub-domain. Instead the site root URL is suppose to be something like https://site.domain.com/appname/ This is causing all my template links to break. The {% url %} tag seems to work only for the site root and doesn't bring in the subdirectory name. What's the Django way of handling this? I'm surprised I haven't been able to find something about 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 -~--~~~~--~~--~--~---
Re: Template links when Django not domain root
I'm not actually using {% url %} at this time. I am setup for mod_wsgi and don't know how to go about configuring links in the templates when the sites root is on a subdirectory. There isn't much in the way of examples on FORCE_SCRIPT_NAME I can find and I'm not really an apache admin so I'm a bit out of my depth here. Is this the avenue I should be pursuing or is there some way to set this up better. the url filter seems to violate DRY methodology. Thanks again. On Jul 30, 9:52 pm, Graham Dumpleton wrote: > Using FORCE_SCRIPT_NAME is only appropriate for certain WSGI hosting > mechanisms. Using it may simply hide the fact that the OPs application > code is wrong to begin with. > > OP should indicate how they are hosting their application for real > site. Ie., mod_python, mod_wsgi, fastcgi or other. > > Graham > > On Jul 31, 6:04 am, Alex Koshelev wrote: > > > If you are using `{% url %}` template tag or `reverse` function you can set > > FORCE_SCRIPT_NAME [1] settings variable specified for your deployment > > project root. Or working with right web-server in front of django project > > force it to tell proper SCRIPT_NAME himself. > > > [1]:http://docs.djangoproject.com/en/dev/ref/settings/#force-script-name > > > --- > > Alex Koshelev > > > On Thu, Jul 30, 2009 at 10:55 PM, Streamweaver > > wrote: > > > > I have a django project that has worked just fine in development but > > > I'm trying to move it to a demo site and the application is not on a > > > root domain or sub-domain. > > > > Instead the site root URL is suppose to be something like > > >https://site.domain.com/appname/ > > > > This is causing all my template links to break. The {% url %} tag > > > seems to work only for the site root and doesn't bring in the > > > subdirectory name. > > > > What's the Django way of handling this? I'm surprised I haven't been > > > able to find something about 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 -~--~~~~--~~--~--~---
Re: Template links when Django not domain root
Thanks for the great replies here. It seems from this there might be less repetition if I can just put a SITE_URL attribute in my settings.py file and then make that available to the template without having to go through the view. Is this possible or easy? Custom template filter perhaps but these seem pretty complicated and more intended to work like decorators than just pushing variables to the template. Hmmm, not sure. On Jul 31, 1:42 pm, Adam Yee wrote: > On Jul 30, 7:29 pm, Graham Dumpleton > wrote: > > > > > If you are using mod_wsgi then you definitely do not need > > FORCE_SCRIPT_NAME as mod_wsgi does the correct think in respect of > > setting up SCRIPT_NAME/PATH_INFO. The only time it might not be right > > with mod_wsgi is if you used WSGIScriptAliasMatch to map the > > application and you didn't set up the directive properly. This can > > happen because how you set up pattern and target for that directive > > will control how SCRIPT_NAME is calculated. WSGIScriptAliasMatch > > should only be used if absolutely required. > > > So, post how you configured mod_wsgi to mount your application just to > > eliminate that as possibility. Verify that FORCE_SCRIPT_NAME isn't set > > in settings.py or if it is that it is set to None. > > > Someone with more Django knowledge would then need to tell you if you > > are specifying urls.py correctly, whether any other settings you need > > to check and whether how URL references are generated are correct. All > > I can tell you is that if mod_wsgi is set up properly, you should > > never need FORCE_SCRIPT_NAME with mod_wsgi. > > > You may need to explain better what is meant by 'This is causing all > > my template links to break'. Ie., what errors are you getting, what > > are the URLs it is generating and what they should be etc. > > > Graham > > > On Jul 31, 12:09 pm, Streamweaver wrote: > > > > I'm not actually using {% url %} at this time. I am setup for > > > mod_wsgi and don't know how to go about configuring links in the > > > templates when the sites root is on a subdirectory. There isn't much > > > in the way of examples on FORCE_SCRIPT_NAME I can find and I'm not > > > really an apache admin so I'm a bit out of my depth here. > > > > Is this the avenue I should be pursuing or is there some way to set > > > this up better. the url filter seems to violate DRY methodology. > > > > Thanks again. > > > > On Jul 30, 9:52 pm, Graham Dumpleton > > > wrote: > > > > > Using FORCE_SCRIPT_NAME is only appropriate for certain WSGI hosting > > > > mechanisms. Using it may simply hide the fact that the OPs application > > > > code is wrong to begin with. > > > > > OP should indicate how they are hosting their application for real > > > > site. Ie., mod_python, mod_wsgi, fastcgi or other. > > > > > Graham > > Graham is right about needing to mount your site correctly. Post your > Apache config athttp://groups.google.com/group/modwsgi?hl=enand they > can help with that. I've not had to use FORCE_SCRIPT_NAME when using > mod_wsgi. What I found that works is passing the script_name in each > view context. This is violating DRY, but I haven't worried about that > too much. This is a way to make apps portable. If you still need or > want to use the {% url %} tag, you just need to preceed it by a > {{ script_name }} (I'm mostly sure, correct me if wrong). You can > give script_name to your context with request.META['SCRIPT_NAME'] if > it exists. > > hope this helps, > Adam > > > > > On Jul 31, 6:04 am, Alex Koshelev wrote: > > > > > > If you are using `{% url %}` template tag or `reverse` function you > > > > > can set > > > > > FORCE_SCRIPT_NAME [1] settings variable specified for your deployment > > > > > project root. Or working with right web-server in front of django > > > > > project > > > > > force it to tell proper SCRIPT_NAME himself. > > > > > > [1]:http://docs.djangoproject.com/en/dev/ref/settings/#force-script-name > > > > > > --- > > > > > Alex Koshelev > > > > > > On Thu, Jul 30, 2009 at 10:55 PM, Streamweaver > > > > > wrote: > > > > > > > I have a django project that has worked just fine in development but > > > > > > I'm trying to move it to a demo site and the application is not on a > > > > > > root domain or sub-domain. > >
Re: Template links when Django not domain root
Thanks. I'm not trying to jump the solution. I'm not the server admin and I have to wait until the weekend is over to get that information from them and I will definitely post it. I was simply asking a question. Trying to come up with a template contexts SITE_URL property isn't an out of bounds question, most templating engines use something like this and just asking the question isnt' a hack. It's just a question. On Aug 1, 6:54 pm, Graham Dumpleton wrote: > Hacks which embed knowledge of the mount point in the application > generally indicate that you are doing something wrong in your > configuration. > > Stop trying to jump to solutions when hasn't even been determined what > you are doing wrong. > > As suggested, post the mod_wsgi configuration you are using so can > confirm that for starters, that that isn't the problem. > > Graham > > On Aug 2, 3:40 am, Streamweaver wrote: > > > Thanks for the great replies here. > > > It seems from this there might be less repetition if I can just put a > > SITE_URL attribute in my settings.py file and then make that available > > to the template without having to go through the view. Is this > > possible or easy? Custom template filter perhaps but these seem > > pretty complicated and more intended to work like decorators than just > > pushing variables to the template. Hmmm, not sure. > > > On Jul 31, 1:42 pm, Adam Yee wrote: > > > > On Jul 30, 7:29 pm, Graham Dumpleton > > > wrote: > > > > > If you are using mod_wsgi then you definitely do not need > > > > FORCE_SCRIPT_NAME as mod_wsgi does the correct think in respect of > > > > setting up SCRIPT_NAME/PATH_INFO. The only time it might not be right > > > > with mod_wsgi is if you used WSGIScriptAliasMatch to map the > > > > application and you didn't set up the directive properly. This can > > > > happen because how you set up pattern and target for that directive > > > > will control how SCRIPT_NAME is calculated. WSGIScriptAliasMatch > > > > should only be used if absolutely required. > > > > > So, post how you configured mod_wsgi to mount your application just to > > > > eliminate that as possibility. Verify that FORCE_SCRIPT_NAME isn't set > > > > in settings.py or if it is that it is set to None. > > > > > Someone with more Django knowledge would then need to tell you if you > > > > are specifying urls.py correctly, whether any other settings you need > > > > to check and whether how URL references are generated are correct. All > > > > I can tell you is that if mod_wsgi is set up properly, you should > > > > never need FORCE_SCRIPT_NAME with mod_wsgi. > > > > > You may need to explain better what is meant by 'This is causing all > > > > my template links to break'. Ie., what errors are you getting, what > > > > are the URLs it is generating and what they should be etc. > > > > > Graham > > > > > On Jul 31, 12:09 pm, Streamweaver wrote: > > > > > > I'm not actually using {% url %} at this time. I am setup for > > > > > mod_wsgi and don't know how to go about configuring links in the > > > > > templates when the sites root is on a subdirectory. There isn't much > > > > > in the way of examples on FORCE_SCRIPT_NAME I can find and I'm not > > > > > really an apache admin so I'm a bit out of my depth here. > > > > > > Is this the avenue I should be pursuing or is there some way to set > > > > > this up better. the url filter seems to violate DRY methodology. > > > > > > Thanks again. > > > > > > On Jul 30, 9:52 pm, Graham Dumpleton > > > > > wrote: > > > > > > > Using FORCE_SCRIPT_NAME is only appropriate for certain WSGI hosting > > > > > > mechanisms. Using it may simply hide the fact that the OPs > > > > > > application > > > > > > code is wrong to begin with. > > > > > > > OP should indicate how they are hosting their application for real > > > > > > site. Ie., mod_python, mod_wsgi, fastcgi or other. > > > > > > > Graham > > > > Graham is right about needing to mount your site correctly. Post your > > > Apache config athttp://groups.google.com/group/modwsgi?hl=enandthey > > > can help with that. I've not had to use FORCE_SCRIPT_NAME when using > > > mod_wsgi. What I found tha
django-pagination with search form
Simple Pagination in Django is great but I'm having some trouble with the best way to design pagination with querysets derived from Search Forms. I'm currently using the Django-Pagination middleware and it works great but there's really pretty bad documentation on it (as with many projects) and I can't figure the best way to pass search form parameters between pages. Is there a recommended Django way to handle this? GET paams, Sessions, Cache? I'm surprised I can't find more discussion or examples on this so that could indicate I'm missing something very obvious and apologize before hand if I am but could use a point in the right direction. --~--~-~--~~~---~--~~ 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 TimeField Model without seconds
I'm not really sure you can but I'm also not clear why this is a problem. It would seem easy to just not use seconds and filter them out in the template and views as needed. Is this practical for your needs or is there a specific benefit you're seeking by filtering out seconds from the field? On Aug 6, 1:26 pm, Hellnar wrote: > Greetings, I am trying to implement a TimeField model which only > consists of HH:MM (ie 16:46) format, I know it is possible to format a > regular Python time object but I am lost about how to manage this with > Django. > > Cheers --~--~-~--~~~---~--~~ 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/ Python 3 - nervous about starting large project
I came from the PHP world myself and am even doing some of it still but I don't think what you're saying is of particular concern. Even in PHP you have to worry about differences in PHP 4 and 5 and so on so the concern itself isn't just a Python one. I can say that support for Python 2.6 will be around for a long time and transitions in Python for me have always been much easier than in PHP. If you're fairly new to Python I doubt you're really venturing into the areas that will be of major concern in a transition as well. Good luck with it and Welcome to the Python end of the pool. On Aug 5, 4:47 pm, snfctech wrote: > Hello. > > We are researching technologies to begin what may become a pretty > large intranet Dashboard project. > > I'm a PHP developer, so the fact that Django uses Python doesn't give > me a head-start - but I've been wanting to consider it, because I am > interested in learning Python. > > However, I'm nervous about the Python 3 situation. What if I start > building a large project based on Django/Python 2.6, and then a year > or two down the road the project starts limping because of all of the > cool new Python 3 modules coming out? And I've got a bunch of Django/ > Python 2.6 code that needs to be ported? > > Any tips would be greatly appreciated. Thanks. > > Tony --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Continuing problems running Django when not site Root.
There's been some discussion here about what to do when you're trying to run a Django site not under the root domain. So for a site like http://mysite.com/django/ Django (or WSGI?) doesn't seem to be able to be able to handle the SCRIPT_NAME ('/django' in this example) portion of the url well. You have to add the request context to the application and views as well as account for it in the templates. Fair enough I guess and I refactored my application to handle this so far. I'm running into pretty big problems with using Django's login framework in this context. First there are the various login settings of 'LOGIN_URL' and such, and these can't be passed a context. I got around this by adding another variable to the settings file I can see in addition to having to read the SCRIPT_NAME in the views and templates. I continue to have a problem though in that the generic login functions seem to have no way to handle SCRIPT_NAME and I suspect this problem extends to generic views in general. Is there anyway around this? Anyone know if fixing this on the Django roadmap? --~--~-~--~~~---~--~~ 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: Continuing problems running Django when not site Root.
I appreciate all the comment here and I definitly could be missing something. I tried backing out to a fresh install as requested above. The issue as best I can understand it lies in the default login scripts provided which are called as follows in my urls.py file (r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'accounts/login.xhtml'}), (r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'template_name': 'accounts/logout.xhtml'}) The templates that normally handle rendering the SCRIPT_NAME property don't do so here I think because this script isn't being passed the RequestContext like other scripts. I'll take a look at the source code for these items and it's likely I can pass a property to it but I'm a bit unsure how since the request object isn't passed to urls.py as far as I know. If you have more insight it would be helpful but so far my investigation seems to be turning up that I can't use these magic methods. Thanks again and I'll keep looking this weekend and post if I find what I'm doing wrong. On Aug 7, 10:49 pm, Malcolm Tredinnick wrote: > On Fri, 2009-08-07 at 14:44 -0700, Streamweaver wrote: > > [...] > > > Is there anyway around this? Anyone know if fixing this on the Django > > roadmap? > > It was fixed over a year ago (before Django 1.0 came out). If you are > using anything later than that, you don't have to do *anything* to worry > about SCRIPT_NAME, although the variable is set in the request.META > dictionary so you can use it to construct URLs if you want to do that > manually. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: Continuing problems running Django when not site Root.
Let me clarify. This method handles the RequestContext obviously since it's a login but what I mean is the SCRIPT_NAME variable isn't set for the template and can't be read as far as I can tell. On Aug 8, 4:15 pm, Streamweaver wrote: > I appreciate all the comment here and I definitly could be missing > something. > > I tried backing out to a fresh install as requested above. > > The issue as best I can understand it lies in the default login > scripts provided which are called as follows in my urls.py file > > (r'^accounts/login/$', 'django.contrib.auth.views.login', > {'template_name': 'accounts/login.xhtml'}), > (r'^accounts/logout/$', 'django.contrib.auth.views.logout', > {'template_name': 'accounts/logout.xhtml'}) > > The templates that normally handle rendering the SCRIPT_NAME property > don't do so here I think because this script isn't being passed the > RequestContext like other scripts. I'll take a look at the source > code for these items and it's likely I can pass a property to it but > I'm a bit unsure how since the request object isn't passed to urls.py > as far as I know. > > If you have more insight it would be helpful but so far my > investigation seems to be turning up that I can't use these magic > methods. > > Thanks again and I'll keep looking this weekend and post if I find > what I'm doing wrong. > > On Aug 7, 10:49 pm, Malcolm Tredinnick > wrote: > > > On Fri, 2009-08-07 at 14:44 -0700, Streamweaver wrote: > > > [...] > > > > Is there anyway around this? Anyone know if fixing this on the Django > > > roadmap? > > > It was fixed over a year ago (before Django 1.0 came out). If you are > > using anything later than that, you don't have to do *anything* to worry > > about SCRIPT_NAME, although the variable is set in the request.META > > dictionary so you can use it to construct URLs if you want to do that > > manually. > > > Regards, > > Malcolm --~--~-~--~~~---~--~~ 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: Continuing problems running Django when not site Root.
Okay I am finnally getting my brain around this. Thanks so much. I tried the code out and it works great, even on the login. I appreciate everyone's help and patience. On Aug 8, 9:49 pm, Malcolm Tredinnick wrote: > On Sat, 2009-08-08 at 13:41 -0700, Streamweaver wrote: > > Let me clarify. This method handles the RequestContext obviously since > > it's a login but what I mean is the SCRIPT_NAME variable isn't set for > > the template and can't be read as far as I can tell. > > Nothing is automatically set for a template. If you want access to a > particular quantity in a template, pass it in. You could even create a > context processor if you want it every time. Typically, SCRIPT_NAME is > *not* required in templates, since things like the url template tag > already handle it automatically and constructing the correct URL for > many things is more complex than just crashing together a few strings, > so it tends to be done via template tags or in views. Thus, SCRIPT_NAME > isn't a likely candidate for something that would be passed in all the > time. > > Regards, > Malcolm --~--~-~--~~~---~--~~ 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: Possible to use Django & MySQL with Python 2.6?
It works fine for me with Python 2.6 on Linux (with the errors mentioned above) . Windows is a bit of a problem as the mysql-python library doesn't yet support 2.6. On Aug 17, 12:32 am, Continuation wrote: > According to the site of the python MySQL driver it only supports > Python 2.3 - 2.5:http://sourceforge.net/projects/mysql-python/ > > So is it possible to use Django & MySQL with Python 2.6? Is there any > workaround I can do to make it work? --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
displaying links based on permissions and object ownership
I may have a similar post to this that was submitted accidentally as I fat-fingered a key. Sorry about that. I'm having a bit of confusion as to how to best approach the display of edit/delete/create links in my templates as my application needs this to be based on group permissions OR cascading object owenership. The situation is I have two models with a FK relationship and each has a method to check if a user is the owner of that object or it's parent object. class Project(models.Model): owner = models.ForeignKey(User) def is_owner(self, user): if user == self.owner: return True return False ... class Release(models.Model): owner = models.ForeignKey(User) def is_owner(self, user): if user == self.owner: return True if self.project_fk.is_owner(user): return True return False For permission checking in my views this was pretty straight forward. I created a decorator called has_perm_or_owner that checks for particular permissions or if a user is an object owner. My question is how do I handle similar checks in my templates? I can easily display a link based on permissions and can even display them based on weather the logged in user is the owner of a particular object being edited and such, but how do I get it to use this cascading check? Thanks in advance for any 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 -~--~~~~--~~--~--~---
displaying links based on permissions and object ownership
I'm having a bit of confusion as to how to best approach the display of edit/delete/create links in my templates as my application needs this to be based on group permissions OR cascading object owenership. The situation is I have two models with a FK relationship and each has a method to check if a user is the owner of that object or it's parent object. class Project(models.Model): owner = models.ForeignKey(User) def is_owner(self, user): ''' Encapulated method for checking owner ship. Required for dectorators. ''' if user == self.owner: return True return False ... --~--~-~--~~~---~--~~ 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: displaying links based on permissions and object ownership
Right. I think option A makes the most sense but I wanted to float the question here. I should probably pass the template something and rework this in my views. Thanks, - Scott On Aug 20, 12:28 pm, Javier Guerra wrote: > On Thu, Aug 20, 2009 at 11:00 AM, Streamweaver wrote: > > For permission checking in my views this was pretty straight forward. > > I created a decorator called has_perm_or_owner that checks for > > particular permissions or if a user is an object owner. > > > My question is how do I handle similar checks in my templates? > > two solutions: > > a) you don't. the view should check and give the template only what's needed > > b) the 'django.core.context_processors.auth' context processor (which > is in the default if you use RequestContext) includes the {{perms}} > object:http://docs.djangoproject.com/en/dev/topics/auth/#authentication-data... > > -- > 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-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 -~--~~~~--~~--~--~---
Related ownership for items that dont' exist yet?
Sorry if I'm getting a little far out here. I have two models, a parent and a child with a FK relationship (See the code below for example) and I have a method in each called is_owner. For the child it checks to see if a user passed is the objects owner OR if that user passes the parents is_owner method. I use this in a decorator that I use in views to give permission for updating or deleting based on checking permissions OR if they pass the objects is_owner check. My problem is with new child objects. How would I check for new child objects if the parent is an owner so they can get the proper Form to create it? class Project(models.Model): owner = models.ForeignKey(User) def is_owner(self, user): if user == self.owner: return True return False class Release(models.Model): project_fk = models.ForeignKey(Project) owner = models.ForeignKey(User) def is_owner(self, user): if user == self.owner: return True if self.project_fk.is_owner(user): return True return False --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Users Full Name in model form?
I had a model that lists an owner with a FK relationship to the Users table. When using model form the dropdown for the owner field defaults to the username. I'd like to override that to use a users name as the choice portion of the dropdown sorted by users last name but I'm having trouble thinking through how to do this. Can anyone point me to an example of something like 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 -~--~~~~--~~--~--~---
Re: Users Full Name in model form?
I put a solituion for this in the form of where this is passed a user object. class UserChoiceField(forms.ModelChoiceField): ''' Returns a select field with user names formatted by last and first name where available and ordered by last name. ''' def label_from_instance(self, obj): if obj.last_name or obj.first_name: display = ", ".join((obj.last_name, obj.first_name)) else: display = obj.username return display On Sep 4, 2:26 pm, Streamweaver wrote: > I had a model that lists an owner with a FK relationship to the Users > table. > > When using model form the dropdown for the owner field defaults to the > username. > > I'd like to override that to use a users name as the choice portion of > the dropdown sorted by users last name but I'm having trouble thinking > through how to do this. > > Can anyone point me to an example of something like 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 -~--~~~~--~~--~--~---
Re: Users Full Name in model form?
This was through a custom form in a public view. I haven't done much with admin forms but maybe someone else knows? On Sep 4, 4:50 pm, Anthony Simonelli wrote: > Is this within the Admin interface? If so, I'm having a similar > problem. I have a model called Request with a FK relationship to an > Employee model. Within the Admin interface, when adding a Request, > the drop-down of the Employees selection read "Employee Object". This > is also the case when listing the Employees. There is no way to > distinguish between the employees. > > How do I change, what I think is called the "string representation" of > the object within the Admin interface. Also, is there some sort of > naming convention when creating models to get these fields > automatically? > > On Fri, Sep 4, 2009 at 1:26 PM, Streamweaver wrote: > > > I had a model that lists an owner with a FK relationship to the Users > > table. > > > When using model form the dropdown for the owner field defaults to the > > username. > > > I'd like to override that to use a users name as the choice portion of > > the dropdown sorted by users last name but I'm having trouble thinking > > through how to do this. > > > Can anyone point me to an example of something like 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 -~--~~~~--~~--~--~---
Having Trouble with Reverse method
I'm having trouble understanding the output of the reverse method. I have the following URL pattern: urlpatterns = patterns('dwrangler.project.views', (r'^in_development/$', 'summary_in_development'), ) from the documentation I would think I can get the URL by using reverse('dwrangler.project.views.summary_in_development') But I keep getting a NoReverseMatch error. I have tried several different formats but keep getting similar errors. I must be missing something obvious and would be thankful if something could point me in the right direction. 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: Having Trouble with Reverse method
Thanks for all the replies. I'm on Django 1.0.2 btw if it makes a difference, I see the extra-patterns. I'm also running this via the manage.py runserver on a development machine and not in staging or production. For the original authors, those variations turn up the same error. To Peters enumerated questions. 1. yep it resolves fine. 2. It seems to be. It's replicated in both settings.py and localsettings.py. 3. the ROOT_URLCONF points to my base app urls.py and that points to the subsequent urls.py under that project via the line (r'^project/', include('dwrangler.project.urls')). Both of these contain a urlpatterns attribute. So the method I'm calling isn't in dwrangler.urls but in dwrangler.project.urls Additional curiousities, if I kill the lighthttp server and restart it I get a new error: "Caught an exception while rendering: Reverse for 'dwrangler.project- root' with arguments '()' and keyword arguments '{}' not found." This is interesting because it's throwing the error message for a template tag that has worked that calls a names URL pattern in the dwrangler.project.urls file. So this seems to be only reading from the dwrangler.urls file and not the included dwrangler.project.urls I'm still struggling with this so any other insight may help. Thanks for all the feedback so far. On Sep 8, 5:31 pm, Peter Coles wrote: > What you provided looks correct -- which means that something else is > probably broken... > > Some things to investigate: > > 1. If you manually go that url: http:/in_development/ > does anything get served? > 2. Is your ROOT_URLCONF setup to properly point to this file in your > settings file? > 3. Is this another url file than the one defined in your ROOT_URLCONF? > If so are you properly "including" this one from your root urls.py? > Details on include > here:http://docs.djangoproject.com/en/dev/topics/http/urls/#including-othe... > > You'll find a wealth of information about urls in django > here:http://docs.djangoproject.com/en/dev/topics/http/urls/ > > Once you get it working, you may find it more convenient to use named > url > patterns:http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-pat... > > On Sep 8, 1:49 pm, Streamweaver wrote: > > > I'm having trouble understanding the output of the reverse method. > > > I have the following URL pattern: > > > urlpatterns = patterns('dwrangler.project.views', > > (r'^in_development/$', 'summary_in_development'), > > ) > > > from the documentation I would think I can get the URL by using > > > reverse('dwrangler.project.views.summary_in_development') > > > But I keep getting a NoReverseMatch error. I have tried several > > different formats but keep getting similar errors. > > > I must be missing something obvious and would be thankful if something > > could point me in the right direction. > > > 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: Having Trouble with Reverse method
Yet more info here. This might be a particular problem due to the particular method being called in multiple URL patterns so I tried making it and calling a named URL pattern but am getting the same message. On Sep 9, 5:18 pm, Streamweaver wrote: > Thanks for all the replies. I'm on Django 1.0.2 btw if it makes a > difference, I see the extra-patterns. I'm also running this via the > manage.py runserver on a development machine and not in staging or > production. > > For the original authors, those variations turn up the same error. > > To Peters enumerated questions. > > 1. yep it resolves fine. > 2. It seems to be. It's replicated in both settings.py and > localsettings.py. > 3. the ROOT_URLCONF points to my base app urls.py and that points to > the subsequent urls.py under that project via the line > (r'^project/', include('dwrangler.project.urls')). Both of these > contain a urlpatterns attribute. > > So the method I'm calling isn't in dwrangler.urls but in > dwrangler.project.urls > > Additional curiousities, if I kill the lighthttp server and restart it > I get a new error: > > "Caught an exception while rendering: Reverse for 'dwrangler.project- > root' with arguments '()' and keyword arguments '{}' not found." > > This is interesting because it's throwing the error message for a > template tag that has worked that calls a names URL pattern in the > dwrangler.project.urls file. So this seems to be only reading from > the dwrangler.urls file and not the included dwrangler.project.urls > > I'm still struggling with this so any other insight may help. > > Thanks for all the feedback so far. > > On Sep 8, 5:31 pm, Peter Coles wrote: > > > What you provided looks correct -- which means that something else is > > probably broken... > > > Some things to investigate: > > > 1. If you manually go that url: http:/in_development/ > > does anything get served? > > 2. Is your ROOT_URLCONF setup to properly point to this file in your > > settings file? > > 3. Is this another url file than the one defined in your ROOT_URLCONF? > > If so are you properly "including" this one from your root urls.py? > > Details on include > > here:http://docs.djangoproject.com/en/dev/topics/http/urls/#including-othe... > > > You'll find a wealth of information about urls in django > > here:http://docs.djangoproject.com/en/dev/topics/http/urls/ > > > Once you get it working, you may find it more convenient to use named > > url > > patterns:http://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-pat... > > > On Sep 8, 1:49 pm, Streamweaver wrote: > > > > I'm having trouble understanding the output of the reverse method. > > > > I have the following URL pattern: > > > > urlpatterns = patterns('dwrangler.project.views', > > > (r'^in_development/$', 'summary_in_development'), > > > ) > > > > from the documentation I would think I can get the URL by using > > > > reverse('dwrangler.project.views.summary_in_development') > > > > But I keep getting a NoReverseMatch error. I have tried several > > > different formats but keep getting similar errors. > > > > I must be missing something obvious and would be thankful if something > > > could point me in the right direction. > > > > 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 -~--~~~~--~~--~--~---
Managers to aggregate child object values?
I'm pretty new to Django still and I know much is still escaping me. In particular I'm having trouble still with how to query subsets of related objects. In this case I have two Models. class Project(models.Model): title = models.CharField(max_length=141) ... class Release(models.Model): project_fk = models.ForeignKey(Project) point_estimate = models.IntegerField(choices=ESTIMATE_CHOICES, null=True, blank=True) velocity_points = models.IntegerField(choices=VELOCITY_CHOICES, null=True, blank=True) ... What I was looking to do is create a way sum the total number of velocity points in releases related to a Project. I also wanted to sum the total number of point_estimate points related to a Project. >From what I see a Custom Manager would seem necessary but I'm getting confused on related objects and aggregating items. This is for Django v 1.0 and would not include v1.1 aggregation features. Thanks in advance for any insight. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Related Managers and use_for_related_fields strangeness
I'm still struggling a bit with related managers. I have what I think should work right by the documentation but behavior isn't as expect. I've pasted the actual code below but the basic deal is this. I have a Project model which has Releases so Releases have a FK field for Projects. I want to be able to get Releses with particular combinations of settings so I created a custom manager for releases. It returns the values I want just fine. My problem is with related sets of releases called from a Project. I've used the 'use_for_related_fields' flag as per the official docs but if I have a Project p and call p.release_set.in_development() for instance, it gives me all Releases in the DB with those flags instead of just the ones related to the instance in p. Any help would be appreciated. --- Start Code --- class ReleaseManager(models.Manager): # Make sure this is used for related managers. use_for_related_fields = True DEV_REVIEW = [u'P', u'W'] PLAN_REVIEW = [u'P', u'W'] # This is for releases with a development status saying it is # either in need of review 'P' or improvement 'W'. def planning_backlog(self): return super(ReleaseManager, self).get_query_set().filter (development_status__in=self.DEV_REVIEW) # This is for actionable releases that are not yet approved or rejected. def prioritization_backlog(self): return super(ReleaseManager, self).get_query_set().filter (development_status='G', point_estimate__gt=0).filter (planning_status__in=self.PLAN_REVIEW) # This is for actionable, approved releases with No velocity Points. def development_backlog(self): return super(ReleaseManager, self).get_query_set().filter (development_status='G', planning_status='A', point_estimate__gt=0, velocity_points__lt=1) # This if for actionable approved releases with veolcity points. # In Development have dev status of 'G' and planning status of 'A' # and Velocity Points > 0 def in_development(self): return super(ReleaseManager, self).get_query_set().filter (development_status='G', planning_status='A', velocity_points__gt=0) def total_velocity(self): velocity = 0 rel_set = self.in_development() for rel in rel_set: velocity += rel.velocity_points return velocity # MODELS class Project(models.Model): title = models.CharField(max_length=141) summary = models.TextField() owner = models.ForeignKey(User) documentation_site = models.URLField(verify_exists=False, null=True, blank=True) created_on = models.DateField(auto_now=False, auto_now_add=True) last_updated = models.DateField(auto_now=True, auto_now_add=True) def __unicode__(self): return self.title class Meta: ordering = ['last_updated'] class Release(models.Model): PS_CHOICES = ( (u'P', u'Pending Review'), (u'N', u'Not Adopted'), (u'W', u'Refine more'), (u'A', u'Approved for Development'), ) DEV_CHOICES = ( (u'P', u'Pending Review'), (u'N', u'Not Advisable'), (u'W', u'Needs More Detail or Work'), (u'G', u'Actionable Plan'), (u'R', u'Released') ) ESTIMATE_CHOICES = [(str(n), str(n)) for n in fib_list(13, 6)] VELOCITY_CHOICES = [(str(n), str(n)) for n in range(0, 21, 3)] project_fk = models.ForeignKey(Project) title = models.CharField(max_length=141) summary = models.TextField() owner = models.ForeignKey(User) planning_status = models.CharField(max_length=1, choices=PS_CHOICES, default=PS_CHOICES[0]) development_status = models.CharField(max_length=1, choices=DEV_CHOICES, default=DEV_CHOICES[0]) point_estimate = models.IntegerField(choices=ESTIMATE_CHOICES, default=0) velocity_points = models.IntegerField(choices=VELOCITY_CHOICES, default=0) internal_priority = models.IntegerField(default=0) created_on = models.DateField(auto_now=False, auto_now_add=True) last_updated = models.DateField(auto_now=True, auto_now_add=True) # Add my custom manager. objects = ReleaseManager() def __unicode__(self): return self.title class Meta: ordering = ["internal_priority"] --~--~-~--~~~---~--~~ 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: Noobie question about getting form data to save to the database
You need to call form.save() after you validate the form. As below: def add(request): if request.method == 'POST': form = AddShow(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/shows/#success') return HttpResponseRedirect('/shows/#error') On Jun 4, 7:39 pm, Andy Dietler wrote: > I'm pretty new to Django and Python and I've had some success from > reading some books and guides playing around so far but I'm having > trouble figuring out how to get data I submit from a form to save into > the database. I've simplified down my code to just the basics and I > can get the form to submit fine and get passed the "if form.isvalid()" > step, but I'm lost from there. I've looked at a ton of code samples, > but most are way too complex and I can't figure out the basics of > this. All I want to do is save the title field as a new database entry > in the shows_show table. Anybody out there willing to take a look at > this incredibly simple code and give me a pointer or two about what is > wrong, what I need to add to get that working. > > Thanks a ton. - Andy > > 3 pertinent files: > > models.py > - > from django.db import models > from django import forms > > class Show(models.Model): > title = models.CharField(max_length=100) > > class AddShow(forms.Form): > title = forms.CharField(max_length=100) > > views.py > > from django.http import HttpResponseRedirect > from tvolt.shows.models import Show, AddShow > > def add(request): > if request.method == 'POST': > form = AddShow(request.POST) > if form.is_valid(): > return HttpResponseRedirect('/shows/#success') > return HttpResponseRedirect('/shows/#error') > > index.html > -- > > > Add a show > > Title > > maxlength="100" /> > > > Add a show > > > > --~--~-~--~~~---~--~~ 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: Related Managers and use_for_related_fields strangeness
No insights at all in the group? --~--~-~--~~~---~--~~ 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: Related Managers and use_for_related_fields strangeness
Cutting down the code sample I gave above in case that helps. Code snippet below Again, my problem is that if I call Release.objects.planning_backlog() it works and I get all relavant Releases. If I call Project.release_set.planning_backlog() I again get all Releases that fit the filter instead of just the ones related to that Project instance. Hopefully that'll help tease out what I'm missing and thanks again. class ReleaseManager(models.Manager): use_for_related_fields = True def planning_backlog(self): return super(ReleaseManager, self).get_query_set().filter (development_status__in=self.DEV_REVIEW) ... class Project(models.Model): title = models.CharField(max_length=141) ... class Release(models.Model): project_fk = models.ForeignKey(Project) title = models.CharField(max_length=141) ... # Add my custom manager. objects = ReleaseManager() --~--~-~--~~~---~--~~ 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: Related Managers and use_for_related_fields strangeness
I'll have to look harder at the documentation then as I'm a bit confuesed. What I thought was happening was that I would get a Project object (p) by filtering. I thought p.release_set returned a query set of Release filtered to those related to that project and I could just continue to filter down through the custom manager. Sorry for any missunderstanding. > But documentation doesn't say nor imply that there will be > any automatic (magic?) per-Project filtering of Release querysets generated > by your manager just because you have set its use_for_related_fields > to True. > > Even further, it recommends against returning filtered querysets whe > use_for_related_fields=True. > > -- > Ramiro Moraleshttp://rmorales.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-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 -~--~~~~--~~--~--~---
Getting a distinct list of Users from two related Models
I have two models with Foreign Key relationships to Users and what I'm looking to do is reterive a unique list of users from both Models. class Project(models.Model): owner = models.ForeignKey(User) class Release(models.Model): owner = models.ForeignKey(User) I know I can retrieve a distinct list of users from either by spanning relationships. (using Projects as an example) Users.objects.filter(project__owner__isnull=False).distinct() But how would I get a distinct set of Users who are owners of Projects OR Releases? Thanks for any insight. --~--~-~--~~~---~--~~ 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: Model gets subset of fields from inheritance, but then admin.py can't find the inherited fields.
I caught the OR lookups documentation and this seems to work. u = User.objects.filter(project__owner__isnull=False).distinct() | User.objects.filter(release__owner__isnull=False).distinct() On Jun 9, 2:02 pm, mw wrote: > Hello, > > I have a class full of common information such as email, name, and > etc, that multiple other models inherit. Everything works fine except > for the customizing of the admin interface. For example, in a setup > such as: > > class CommonStuff(models.Model): > email = models.EmailField(...) > > class Person(CommonStuff): > otherattribute = ... > somemore = ... > > The admin interface raises an exception: > .fieldsets[1][1]['fields']' refers to field 'email,' that is missing > from the form. > > So admin.py isn't quite properly detecting that the model has > inherited the email attribute. I imagine I'm just not registering > something correctly. Any ideas? > > Thanks in advance, --~--~-~--~~~---~--~~ 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: Getting a distinct list of Users from two related Models
Thanks so much for the reply. Oddly the method you suggests throws an error but I'm not sure why. The solution I came up with is as follows: User.objects.order_by('username').filter (project__owner__isnull=False).distinct() | User.objects.filter (release__owner__isnull=False).distinct() I would expect the line you wrote to give the same results but when I try it I get an Template Error of "Caught an exception while rendering: no such column: U1.owner_id" I have no idea why. It's working for me so I don't have a problem now but I'm definitly missing something about why I'm getting this error at all. Thanks again for the reply. On Jun 9, 2:43 pm, googletorp wrote: > You can do > > Users.objects.exclude(project__owner__isnull=True, > other__model__isnull=True).distinct() > > ~Jakob > > On Jun 9, 7:49 pm, Streamweaver wrote: > > > I have two models with Foreign Key relationships to Users and what I'm > > looking to do is reterive a unique list of users from both Models. > > > class Project(models.Model): > > owner = models.ForeignKey(User) > > > class Release(models.Model): > > owner = models.ForeignKey(User) > > > I know I can retrieve a distinct list of users from either by spanning > > relationships. (using Projects as an example) > > > Users.objects.filter(project__owner__isnull=False).distinct() > > > But how would I get a distinct set of Users who are owners of Projects > > OR Releases? > > > Thanks for any insight. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Date of last update across Relationships
What I want to do is get the date of the last update across relationships to figure out when the last update in an entire series of related objects happened. I'm pasting the relevant code of my models below but for example, I want to be able to call a series_updated method on project that returns the most recent date of a last_updated value from the project or any of the related Releases or Activities. I'm having trouble wrapping my head around this and would appreciate any insight. class Project(models.Model): last_updated = models.DateField(auto_now=True, auto_now_add=True) class Meta: get_latest_by = 'last_updated' ordering = ['last_updated'] class Release(models.Model): project_fk = models.ForeignKey(Project) last_updated = models.DateField(auto_now=True, auto_now_add=True) class Meta: get_latest_by = 'last_updated' ordering = ["project_fk", "internal_priority"] class Activity(models.Model): release_fk = models.ForeignKey(Release) last_updated = models.DateField(auto_now=True, auto_now_add=True) class Meta: get_latest_by = 'last_updated' ordering = ['last_updated'] --~--~-~--~~~---~--~~ 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 Help: "Get Blogs where last Entry.title='foo'"
If I understand your question right there is an example that covers this exact situation that may help at http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships I believe it could come out to something like this: e = Entry.objects.filter(title__exact='foo') blog = e.blog On Jun 15, 2:41 pm, Jason wrote: > I'm new to django and attempting to leverage the query functionality. > I'm not sure if what I'm attempting requires custom sql or if I"m just > missing something. I'm spending alot of time with the docs but > haven't found guidance for this issue. > > Just using blogs as an easy example, assume the models below... > > class Blog(models.Model): > name = models.CharField(max_length=100, unique=True) > > class Entry(models.Model): > blog = models.ForeignKey(Blog) > title = models.CharField(max_length=100) > > How can I construct a query that returns all blogs where the last > entry has a title of 'foo'? > > Note: Using Django 1.1 beta, and thanks in advance. --~--~-~--~~~---~--~~ 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: Getting a distinct list of Users from two related Models
awesome. Thanks for that. I put that in the comments in my code so if I ever get back to it after an update I can streamline it a bit. Thanks again. On Jun 11, 10:44 am, Karen Tracey wrote: > On Wed, Jun 10, 2009 at 3:24 PM, Streamweaver wrote: > > > > > > > Thanks so much for the reply. > > > Oddly the method you suggests throws an error but I'm not sure why. > > > The solution I came up with is as follows: > > > User.objects.order_by('username').filter > > (project__owner__isnull=False).distinct() | User.objects.filter > > (release__owner__isnull=False).distinct() > > > I would expect the line you wrote to give the same results but when I > > try it I get an Template Error of "Caught an exception while > > rendering: no such column: U1.owner_id" I have no idea why. > > > It's working for me so I don't have a problem now but I'm definitly > > missing something about why I'm getting this error at all. > > An error like that -- where the ORM generates SQL that is incorrect -- is > generally a bug in Django. In this case I can recreate it with the 1.0.2 > release, but not with current trunk or 1.0.X branch code, so it is > apparently a bug that has been found and fixed since 1.0.2. > > Karen --~--~-~--~~~---~--~~ 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 Help: "Get Blogs where last Entry.title='foo'"
A custom method in the model could work fine. If you set a 'get_latest_by' in the Entry Model -> http://www.djangoproject.com/documentation/models/get_latest/ Then in the Blog Model define something like: def last_is_foo(self): if Entry.objects.latest().title == 'foo' return True return False Adding a CustomManager to that would easily give you back sets. Getting closer? On Jun 15, 4:11 pm, Jason wrote: > Close. That returns all entrys that have title foo. I need all blogs > *where the last entry* has title foo. I think I need to > leverage .extra(where=something) but not having much luck. > > On Jun 15, 2:36 pm, Streamweaver wrote: > > > If I understand your question right there is an example that covers > > this exact situation that may help at > > >http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-... > > > I believe it could come out to something like this: > > > e = Entry.objects.filter(title__exact='foo') > > > blog = e.blog > > > On Jun 15, 2:41 pm, Jason wrote: > > > > I'm new to django and attempting to leverage the query functionality. > > > I'm not sure if what I'm attempting requires custom sql or if I"m just > > > missing something. I'm spending alot of time with the docs but > > > haven't found guidance for this issue. > > > > Just using blogs as an easy example, assume the models below... > > > > class Blog(models.Model): > > > name = models.CharField(max_length=100, unique=True) > > > > class Entry(models.Model): > > > blog = models.ForeignKey(Blog) > > > title = models.CharField(max_length=100) > > > > How can I construct a query that returns all blogs where the last > > > entry has a title of 'foo'? > > > > Note: Using Django 1.1 beta, and thanks in advance. --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Sometimes datetime sometimes date?
I ran into what I think might be a bug and wanted to check here before possibly posting it. Essentially what seems to be happening is that Django seems to return datetime.datetime or datetime.date from DateFields in models and I can't figure out why it returns one type at one time and another type at another. I have two models and the parent has a method that is suppose to compare it's latest update date and the date of the latest child update and return whichever date is more rescent. However when I try to unit test the Release.all_last_update method I get the following error: "TypeError: can't compare datetime.datetime to datetime.date" But all values are being pulled from a DateField. Is Django casting it incorrectly or am I missing something somewhere? Models are below. class Release(models.Model): created_on = models.DateField(auto_now=False, auto_now_add=True) last_updated = models.DateField(auto_now=True, auto_now_add=True) def all_last_updated(self): d = [] d.append(self.last_updated) d.append(Activity.objects.filter(release_fk=self).latest ().last_updated) d.sort().reverse() return d[0] class Meta: get_latest_by = 'last_updated' ordering = ["project_fk", "internal_priority"] class Activity(models.Model): created_on = models.DateField(auto_now=False, auto_now_add=True) last_updated = models.DateField(auto_now=True, auto_now_add=True) def all_last_updated(self): return self.last_updated class Meta: get_latest_by = 'created_on' ordering = ['created_on'] --~--~-~--~~~---~--~~ 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: Sometimes datetime sometimes date?
sqlite3 I changed the method and it seems to be working now. The code I'm using is: def all_last_updated(self): d = [self.last_updated, self.activity_set.latest ().last_updated] d.sort() d.reverse() return d[0] There seemed to be some problem when chaining sort().reverse() before. Not sure I understand it still and attributing it to me missing something in general but it's working now. On Jun 15, 10:08 pm, Ramiro Morales wrote: > On Mon, Jun 15, 2009 at 10:34 PM, Streamweaver wrote: > > > I ran into what I think might be a bug and wanted to check here before > > possibly posting it. > > > Essentially what seems to be happening is that Django seems to return > > datetime.datetime or datetime.date from DateFields in models and I > > can't figure out why it returns one type at one time and another type > > at another. > > What database are you using? > > -- > Ramiro Moraleshttp://rmorales.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-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 -~--~~~~--~~--~--~---
Reverse Method Not finding URLs
I'm still having considerable problems with my reverse URLs and can't find what I'm doing wrong. For reference I'm pasting in my localsettings file (with some info scrubbed out), my root urls.py file as well as an included urls.py file relevant to the error. My problem is that I am getting various errors for the reverse function not being able to find URLs. The most noticable one when I try to load the site overall I get a template error of "Caught an exception while rendering: Reverse for 'view-release' with arguments '()' and keyword arguments '{'slug': u'paint-dog-in-dev', 'project_slug': u'blue-dog'}' not found." Even in the manage.py shell though I'm having trouble as some URLs are found and other seem not to be. For instance if I try 'reverse('list-project') I get the expected result of '/project/list/' but if I try another URL from the same file I get a NoReverseMatch error So if I try 'reverse('view-project', args=['blue-dog']) I would expect the result '/project/blue-dog/' but instead get a NoReverseMatch error. I get those on a number of other URLs as well and I can't seem to find the problem If anyone would point out what I'm doing wrong I would be very grateful. *** INCLUDED FOR REFERENCE BELOW * *** urls.py file from django.conf.urls.defaults import * from django.conf import settings # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^$', 'dwrangler.project.views.summary_in_development', name="dwrangler-root"), url(r'^admin/(.*)', admin.site.root), url(r'^project/', include('dwrangler.project.urls')), url(r'^accounts/', include('dwrangler.accounts.urls')), url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'accounts/login.xhtml'}, "login-account"), url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'template_name': 'accounts/logout.xhtml'}, "logout-account") ) # DISABLE THIS IN PRODUCTION if settings.DEV_ENV: from os import path urlpatterns += patterns('', (r'^static/(?P.*)$', 'django.views.static.serve', { 'document_root': path.join(settings.BASE_DIR, '../media') }), ) *** project/urls.p file * from django.conf.urls.defaults import * from dwrangler.project.feeds import * rssfeeds = { 'in_development': RssInDevelopment, 'awaiting_development': RssAwaitingDevelopment, 'in_planning_review': RssInPlanningReview, 'in_tech_review': RssInTechReview, } atomfeeds = { 'in_development': AtomInDevelopment, 'awaiting_development': AtomAwaitingDevelopment, 'in_planning_review': AtomInPlanningReview, 'in_tech_review': AtomInTechReview, } localsettings.py file * # Local settings file. This should NEVER be checked in. # Django settings for dwrangler project. from os import path # Get the directory of this file for relative dir paths. # Django sets too many absolute paths. BASE_DIR = path.dirname(path.abspath(__file__)) # Set this to teh same value returned by request.MET['SCRIPT_NAME'] as a # workaround for Django not picking up URL subdirectory installs. # A pox on you Django!!! May Digo's eat your baby! SUB_URL = '' # Some default login and logout URL information. LOGIN_URL = '%s/accounts/login/' % SUB_URL LOGIN_REDIRECT_URL = '%s/accounts/profile/' % SUB_URL LOGOUT_URL = '%s/accounts/logout/' % SUB_URL # Look to see if the Development flag is set. DEV_ENV = True DEBUG = True TEMPLATE_DEBUG = True ADMINS = ( # Name and email address of people to email as admins. # 'Name', 'em...@email.com' 'Scott Turnbull', 'stur...@emory.edu' ) MANAGERS = ADMINS DATABASE_ENGINE = 'mysql' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. DATABASE_NAME = 'dwrangler_dvl' # Or path to database file if using sqlite3. DATABASE_USER = 'dwrangler' # Not used with sqlite3. DATABASE_PASSWORD = ## Not used with sqlite3. DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3. DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3. # EULCORE LDAP SETTINGS # LDAP login settings. These are configured for emory, but you'll need # to get a base user DN and password elsewhere. AUTH_LDAP_SERVER = AUTH_LDAP_BASE_USER = ## AUTH_LDAP_BASE_PASS = # password for USERNAME above AUTH_LDAP_SEARCH_SUFFIX = # AUTH_LDAP_SEARCH_FILTER = AUTH_LDAP_CHECK_SERVER_CERT = False # ALWAYS SET True in production. AUTH_LDAP_CA_CERT_PATH = '' # absolute path of cert # DJANGO-PAGINATION SETTINGS # Pagination settings for use with django-pagination middleware PAGINATION_DEFAULT_PAGINATION = 10 # The default amount of items to show on a page if no number is specified. # PAGINATION_DEFAULT_WINDOW = 3 # The number of items to the left and to the right of the current pag
Re: Reverse Method Not finding URLs
I appreciate the answer and I'll give that a try and put some feedback here about it. On Sep 23, 8:32 pm, Peter Coles wrote: > Looks like your regex isn't matching: > > reverse('view-project', args=['blue-dog']) > > is trying the regex here: > > url(r'^(?P\w+)/$', 'view_project', name="view-project"), > > I think you want (?P[\w\-]+). Whenever I'm unsure about a > regex, I open up a shell "import re" and test it out. > > -- > Peter > > On Sep 23, 6:01 pm, Streamweaver wrote: > > > I'm still having considerable problems with my reverse URLs and can't > > find what I'm doing wrong. For reference I'm pasting in my > > localsettings file (with some info scrubbed out), my root urls.py file > > as well as an included urls.py file relevant to the error. > > > My problem is that I am getting various errors for the reverse > > function not being able to find URLs. The most noticable one when I > > try to load the site overall I get a template error of > > > "Caught an exception while rendering: Reverse for 'view-release' with > > arguments '()' and keyword arguments '{'slug': u'paint-dog-in-dev', > > 'project_slug': u'blue-dog'}' not found." > > > Even in the manage.py shell though I'm having trouble as some URLs are > > found and other seem not to be. > > > For instance if I try 'reverse('list-project') I get the expected > > result of '/project/list/' > > > but if I try another URL from the same file I get a NoReverseMatch > > error > > > So if I try 'reverse('view-project', args=['blue-dog']) I would expect > > the result '/project/blue-dog/' but instead get a NoReverseMatch > > error. I get those on a number of other URLs as well and I can't seem > > to find the problem > > > If anyone would point out what I'm doing wrong I would be very > > grateful. > > > *** INCLUDED FOR REFERENCE BELOW * > > *** urls.py file > > from django.conf.urls.defaults import * > > from django.conf import settings > > > # Uncomment the next two lines to enable the admin: > > from django.contrib import admin > > admin.autodiscover() > > > urlpatterns = patterns('', > > url(r'^$', 'dwrangler.project.views.summary_in_development', > > name="dwrangler-root"), > > url(r'^admin/(.*)', admin.site.root), > > url(r'^project/', include('dwrangler.project.urls')), > > url(r'^accounts/', include('dwrangler.accounts.urls')), > > url(r'^accounts/login/$', 'django.contrib.auth.views.login', > > {'template_name': 'accounts/login.xhtml'}, "login-account"), > > url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', > > {'template_name': 'accounts/logout.xhtml'}, "logout-account") > > ) > > > # DISABLE THIS IN PRODUCTION > > if settings.DEV_ENV: > > from os import path > > urlpatterns += patterns('', > > (r'^static/(?P.*)$', 'django.views.static.serve', { > > 'document_root': path.join(settings.BASE_DIR, '../media') > > }), > > ) > > > *** project/urls.p file * > > from django.conf.urls.defaults import * > > from dwrangler.project.feeds import * > > > rssfeeds = { > > 'in_development': RssInDevelopment, > > 'awaiting_development': RssAwaitingDevelopment, > > 'in_planning_review': RssInPlanningReview, > > 'in_tech_review': RssInTechReview, > > > } > > > atomfeeds = { > > 'in_development': AtomInDevelopment, > > 'awaiting_development': AtomAwaitingDevelopment, > > 'in_planning_review': AtomInPlanningReview, > > 'in_tech_review': AtomInTechReview, > > > } > > > localsettings.py file * > > # Local settings file. This should NEVER be checked in. > > > # Django settings for dwrangler project. > > from os import path > > > # Get the directory of this file for relative dir paths. > > # Django sets too many absolute paths. > > BASE_DIR = path.dirname(path.abspath(__file__)) > > > # Set
Re: Reverse Method Not finding URLs
I tried this solution and that's what it was. I knew I was missing something obvious. Thanks so much. On Sep 23, 8:32 pm, Peter Coles wrote: > Looks like your regex isn't matching: > > reverse('view-project', args=['blue-dog']) > > is trying the regex here: > > url(r'^(?P\w+)/$', 'view_project', name="view-project"), > > I think you want (?P[\w\-]+). Whenever I'm unsure about a > regex, I open up a shell "import re" and test it out. > > -- > Peter > > On Sep 23, 6:01 pm, Streamweaver wrote: > > > I'm still having considerable problems with my reverse URLs and can't > > find what I'm doing wrong. For reference I'm pasting in my > > localsettings file (with some info scrubbed out), my root urls.py file > > as well as an included urls.py file relevant to the error. > > > My problem is that I am getting various errors for the reverse > > function not being able to find URLs. The most noticable one when I > > try to load the site overall I get a template error of > > > "Caught an exception while rendering: Reverse for 'view-release' with > > arguments '()' and keyword arguments '{'slug': u'paint-dog-in-dev', > > 'project_slug': u'blue-dog'}' not found." > > > Even in the manage.py shell though I'm having trouble as some URLs are > > found and other seem not to be. > > > For instance if I try 'reverse('list-project') I get the expected > > result of '/project/list/' > > > but if I try another URL from the same file I get a NoReverseMatch > > error > > > So if I try 'reverse('view-project', args=['blue-dog']) I would expect > > the result '/project/blue-dog/' but instead get a NoReverseMatch > > error. I get those on a number of other URLs as well and I can't seem > > to find the problem > > > If anyone would point out what I'm doing wrong I would be very > > grateful. > > > *** INCLUDED FOR REFERENCE BELOW * > > *** urls.py file > > from django.conf.urls.defaults import * > > from django.conf import settings > > > # Uncomment the next two lines to enable the admin: > > from django.contrib import admin > > admin.autodiscover() > > > urlpatterns = patterns('', > > url(r'^$', 'dwrangler.project.views.summary_in_development', > > name="dwrangler-root"), > > url(r'^admin/(.*)', admin.site.root), > > url(r'^project/', include('dwrangler.project.urls')), > > url(r'^accounts/', include('dwrangler.accounts.urls')), > > url(r'^accounts/login/$', 'django.contrib.auth.views.login', > > {'template_name': 'accounts/login.xhtml'}, "login-account"), > > url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', > > {'template_name': 'accounts/logout.xhtml'}, "logout-account") > > ) > > > # DISABLE THIS IN PRODUCTION > > if settings.DEV_ENV: > > from os import path > > urlpatterns += patterns('', > > (r'^static/(?P.*)$', 'django.views.static.serve', { > > 'document_root': path.join(settings.BASE_DIR, '../media') > > }), > > ) > > > *** project/urls.p file * > > from django.conf.urls.defaults import * > > from dwrangler.project.feeds import * > > > rssfeeds = { > > 'in_development': RssInDevelopment, > > 'awaiting_development': RssAwaitingDevelopment, > > 'in_planning_review': RssInPlanningReview, > > 'in_tech_review': RssInTechReview, > > > } > > > atomfeeds = { > > 'in_development': AtomInDevelopment, > > 'awaiting_development': AtomAwaitingDevelopment, > > 'in_planning_review': AtomInPlanningReview, > > 'in_tech_review': AtomInTechReview, > > > } > > > localsettings.py file * > > # Local settings file. This should NEVER be checked in. > > > # Django settings for dwrangler project. > > from os import path > > > # Get the directory of this file for relative dir paths. > > # Django sets too many absolute paths. > > BASE_DIR = path.dirname(path.abspath(__file__)) &
More Reverse Method Woes
I'm continuing to struggle with the reverse method in Django. After fixing some mistakes of mine earlier I'm getting an ImproperlyConfigured Error whenever I try to use a reverse method. The site works fine with one but whenever I try to use a reverse method, even in shell I get the following error. "ImproperlyConfigured: The included urlconf dwrangler.project.urls doesn't have a ny patterns in it" I've commented lines out in dwrangler.project.urls to have a very controlled single URL but I still get the error. I'm pasting the contents of the relevant files here in hopes someone can give me some insight. Sorry to be so behind on this function. The example I've been testing in shell is 'print reverse('list-project')' but I've also tried calling 'project_index' as well an so forth. *** Settings is correct in calling *** ROOT_URLCONF = 'dwrangler.urls' root level dwrangler.urls file*** urlpatterns = patterns('', url(r'^$', 'dwrangler.project.views.summary_in_development', name="dwrangler-root"), url(r'^admin/(.*)', admin.site.root), url(r'^project/', include('dwrangler.project.urls')), url(r'^accounts/', include('dwrangler.accounts.urls')), url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'accounts/login.xhtml'}, "login-account"), url(r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'template_name': 'accounts/logout.xhtml'}, "logout-account") ) dwrangler.project.urls file *** urlpatterns = patterns('dwrangler.project.views', url(r'^list/$', 'project_index', name='list-project'), ) --~--~-~--~~~---~--~~ 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: More Reverse Method Woes
Okay, I think I've figured this out with the help of a co-worker and WOW would I never have gotten this on my own and nobody would have been able to get it from the code I posted here. It's important enough to post the problem here. This problem came out of using the RSS syndication framework in Django and the differences in how view methods and RSS classes are compiled. The issue was that I was generating RSS links as follows: class RssInPlanningReview(SummaryReleaseInfo): # Feeds for Under Planning Review Queue title = 'Releases Under Planning Review' link = reverse('planning-review') description = 'These Releases are currently awaiting review by planners.' Setting the link as an attribute was what was causing the error because Classes and URL patterns are compiled when the application loads. So in this case when the application loads it would try to compile the reverse URL but the URLS haddn't compiled yet. The fix for this was to move the link into a class method instead of an attribute so this works fine: class RssInPlanningReview(SummaryReleaseInfo): # Feeds for Under Planning Review Queue title = 'Releases Under Planning Review' description = 'These Releases are currently awaiting review by planners.' def link(self): return reverse('tech-review') This is probably obvious to the hard-core programmers here but something I missed easily and I expect there are others who do as well. Thanks to Karen for her help and to my co-worker for his insight. Hope this post is useful to someone in the future. On Oct 2, 2:20 pm, Karen Tracey wrote: > On Fri, Oct 2, 2009 at 11:01 AM, Streamweaver wrote: > > > > > > > I'm continuing to struggle with the reverse method in Django. After > > fixing some mistakes of mine earlier I'm getting an > > ImproperlyConfigured Error whenever I try to use a reverse method. > > The site works fine with one but whenever I try to use a reverse > > method, even in shell I get the following error. > > > "ImproperlyConfigured: The included urlconf dwrangler.project.urls > > doesn't have a ny patterns in it" > > > [snip] > > > dwrangler.project.urls file *** > > urlpatterns = patterns('dwrangler.project.views', > > url(r'^list/$', 'project_index', name='list-project'), > > ) > > That cannot be the complete file because if it was you would get: > > NameError: name 'patterns' is not defined > > when it was imported. What you have shown us is fine. The problem lies in > something you have left out. Something that either makes that entire chunk > part of a comment, or redefines urlpatterns to be None, or > > Karen --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Unique Fields and form submission validation
The title field in my model is set to unique and when I use a form to edit this I get an error that an item with this value already exists. As I understand it this is because ModelForm throws an error when I call form.is_valid() and all information I can find tells me to override the clean method in the form however it seems like this requires me to reimplement the entire validation code again? Is there an easier way to deal with unique text fields in form validation for existing data? Thanks in advance for any 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: Unique Fields and form submission validation
Some more information. The view method to save the item is as follows: def update_project(request, slug): '''Method for editing already existing projects.''' project = get_object_or_404(Project, slug=slug) if request.method == 'POST': # If form was submitted run it through. form = ProjectForm(request.POST) if form.is_valid(): form_instance = form.save(commit=False) form_instance.id = project.id form_instance.created_on = project.created_on form_instance.save() return HttpResponseRedirect(reverse('view-project', args= [slug])) else: form = ProjectForm(instance=project) return render_with_context(request, 'project/projectedit.xhtml', { 'form': form, 'action': reverse('update-project', args=[slug]), 'button': 'Update Project', 'title': 'Editing Project' }) On Oct 7, 5:24 pm, Streamweaver wrote: > The title field in my model is set to unique and when I use a form to > edit this I get an error that an item with this value already exists. > > As I understand it this is because ModelForm throws an error when I > call form.is_valid() and all information I can find tells me to > override the clean method in the form however it seems like this > requires me to reimplement the entire validation code again? > > Is there an easier way to deal with unique text fields in form > validation for existing data? > > Thanks in advance for any 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: Unique Fields and form submission validation
I found a solution off of stack overflow. I had to bind an instance to the form when editing. So I changed the following line: form = ProjectForm(request.POST, instance=project) It seems to work and is in testing. On Oct 7, 5:40 pm, Streamweaver wrote: > Some more information. The view method to save the item is as follows: > > def update_project(request, slug): > '''Method for editing already existing projects.''' > > project = get_object_or_404(Project, slug=slug) > if request.method == 'POST': # If form was submitted run it > through. > form = ProjectForm(request.POST) > if form.is_valid(): > form_instance = form.save(commit=False) > form_instance.id = project.id > form_instance.created_on = project.created_on > form_instance.save() > return HttpResponseRedirect(reverse('view-project', args= > [slug])) > else: > form = ProjectForm(instance=project) > > return render_with_context(request, 'project/projectedit.xhtml', { > 'form': form, > 'action': reverse('update-project', > args=[slug]), > 'button': 'Update Project', > 'title': 'Editing Project' > }) > > On Oct 7, 5:24 pm, Streamweaver wrote: > > > The title field in my model is set to unique and when I use a form to > > edit this I get an error that an item with this value already exists. > > > As I understand it this is because ModelForm throws an error when I > > call form.is_valid() and all information I can find tells me to > > override the clean method in the form however it seems like this > > requires me to reimplement the entire validation code again? > > > Is there an easier way to deal with unique text fields in form > > validation for existing data? > > > Thanks in advance for any 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: efficiently deleting content based on how old it is
You could set this up as a custom manage.py command and run a cron on that. Gives the advantage of both initiating from outside the app and using Django's DB abstraction layer. A very simple way to do this would be to put all month text names in order in a tuple. i.e. monthnames = ('jan', 'feb', 'mar', ) or however your month names are reflected. (You can actually generate this list by doing a 'for m in' line and pull out the month names but you get what I mean. Then just iterate over the month names more than 6 back from the current position and delete the records. On Oct 8, 10:54 am, Chris Withers wrote: > Tim Chase wrote: > > I wouldn't try to do it from within the web app itself -- > > I'd schedule some wee-hours cron job to do the deletion. > > I plan to, don't worry ;-) > But, I would like to do it from within the Django environment to make it > immune to changes of database... > > > 6mo boundary. Your Month is defined as a string, and I > > don't see any actual date information in it. > > Yeah, an unfortunate artifact of the legacy system I'm replacing. > Months are of the form "September 2009", "August 2009", etc. > How would you represent those in a Django ORM sensible way? > > > In all, I'd just skip Django completely and do something > > like create a quick shell-script to execute the raw SQL and > > schedule it to run monthly > > You guessed right about the database, but that's a luxury I don't have. > The database used may change, so I'd like to do this through the Django > ORM. Does the Django ORM have a sql abstraction layer like sqlalchemy > where I can do the kind of thing you're proposing, or do I need to work > with models? > > cheers, > > Chris > > -- > Simplistix - Content Management, Batch Processing & Python Consulting > -http://www.simplistix.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-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 -~--~~~~--~~--~--~---
Displaying Calculated Values in Django Admin
Is it possible to display calculated values for models in the admin interface. I know about the list_display attribute for model.Admin but all I really want to do is add text to a model edit form so I can see calculated values. For instance I have a model called Profile with a DateField called birthday. I have a method as a @property that returns calculated age as of today. I'd like to display the calculated age as text in the model editing form in the admin interface. How would I do this. i.e. displaying the property below as text in the admin interface class Profile(models.Model): ... @property def age(self): """Returns age in years as of today.""" today = date.today() return self.age_bydate(today) Thanks for any input. -- 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: Displaying Calculated Values in Django Admin
Thanks for the reply. I'm still working with this and have it working in cases of editing records but when I try to create a new record it throws an error as would be expected since there's no instance to read the initial values from. I tried putting an is_bound check to give a devault but of course as that's happening in __init__ it's never bound so that's not working. The solution is still escaping me and any insight would be helpful. Thanks again. Some sample of the code I've been trying is: class ProfileAdminForm(ModelForm): """Additional display Fields for Profile""" age = forms.IntegerField() # Calculated age property bmr = forms.FloatField(label='BMR') # Display the BMR value def __init__(self, *args, **kwargs): super(ProfileAdminForm, self).__init__(*args, **kwargs) self.fields['age'].initial = self.instance.age self.fields['age'].widget.attrs['readonly'] = True self.fields['bmr'].initial = self.instance.weight.bmr self.fields['bmr'].widget.attrs['readonly'] = True class Meta: model = Profile class ProfileAdmin(admin.ModelAdmin): form = ProfileAdminForm fieldsets = [ (None, {'fields': ['user', 'gender', 'height', 'birthday']}), ('Calculated Values', {'fields': ['age', 'bmr'], 'classes': ['collapse']}), ] inlines = [WeightInline] On Dec 16, 9:47 pm, Matt Schinckel wrote: > On Dec 17, 12:03 pm, Streamweaver wrote: > > > > > Is it possible to display calculated values for models in the admin > > interface. I know about the list_display attribute for model.Admin > > but all I really want to do is add text to a model edit form so I can > > see calculated values. > > > For instance I have a model called Profile with a DateField called > > birthday. I have a method as a @property that returns calculated age > > as of today. I'd like to display the calculated age as text in the > > model editing form in the admin interface. > > > How would I do this. > > > i.e. displaying the property below as text in the admin interface > > > class Profile(models.Model): > > ... > > > @property > > def age(self): > > """Returns age in years as of today.""" > > today = date.today() > > return self.age_bydate(today) > > > Thanks for any input. > > You can add in fields to a custom form, which can do this. > > class ProfileAdmin(admin.ModelAdmin): > form = forms.ProfileAdminForm > > Matt -- 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.
feed decorator
I'm having trouble developing a feed decorator. I feel like the decorator I've come up with should work but isn't and I wanted to ask if someone can spot my error. I have two view methods one that returns a normal HTML view and another that returns an rss feed of the same data. They both take the same arguments. I am trying to create a decorator that checks the request objects for a format variable in the querystring and returns the feed view instead of the html view. Like so: my_view_feed @format_req('rss', my_view_feed) my_view So a request for '/site/foo/bar' would return 'my_view' but '/site/foo/ bar?format=rss' would return 'my_view_feed' This is the decorator method I created and I would think would work but I'm still struggling a bit with decorators with arguments, even after reading Bruce's excellent post (http://www.artima.com/weblogs/ viewpost.jsp?thread=240845) def format_req(fmt, new_fn): def _decorator(view_fn): def _wraped(request, *args, **kwargs): req_format = request.GET.get('format', None) if req_format == fmt: return new_fn(request, *args, **kwargs) # Default to returning the original method return view_fn(request, *args, **kwargs) return _wraped return _decorator I would have though a request with 'format=rss' would return new_view but no matter what I do I always get view_fn returned. Can anyone point me toward where I'm going wrong. As usual I'll post the final code once I get it working for reference. -- 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: feed decorator
No insights? I'm still plugging away at it but it's not working for some reason. On Apr 18, 11:15 pm, Streamweaver wrote: > I'm having trouble developing a feed decorator. I feel like the > decorator I've come up with should work but isn't and I wanted to ask > if someone can spot my error. > > I have two view methods one that returns a normal HTML view and > another that returns an rss feed of the same data. They both take the > same arguments. I am trying to create a decorator that checks the > request objects for a format variable in the querystring and returns > the feed view instead of the html view. Like so: > > my_view_feed > > @format_req('rss', my_view_feed) > my_view > > So a request for '/site/foo/bar' would return 'my_view' but '/site/foo/ > bar?format=rss' would return 'my_view_feed' > > This is the decorator method I created and I would think would work > but I'm still struggling a bit with decorators with arguments, even > after reading Bruce's excellent post (http://www.artima.com/weblogs/ > viewpost.jsp?thread=240845) > > def format_req(fmt, new_fn): > > def _decorator(view_fn): > > def _wraped(request, *args, **kwargs): > req_format = request.GET.get('format', None) > if req_format == fmt: > return new_fn(request, *args, **kwargs) > # Default to returning the original method > return view_fn(request, *args, **kwargs) > > return _wraped > > return _decorator > > I would have though a request with 'format=rss' would return new_view > but no matter what I do I always get view_fn returned. > > Can anyone point me toward where I'm going wrong. As usual I'll post > the final code once I get it working for reference. > > -- > 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. -- 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: Equivalent of php json_encode?
I've found the native Python JSON library about the easiest to use out there. http://docs.python.org/library/json.html On May 4, 10:34 am, zweb wrote: > Is there a django or python equivalent of php json_encode? > > the data I am converting to json has text fields that have quotes, > double quotes, newlines and html tags. Creating json manually in my > program without escaping or converting these special characters is > causing problem on javascript side. > > A php programmer suggested I use equivalent of php json_encode. > > -- > 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. -- 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.
Content Types and Filtering Generic Relationships
I'm trying to implement tagging using Content Types and Generic Relationships.What I want to is query any tagged item with a status of Published. All my tagged models are implementing an Abstract Model class with a status field so they share the 'Published' and 'Unpublished' types. Here are some cut down version of the models I'm using for an example.Right now I only have Posts related to Tags but I plan on adding flat pages and such. What I want to be able to have pages for tags return all content with a status of Published but I don't seem to be able to find a way to do this. I can find content and tags just fine but when I have to filter it further I'm stumbling and would appreciate any insight or pointers to example code. I've seen some examples of custom managers online but the folks there are writing naked SQL in the managers and I'd like to avoid going that route if I can class Tag(models.Model): text = models.CharField(max_length=30, unique=True) slug = models.SlugField(max_length=30, unique=True, null=True, blank=True) class TaggedItem(models.Model): tag = models.ForeignKey(Tag) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') class Post(models.Model): title = models.CharField(max_length=75) ... status = models.CharField(max_length=1, choices=POST_STATUS) topics = generic.GenericRelation(TopicCatalog) tags = generic.GenericRelation(TagCatalog) -- 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: Content Types and Filtering Generic Relationships
Still hoping someone has some insight here. I've been plugging away at it and am still not finding an answer I can live with as an engineer. Currently I'm cheating a bit to filter down by only published objects in my view like so tag = get_object_or_404(Tag, slug=slug) contentitems = tag.taggeditem_set.all() contentlist = [item for item in contentitems if item.content_object.status == 'P'] Obviously this seems a bit sloppy and I'm probably better off putting this in a custom related manager that catches errors if I'm trying to filter on fields that a model doesn't have (which could happen in generic models). It doesn't do well at ordering obviously. I'm still struggling with this though and am not sure generic tagging is the way I should be going with this. Still appreciate any insight out there. On May 24, 10:05 am, Streamweaver wrote: > I'm trying to implement tagging using Content Types and Generic > Relationships. What I want to is query any tagged item with a > status of Published. > > All my tagged models are implementing an Abstract Model class with a > status field so they share the 'Published' and 'Unpublished' types. > > Here are some cut down version of the models I'm using for an > example. Right now I only have Posts related to Tags but I plan on > adding flat pages and such. What I want to be able to have pages for > tags return all content with a status of Published but I don't seem to > be able to find a way to do this. I can find content and tags just > fine but when I have to filter it further I'm stumbling and would > appreciate any insight or pointers to example code. I've seen some > examples of custom managers online but the folks there are writing > naked SQL in the managers and I'd like to avoid going that route if I > can > > class Tag(models.Model): > > text = models.CharField(max_length=30, unique=True) > slug = models.SlugField(max_length=30, unique=True, null=True, > blank=True) > > class TaggedItem(models.Model): > > tag = models.ForeignKey(Tag) > > content_type = models.ForeignKey(ContentType) > object_id = models.PositiveIntegerField() > content_object = generic.GenericForeignKey('content_type', > 'object_id') > > class Post(models.Model): > > title = models.CharField(max_length=75) > ... > status = models.CharField(max_length=1, choices=POST_STATUS) > > topics = generic.GenericRelation(TopicCatalog) > tags = generic.GenericRelation(TagCatalog) > > -- > 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. -- 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 1.2.1 doesn't work with South but 1.2 works? How to find the previous version Django 1.2?
South is working fine for me with Django 1.2 as well. What errors are you getting? There's a south discussion group that may be more productive for this conversation though. On Jun 1, 9:29 pm, flyinglegs wrote: > I am having some trouble with South database migration using Fabric. I > tried several machines, one works and the other 3 doesn't work. The > only difference is that the machine that's working is using Django > 1.2, and the others are using Django 1.2.1. > > Somehow I couldn't find the Django 1.2 tarball on the website, any > idea why it was pulled? Does anybody else have trouble using Django > 1.2.1 with South 0.7.1? > > 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.
Adding request context to standard login/logout views?
I use the the standard django login and logout views in the usual way url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'accounts/login.xhtml'}, "login-account"), url(r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'accounts/logout.xhtml'}, "logout-account") My problem is that I need to add the request context to those templates as my media URLs require the MEDIA_URL variable. Is there a way to add the request context -- 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 request context to standard login/logout views?
Argh!! Please ignore. This is not the message you're looking for. context varibles are passed to generic views by default. I got my errors confused. On Aug 11, 2:59 pm, Streamweaver wrote: > I use the the standard django login and logout views in the usual way > > url(r'^login/$', 'django.contrib.auth.views.login', > {'template_name': 'accounts/login.xhtml'}, "login-account"), > url(r'^logout/$', 'django.contrib.auth.views.logout', > {'template_name': 'accounts/logout.xhtml'}, "logout-account") > > My problem is that I need to add the request context to those > templates as my media URLs require the MEDIA_URL variable. Is there a > way to add the request context -- 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.
Add message on specific error to 500 page
On our 500 error page I would like to display a message specifically if the error is in the Database connection, and not display the message on any other uncaught exception but I can't seem to figure out a way to catch the specific exception going to a 500 page. Has anyone done 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: Add message on specific error to 500 page
I'm still looking into this if anyone has any insight. On Oct 7, 2:04 pm, Streamweaver wrote: > On our 500 error page I would like to display a message specifically > if the error is in the Database connection, and not display the > message on any other uncaught exception but I can't seem to figure out > a way to catch the specific exception going to a 500 page. > > Has anyone done 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.
Grouping and returning latest of each group?
I have a model called 'Ticket' with several fields 'number', 'milestone', 'status', 'resolution', 'estimate', 'last_updated' These are just multiple entries for the same support ticket that I'm pulling from another system. I keep multiple entries of a ticket so I can trac changes in estimation and so forth over time. functionally though what I'll want to do most often is bring by the more recent ticket (by last_updated) of each unique 'number' In SQL I'd normally do this by a sort and a group by but I can't seem to figure out how to do it in Django effectively. Has anyone done anything like this previously? -- 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: Grouping and returning latest of each group?
I think really I'm better off redesigning my model structure for this. Even trying to do it in pure SQL or with the extra attribute it's ungodly messy. What I really need is a Ticket model and a TicketHistory model. Keep the most rescent ticket information in Ticket and versions of tickets in TicketHistory as they change. Sorry to have floated this here. On Feb 8, 5:22 pm, Streamweaver wrote: > I have a model called 'Ticket' with several fields 'number', > 'milestone', 'status', 'resolution', 'estimate', 'last_updated' > > These are just multiple entries for the same support ticket that I'm > pulling from another system. I keep multiple entries of a ticket so I > can trac changes in estimation and so forth over time. > > functionally though what I'll want to do most often is bring by the > more recent ticket (by last_updated) of each unique 'number' > > In SQL I'd normally do this by a sort and a group by but I can't seem > to figure out how to do it in Django effectively. > > Has anyone done anything like this previously? -- 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.
URL Patterns for Nested Catagories.
I'm trying to setup a Django based blog for myself and I'd like to do wordpress like nested catagories. The model itself is fine and there are some good posts about how to do such things around (i.e. http://swixel.net/2009/01/01/django-nested-categories-blogging-like-wordpress-again/) The thing I'm having trouble wrapping my head around is how would I setup URL Patterns for nested catagories when it may have any number of extra layers? Say I had a set of nested catagories like Parent - Child Level 1 - Child Level 2 which I would expect to have a url like: /parent/child-level-1/child-level-2/ Is it possible to even pick up a variable number of URL attributes like that? I suppose I could do something like r'^(?P.*)$' and then parse path in the view but this could wreak havoc with other URLs. Anyone have any ideas? -- 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: URL Patterns for Nested Catagories.
Big thanks for the reply. I already have a custom save method on the Catagory for slugs so it'll be easy enough to create a path. I may not understand the suggested implementation very well but it sounds like I may not have to do a split at all if I store the sluggified path then I think all I should have to do is query on that? I'll give it a try and try to post what I've come up with back here so others can reference it. Thanks again. On Apr 7, 8:34 pm, Tim Shaffer wrote: > Oh, check out the Category class from django-simplecms. It implements > the first method. > > Specifically, check out the save() method that builds the path based > on all the parent categories if it doesn't exist. > > http://code.google.com/p/django-simplecms/source/browse/trunk/simplec... -- 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: URL Patterns for Nested Catagories.
Thanks again. Just following up with my model to show how I'm implementing based on the advice above. Note I call my categories model Topics instead but you get the picture. class Topic(models.Model): ''' Topics form sections and categories of posts to enable topical based conversations. ''' text = models.CharField(max_length=75) parent = models.ForeignKey('self', null=True, blank=True) # Enable topic structures. description = models.TextField(null=True, blank=True) slug = models.CharField(max_length=75) path = models.CharField(max_length=255) # Custom manager for returning published posts. objects = TopicManager() def get_path(self): ''' Constructs the path value for this topic based on hierarchy. ''' ontology = [] target = self.parent while(target is not None): ontology.append(target.slug) target = target.parent ontology.append(self.slug) return '/'.join(ontology) def save(self, force_insert=False, force_update=False): ''' Custom save method to handle slugs and such. ''' # Set pub_date if none exist and publish is true. if not self.slug: qs = Topic.objects.filter(parent=self.parent) unique_slugify(self, self.text, queryset=qs) # Unique for each parent. # Raise validation error if trying to create slug duplicate under parent. if Topic.objects.exclude(pk=self.pk).filter(parent=self.parent, slug=self.slug): raise ValidationError("Slugs cannot be duplicated under the same parent topic.") self.path = self.get_path() # Rebuild the path attribute whenever saved. super(Topic, self).save(force_insert, force_update) # Actual Save method. def __unicode__(self): '''Returns the name of the Topic as a it's chained relationship.''' ontology = [] target = self.parent while(target is not None): ontology.append(target.text) target = target.parent ontology.append(self.text) return ' - '.join(ontology) class Meta: ordering = ['path'] unique_together = (('slug', 'parent')) On Apr 7, 8:34 pm, Tim Shaffer wrote: > Oh, check out the Category class from django-simplecms. It implements > the first method. > > Specifically, check out the save() method that builds the path based > on all the parent categories if it doesn't exist. > > http://code.google.com/p/django-simplecms/source/browse/trunk/simplec... -- 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.