Re: auth: get_profile(): create if it does not exist.

2009-01-14 Thread jweinstein
Where does this code go? I want to create a user profile for every user created. On Dec 18 2008, 2:37 am, "James Bennett" wrote: > On Wed, Dec 17, 2008 at 5:21 PM, Malcolm Tredinnick > > wrote: > > This would be the "standard" solution. I

Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread James Bennett
On Wed, Dec 17, 2008 at 5:21 PM, Malcolm Tredinnick wrote: > This would be the "standard" solution. I thought James Bennett's > django-profiles app did this, but apparently I'm mistaken (it would be > slightly duplicated work if it did, in any case). django-profiles

Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread Thomas Guettler
> ## > try: > m = SomeModel.objects.get(pk=request.user) > except: > m = SomeModel() > ## > > Attention, catch-all ("except" without an exception class) is evil. There are a lot of exception that could happen. You could use: try: except SomeModel.DoesNotExist:

Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread Malcolm Tredinnick
On Wed, 2008-12-17 at 08:25 -0600, Milan Andric wrote: > On Wed, Dec 17, 2008 at 4:00 AM, Thomas Guettler wrote: > > > > Hi, > > > > The method user.get_profile() fails, if the user has no profile. During > > my custom login I > > check if the user has a profile and create it

Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread 7timesTom
actually don't user super(self.__class__, self) http://loveandtheft.org/2008/09/03/how-super-should-be-used-when-calling-a-parents-method/ use super(MyManager, self) On 17 Dec, 18:15, 7timesTom wrote: > On 17 Dec, 16:08, Darthmahon wrote: > >

Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread 7timesTom
On 17 Dec, 16:08, Darthmahon wrote: > Why not create your own function then and just put the try or except > code in that? That way it'll only be one line. Yup. Using model.Manager i.e.: class MyManager(models.Manager): def get_or_blank(self, pk_val): try:

Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread Darthmahon
Why not create your own function then and just put the try or except code in that? That way it'll only be one line. On Dec 17, 3:19 pm, nbv4 wrote: > On Dec 17, 5:00 am, Thomas Guettler wrote: > > > > > Hi, > > > The method user.get_profile() fails, if the

Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread nbv4
On Dec 17, 5:00 am, Thomas Guettler wrote: > Hi, > > The method user.get_profile() fails, if the user has no profile. During > my custom login I > check if the user has a profile and create it if needed. > > But sometimes this fails: A new user gets created, but before his

Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread Milan Andric
On Wed, Dec 17, 2008 at 4:00 AM, Thomas Guettler wrote: > > Hi, > > The method user.get_profile() fails, if the user has no profile. During > my custom login I > check if the user has a profile and create it if needed. > > But sometimes this fails: A new user gets created, but

Re: auth: get_profile(): create if it does not exist.

2008-12-17 Thread Darthmahon
Can you not do this: if request.user.is_authenticated(): # Get profile user.get_profile() else: # Create profile On Dec 17, 10:00 am, Thomas Guettler wrote: > Hi, > > The method user.get_profile() fails, if the user has no profile. During > my custom login I >

auth: get_profile(): create if it does not exist.

2008-12-17 Thread Thomas Guettler
Hi, The method user.get_profile() fails, if the user has no profile. During my custom login I check if the user has a profile and create it if needed. But sometimes this fails: A new user gets created, but before his first login someone else tries to access the not yet created profile. Since