Friday, January 22, 2010

Re: Should a decorator be used here or should I do something else.

If it's different instances of the model that should have age-restrictions applied then I would be tempted to push this down to the model layer by creating a new Manager called e.g. age_filtered and then use that in view:

q = Data.age_filtered(age).filter(id=23)

You could even make the default manager the age filter so that if a view forgets to use the age_filtered() manager then they only get "safe" all ages content (assuming such a thing exists).

Malcolm

On Thu, Jan 21, 2010 at 5:13 PM, Bill Freeman <ke1g.nh@gmail.com> wrote:
A decorator is certainly a clean way to apply consistent checking to a bunch of
views.  But it is primarily useful if the selection of the view
function by the urlconf
gives you all you need to know about for what age groups the *CONTENT* is
appropriate.

If, on the other hand, different rows in the same table (different
instances of the
same model) are appropriate for different age groups, then you're stuck with
either doing your object query in the decorator and passing it to the
view, which
might be too magic.  (Maybe pass a base queryset to the view for
further filtering,
but still pretty magic.)

A shared function that you call from the view to filter a queryset based on age
criteria might feel more explicit.

Bill

On Wed, Jan 20, 2010 at 5:15 PM, Jeffrey Taggarty <jtaggarty@gmail.com> wrote:
> Hi Guys, I have a bit of a dilemma in terms of design of a small web
> application...
>
> I have this requirement where content is being served by age group. On
> first load the user selects their age group and I store that in the
> cookie. I read that cookie and query content for the pages based on
> that agegroup cookie. My question is should I use a decorator to check
> the cookie on every new page requested to make sure they're getting
> the proper content served based on that agegroup in the cookie? I have
> about 6 functions in total in my views. I was thinking just writing a
> decorator to handle that but I am not sure that's the best way to go
> about this.
>
> Thanks
>
>
> Jeff
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>
>
>

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




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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate