Re: Calling method of a proxy-model in a template

2010-10-08 Thread mettwoch
Hi Daniel,

Thanks for the hint, I've read through the documentation and I should
be able to handle it despite the fact that I'm more of a "surface"
than an "underground" programmer.

Kindly Yours
Marc

On Sep 30, 5:19 pm, Daniel Roseman  wrote:
> On Sep 30, 3:31 pm, mettwoch  wrote:
>
> > Hi,
>
> > Let's say that I have aproxymodel of the User model that adds some
> > methods. What would be an elegant way to access these methods from
> > within a template in the same easy way I access the User attributes
> > through {{ request.session.user.some_attribute }}.
>
> > Kindly Yours
> > Marc
>
> Well, you don't access the user through request.session.user, but
> simply through request.user. And if you have the auth context
> processor installed, which you do by default, you can simply get it
> via {{ user }}.
>
> So one answer is to define your own context processor to use in place
> of the auth one, which returns an instance of yourproxyclass for the
> user.
>
> Another possibility is to provide a custom request middleware which
> replaces request.user with your version. This might be preferable, as
> you now have access to the extra methods throughout your code, not
> just in templates.
> --
> DR.

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



Re: Calling method of a proxy-model in a template

2010-09-30 Thread Daniel Roseman
On Sep 30, 3:31 pm, mettwoch  wrote:
> Hi,
>
> Let's say that I have a proxy model of the User model that adds some
> methods. What would be an elegant way to access these methods from
> within a template in the same easy way I access the User attributes
> through {{ request.session.user.some_attribute }}.
>
> Kindly Yours
> Marc

Well, you don't access the user through request.session.user, but
simply through request.user. And if you have the auth context
processor installed, which you do by default, you can simply get it
via {{ user }}.

So one answer is to define your own context processor to use in place
of the auth one, which returns an instance of your proxy class for the
user.

Another possibility is to provide a custom request middleware which
replaces request.user with your version. This might be preferable, as
you now have access to the extra methods throughout your code, not
just in templates.
--
DR.

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



Calling method of a proxy-model in a template

2010-09-30 Thread mettwoch
Hi,

Let's say that I have a proxy model of the User model that adds some
methods. What would be an elegant way to access these methods from
within a template in the same easy way I access the User attributes
through {{ request.session.user.some_attribute }}.

Kindly Yours
Marc

-- 
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.