Re: Get current user outside a view / without an request object

2009-08-20 Thread Julienoune

Hello, I'have a little problem with this code??

when I'l trying to put :
" def __init__(self, inputUser, *args, **kwargs):"
I have the following error :
__init__() takes at least 2 non-keyword arguments (1 given)

So, I suppose I need to set the inputUser in a specific place, but I
can' figure out where?

For information, I'm working with  the django admin site .

Any idea?

On 7 août, 03:28, Julián C. Pérez  wrote:
> Bingo!!!
> :D
> I follow 
> this:http://oebfare.com/blog/2008/feb/23/changing-modelchoicefield-queryset/
> and now I'm happy with mi desired current user based queryset
> Thank you all!
>
> BTW, my form class finally looks like...
> ---
> class SendMessageForm(forms.Form):
>
>         recipientUser = ShowValidContactList
> (queryset=None,label=u'Send to')
>         messageSubject= forms.CharField(label=u'Subject')
>         messageContent = forms.CharField
> (label=u'Content',widget=forms.Textarea())
>
>         def __init__(self, inputUser, *args, **kwargs):
>                self.user= inputUser
>                super(SendMessageForm, self).__init__(*args, **kwargs)
>                self.fields['recipientUser'].queryset = # Anything with
> the current user, in this case 'self.user'
> ---
>
> On Aug 6, 11:14 am, Julián C. Pérez  wrote:
>
> > Thanks for reply, Paulo
> > But if I...
> > ---
> > class SendMessageForm(forms.Form):
>
> >         recipientUser = ShowValidContactList(currentUser=self.user,
> > label=u'Send to')
> >         messageSubject= forms.CharField(label=u'Subject')
> >         messageContent = forms.CharField(label=u'Content',
> > widget=forms.Textarea())
>
> >         def __init__(self, inputUser, *args, **kwargs):
> >                self.user= inputUser
> >                super(SendMessageForm, self).__init__(*args, **kwargs)
> > ---
> > the 'recipientUser = ShowValidContactList(currentUser=self.user,
> > label=u'Send to')' raises error because of that 'self.user' ('self'
> > wouldn't be defined and be out of scope)
>
> > On Aug 6, 11:09 am, Paulo Almeida  wrote:
>
> > > It doesn't have to be a callable, you can just do something like:
>
> > > recipientUser = ShowValidContactList(currentUser=self.currentUser)
>
> > > I never used that kwargs.pop function (I didn't know you could do that),
> > >  but I have code like this:
>
> > > class ExperimentForm(ModelForm):
> > >     """ Generate form to handle experiment information. """
> > >     def __init__(self, user, *args, **kwargs):
> > >         super(ExperimentForm, self).__init__(*args, **kwargs)
> > >         try:
> > >             preferences = Preferences.objects.get(user=user)
>
> > > That last 'user' is just what came from the function call in the view.
>
> > > - Paulo
>
> > > 2009/8/6 Julián C. Pérez 
>
> > > > My real problem it that the field should looks like:
> > > > ---
> > > > recipientUser = ShowValidContactList(currentUser=_something_,
> > > > label=u'Send to')
> > > > ---
> > > > and if I have a form's init method like...
> > > > ---
> > > > def __init__(self, *args, **kwargs):
> > > >    self.currentUser = kwargs.pop('currentUser', None)
> > > >    super(SendMessageForm, self).__init__(*args, **kwargs)
> > > > ---
> > > > it won't change the current user already defined in the field
>
> > > > Now, I want to make something like...
> > > > ---
> > > > recipientUser = ShowValidContactList(currentUser=getCurrentUser,
> > > > label=u'Send to')
> > > > ---
> > > > where 'getCurrentUser' is a callable function similar to:
> > > > ---
> > > > def get_image_path(instance, filename):
> > > >    return 'photos/%s/%s' % (instance.id, filename)
>
> > > > class Photo(models.Model):
> > > >    image = models.ImageField(upload_to=get_image_path)
> > > > ---
> > > > how can I do that?
>
> > > > On Aug 6, 9:58 am, Daniel Roseman  wrote:
> > > > > On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
>
> > > > > > Hi
> > > > > > I tried doing that...
> > > > > > But it does not work
> > > > > > For example, if I do something like...
> > > > > > ---
> > > > > > class SendMessageForm(forms.Form):
> > > > > >         recipientUser = ShowValidContactList(label=u'Send to')
> > > > > >         messageSubject= forms.CharField(label=u'Subject')
> > > > > >         messageContent = forms.CharField
> > > > > > (label=u'Content',widget=forms.Textarea())
> > > > > >         def __init__(self, currentUser):
> > > > > >                 self.currentUser = currentUser
> > > > > >                 super(SendMessageForm, self).__init__(*args, 
> > > > > > **kwargs)
> > > > > > ---
> > > > > > that init method in my custom form class won't change anything in 
> > > > > > the
> > > > > > already defined ShowValidContactList field
>
> > > > > Because you are clobbering the existing parameters to __init__. You
> > > > > should do it like this:
>
> > > > > def __init__(self, *args, **kwargs):
> > > > >     self.currentUser = kwargs.pop('currentUser', None)
> > > > >     super(SendMessageForm, self).__init__(*args, **kwargs)
>
> > > > > --
> > > > > DR.
--~--~-

Re: Get current user outside a view / without an request object

2009-08-06 Thread Julián C . Pérez

Bingo!!!
:D
I follow this:
http://oebfare.com/blog/2008/feb/23/changing-modelchoicefield-queryset/
and now I'm happy with mi desired current user based queryset
Thank you all!

BTW, my form class finally looks like...
---
class SendMessageForm(forms.Form):

recipientUser = ShowValidContactList
(queryset=None,label=u'Send to')
messageSubject= forms.CharField(label=u'Subject')
messageContent = forms.CharField
(label=u'Content',widget=forms.Textarea())

def __init__(self, inputUser, *args, **kwargs):
   self.user= inputUser
   super(SendMessageForm, self).__init__(*args, **kwargs)
   self.fields['recipientUser'].queryset = # Anything with
the current user, in this case 'self.user'
---

On Aug 6, 11:14 am, Julián C. Pérez  wrote:
> Thanks for reply, Paulo
> But if I...
> ---
> class SendMessageForm(forms.Form):
>
>         recipientUser = ShowValidContactList(currentUser=self.user,
> label=u'Send to')
>         messageSubject= forms.CharField(label=u'Subject')
>         messageContent = forms.CharField(label=u'Content',
> widget=forms.Textarea())
>
>         def __init__(self, inputUser, *args, **kwargs):
>                self.user= inputUser
>                super(SendMessageForm, self).__init__(*args, **kwargs)
> ---
> the 'recipientUser = ShowValidContactList(currentUser=self.user,
> label=u'Send to')' raises error because of that 'self.user' ('self'
> wouldn't be defined and be out of scope)
>
> On Aug 6, 11:09 am, Paulo Almeida  wrote:
>
> > It doesn't have to be a callable, you can just do something like:
>
> > recipientUser = ShowValidContactList(currentUser=self.currentUser)
>
> > I never used that kwargs.pop function (I didn't know you could do that),
> >  but I have code like this:
>
> > class ExperimentForm(ModelForm):
> >     """ Generate form to handle experiment information. """
> >     def __init__(self, user, *args, **kwargs):
> >         super(ExperimentForm, self).__init__(*args, **kwargs)
> >         try:
> >             preferences = Preferences.objects.get(user=user)
>
> > That last 'user' is just what came from the function call in the view.
>
> > - Paulo
>
> > 2009/8/6 Julián C. Pérez 
>
> > > My real problem it that the field should looks like:
> > > ---
> > > recipientUser = ShowValidContactList(currentUser=_something_,
> > > label=u'Send to')
> > > ---
> > > and if I have a form's init method like...
> > > ---
> > > def __init__(self, *args, **kwargs):
> > >    self.currentUser = kwargs.pop('currentUser', None)
> > >    super(SendMessageForm, self).__init__(*args, **kwargs)
> > > ---
> > > it won't change the current user already defined in the field
>
> > > Now, I want to make something like...
> > > ---
> > > recipientUser = ShowValidContactList(currentUser=getCurrentUser,
> > > label=u'Send to')
> > > ---
> > > where 'getCurrentUser' is a callable function similar to:
> > > ---
> > > def get_image_path(instance, filename):
> > >    return 'photos/%s/%s' % (instance.id, filename)
>
> > > class Photo(models.Model):
> > >    image = models.ImageField(upload_to=get_image_path)
> > > ---
> > > how can I do that?
>
> > > On Aug 6, 9:58 am, Daniel Roseman  wrote:
> > > > On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
>
> > > > > Hi
> > > > > I tried doing that...
> > > > > But it does not work
> > > > > For example, if I do something like...
> > > > > ---
> > > > > class SendMessageForm(forms.Form):
> > > > >         recipientUser = ShowValidContactList(label=u'Send to')
> > > > >         messageSubject= forms.CharField(label=u'Subject')
> > > > >         messageContent = forms.CharField
> > > > > (label=u'Content',widget=forms.Textarea())
> > > > >         def __init__(self, currentUser):
> > > > >                 self.currentUser = currentUser
> > > > >                 super(SendMessageForm, self).__init__(*args, **kwargs)
> > > > > ---
> > > > > that init method in my custom form class won't change anything in the
> > > > > already defined ShowValidContactList field
>
> > > > Because you are clobbering the existing parameters to __init__. You
> > > > should do it like this:
>
> > > > def __init__(self, *args, **kwargs):
> > > >     self.currentUser = kwargs.pop('currentUser', None)
> > > >     super(SendMessageForm, self).__init__(*args, **kwargs)
>
> > > > --
> > > > DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get current user outside a view / without an request object

2009-08-06 Thread Paulo Almeida
But why don't you put:

recipientUser = ShowValidContactList(currentUser=self.user)

inside the __init__?

- Paulo

2009/8/6 Julián C. Pérez 

>
> Thanks for reply, Paulo
> But if I...
> ---
> class SendMessageForm(forms.Form):
>
>recipientUser = ShowValidContactList(currentUser=self.user,
> label=u'Send to')
>messageSubject= forms.CharField(label=u'Subject')
>messageContent = forms.CharField(label=u'Content',
> widget=forms.Textarea())
>
> def __init__(self, inputUser, *args, **kwargs):
>   self.user= inputUser
>super(SendMessageForm, self).__init__(*args, **kwargs)
> ---
> the 'recipientUser = ShowValidContactList(currentUser=self.user,
> label=u'Send to')' raises error because of that 'self.user' ('self'
> wouldn't be defined and be out of scope)
>
> On Aug 6, 11:09 am, Paulo Almeida  wrote:
> > It doesn't have to be a callable, you can just do something like:
> >
> > recipientUser = ShowValidContactList(currentUser=self.currentUser)
> >
> > I never used that kwargs.pop function (I didn't know you could do that),
> >  but I have code like this:
> >
> > class ExperimentForm(ModelForm):
> > """ Generate form to handle experiment information. """
> > def __init__(self, user, *args, **kwargs):
> > super(ExperimentForm, self).__init__(*args, **kwargs)
> > try:
> > preferences = Preferences.objects.get(user=user)
> >
> > That last 'user' is just what came from the function call in the view.
> >
> > - Paulo
> >
> > 2009/8/6 Julián C. Pérez 
> >
> >
> >
> > > My real problem it that the field should looks like:
> > > ---
> > > recipientUser = ShowValidContactList(currentUser=_something_,
> > > label=u'Send to')
> > > ---
> > > and if I have a form's init method like...
> > > ---
> > > def __init__(self, *args, **kwargs):
> > >self.currentUser = kwargs.pop('currentUser', None)
> > >super(SendMessageForm, self).__init__(*args, **kwargs)
> > > ---
> > > it won't change the current user already defined in the field
> >
> > > Now, I want to make something like...
> > > ---
> > > recipientUser = ShowValidContactList(currentUser=getCurrentUser,
> > > label=u'Send to')
> > > ---
> > > where 'getCurrentUser' is a callable function similar to:
> > > ---
> > > def get_image_path(instance, filename):
> > >return 'photos/%s/%s' % (instance.id, filename)
> >
> > > class Photo(models.Model):
> > >image = models.ImageField(upload_to=get_image_path)
> > > ---
> > > how can I do that?
> >
> > > On Aug 6, 9:58 am, Daniel Roseman  wrote:
> > > > On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
> >
> > > > > Hi
> > > > > I tried doing that...
> > > > > But it does not work
> > > > > For example, if I do something like...
> > > > > ---
> > > > > class SendMessageForm(forms.Form):
> > > > > recipientUser = ShowValidContactList(label=u'Send to')
> > > > > messageSubject= forms.CharField(label=u'Subject')
> > > > > messageContent = forms.CharField
> > > > > (label=u'Content',widget=forms.Textarea())
> > > > > def __init__(self, currentUser):
> > > > > self.currentUser = currentUser
> > > > > super(SendMessageForm, self).__init__(*args,
> **kwargs)
> > > > > ---
> > > > > that init method in my custom form class won't change anything in
> the
> > > > > already defined ShowValidContactList field
> >
> > > > Because you are clobbering the existing parameters to __init__. You
> > > > should do it like this:
> >
> > > > def __init__(self, *args, **kwargs):
> > > > self.currentUser = kwargs.pop('currentUser', None)
> > > > super(SendMessageForm, self).__init__(*args, **kwargs)
> >
> > > > --
> > > > DR.
> >
>

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



Re: Get current user outside a view / without an request object

2009-08-06 Thread Julián C . Pérez

Thanks for reply, Paulo
But if I...
---
class SendMessageForm(forms.Form):

recipientUser = ShowValidContactList(currentUser=self.user,
label=u'Send to')
messageSubject= forms.CharField(label=u'Subject')
messageContent = forms.CharField(label=u'Content',
widget=forms.Textarea())

def __init__(self, inputUser, *args, **kwargs):
   self.user= inputUser
   super(SendMessageForm, self).__init__(*args, **kwargs)
---
the 'recipientUser = ShowValidContactList(currentUser=self.user,
label=u'Send to')' raises error because of that 'self.user' ('self'
wouldn't be defined and be out of scope)

On Aug 6, 11:09 am, Paulo Almeida  wrote:
> It doesn't have to be a callable, you can just do something like:
>
> recipientUser = ShowValidContactList(currentUser=self.currentUser)
>
> I never used that kwargs.pop function (I didn't know you could do that),
>  but I have code like this:
>
> class ExperimentForm(ModelForm):
>     """ Generate form to handle experiment information. """
>     def __init__(self, user, *args, **kwargs):
>         super(ExperimentForm, self).__init__(*args, **kwargs)
>         try:
>             preferences = Preferences.objects.get(user=user)
>
> That last 'user' is just what came from the function call in the view.
>
> - Paulo
>
> 2009/8/6 Julián C. Pérez 
>
>
>
> > My real problem it that the field should looks like:
> > ---
> > recipientUser = ShowValidContactList(currentUser=_something_,
> > label=u'Send to')
> > ---
> > and if I have a form's init method like...
> > ---
> > def __init__(self, *args, **kwargs):
> >    self.currentUser = kwargs.pop('currentUser', None)
> >    super(SendMessageForm, self).__init__(*args, **kwargs)
> > ---
> > it won't change the current user already defined in the field
>
> > Now, I want to make something like...
> > ---
> > recipientUser = ShowValidContactList(currentUser=getCurrentUser,
> > label=u'Send to')
> > ---
> > where 'getCurrentUser' is a callable function similar to:
> > ---
> > def get_image_path(instance, filename):
> >    return 'photos/%s/%s' % (instance.id, filename)
>
> > class Photo(models.Model):
> >    image = models.ImageField(upload_to=get_image_path)
> > ---
> > how can I do that?
>
> > On Aug 6, 9:58 am, Daniel Roseman  wrote:
> > > On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
>
> > > > Hi
> > > > I tried doing that...
> > > > But it does not work
> > > > For example, if I do something like...
> > > > ---
> > > > class SendMessageForm(forms.Form):
> > > >         recipientUser = ShowValidContactList(label=u'Send to')
> > > >         messageSubject= forms.CharField(label=u'Subject')
> > > >         messageContent = forms.CharField
> > > > (label=u'Content',widget=forms.Textarea())
> > > >         def __init__(self, currentUser):
> > > >                 self.currentUser = currentUser
> > > >                 super(SendMessageForm, self).__init__(*args, **kwargs)
> > > > ---
> > > > that init method in my custom form class won't change anything in the
> > > > already defined ShowValidContactList field
>
> > > Because you are clobbering the existing parameters to __init__. You
> > > should do it like this:
>
> > > def __init__(self, *args, **kwargs):
> > >     self.currentUser = kwargs.pop('currentUser', None)
> > >     super(SendMessageForm, self).__init__(*args, **kwargs)
>
> > > --
> > > DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get current user outside a view / without an request object

2009-08-06 Thread Paulo Almeida
It doesn't have to be a callable, you can just do something like:

recipientUser = ShowValidContactList(currentUser=self.currentUser)

I never used that kwargs.pop function (I didn't know you could do that),
 but I have code like this:

class ExperimentForm(ModelForm):
""" Generate form to handle experiment information. """
def __init__(self, user, *args, **kwargs):
super(ExperimentForm, self).__init__(*args, **kwargs)
try:
preferences = Preferences.objects.get(user=user)

That last 'user' is just what came from the function call in the view.

- Paulo

2009/8/6 Julián C. Pérez 

>
> My real problem it that the field should looks like:
> ---
> recipientUser = ShowValidContactList(currentUser=_something_,
> label=u'Send to')
> ---
> and if I have a form's init method like...
> ---
> def __init__(self, *args, **kwargs):
>self.currentUser = kwargs.pop('currentUser', None)
>super(SendMessageForm, self).__init__(*args, **kwargs)
> ---
> it won't change the current user already defined in the field
>
> Now, I want to make something like...
> ---
> recipientUser = ShowValidContactList(currentUser=getCurrentUser,
> label=u'Send to')
> ---
> where 'getCurrentUser' is a callable function similar to:
> ---
> def get_image_path(instance, filename):
>return 'photos/%s/%s' % (instance.id, filename)
>
> class Photo(models.Model):
>image = models.ImageField(upload_to=get_image_path)
> ---
> how can I do that?
>
> On Aug 6, 9:58 am, Daniel Roseman  wrote:
> > On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
> >
> >
> >
> > > Hi
> > > I tried doing that...
> > > But it does not work
> > > For example, if I do something like...
> > > ---
> > > class SendMessageForm(forms.Form):
> > > recipientUser = ShowValidContactList(label=u'Send to')
> > > messageSubject= forms.CharField(label=u'Subject')
> > > messageContent = forms.CharField
> > > (label=u'Content',widget=forms.Textarea())
> > > def __init__(self, currentUser):
> > > self.currentUser = currentUser
> > > super(SendMessageForm, self).__init__(*args, **kwargs)
> > > ---
> > > that init method in my custom form class won't change anything in the
> > > already defined ShowValidContactList field
> >
> > Because you are clobbering the existing parameters to __init__. You
> > should do it like this:
> >
> > def __init__(self, *args, **kwargs):
> > self.currentUser = kwargs.pop('currentUser', None)
> > super(SendMessageForm, self).__init__(*args, **kwargs)
> >
> > --
> > DR.
> >
>

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



Re: Get current user outside a view / without an request object

2009-08-06 Thread Julián C . Pérez

My real problem it that the field should looks like:
---
recipientUser = ShowValidContactList(currentUser=_something_,
label=u'Send to')
---
and if I have a form's init method like...
---
def __init__(self, *args, **kwargs):
self.currentUser = kwargs.pop('currentUser', None)
super(SendMessageForm, self).__init__(*args, **kwargs)
---
it won't change the current user already defined in the field

Now, I want to make something like...
---
recipientUser = ShowValidContactList(currentUser=getCurrentUser,
label=u'Send to')
---
where 'getCurrentUser' is a callable function similar to:
---
def get_image_path(instance, filename):
return 'photos/%s/%s' % (instance.id, filename)

class Photo(models.Model):
image = models.ImageField(upload_to=get_image_path)
---
how can I do that?

On Aug 6, 9:58 am, Daniel Roseman  wrote:
> On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
>
>
>
> > Hi
> > I tried doing that...
> > But it does not work
> > For example, if I do something like...
> > ---
> > class SendMessageForm(forms.Form):
> >         recipientUser = ShowValidContactList(label=u'Send to')
> >         messageSubject= forms.CharField(label=u'Subject')
> >         messageContent = forms.CharField
> > (label=u'Content',widget=forms.Textarea())
> >         def __init__(self, currentUser):
> >                 self.currentUser = currentUser
> >                 super(SendMessageForm, self).__init__(*args, **kwargs)
> > ---
> > that init method in my custom form class won't change anything in the
> > already defined ShowValidContactList field
>
> Because you are clobbering the existing parameters to __init__. You
> should do it like this:
>
> def __init__(self, *args, **kwargs):
>     self.currentUser = kwargs.pop('currentUser', None)
>     super(SendMessageForm, self).__init__(*args, **kwargs)
>
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get current user outside a view / without an request object

2009-08-06 Thread Daniel Roseman

On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
> Hi
> I tried doing that...
> But it does not work
> For example, if I do something like...
> ---
> class SendMessageForm(forms.Form):
>         recipientUser = ShowValidContactList(label=u'Send to')
>         messageSubject= forms.CharField(label=u'Subject')
>         messageContent = forms.CharField
> (label=u'Content',widget=forms.Textarea())
>         def __init__(self, currentUser):
>                 self.currentUser = currentUser
>                 super(SendMessageForm, self).__init__(*args, **kwargs)
> ---
> that init method in my custom form class won't change anything in the
> already defined ShowValidContactList field

Because you are clobbering the existing parameters to __init__. You
should do it like this:

def __init__(self, *args, **kwargs):
self.currentUser = kwargs.pop('currentUser', None)
super(SendMessageForm, self).__init__(*args, **kwargs)

--
DR.

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



Re: Get current user outside a view / without an request object

2009-08-06 Thread Julián C . Pérez

Hi
I tried doing that...
But it does not work
For example, if I do something like...
---
class SendMessageForm(forms.Form):
recipientUser = ShowValidContactList(label=u'Send to')
messageSubject= forms.CharField(label=u'Subject')
messageContent = forms.CharField
(label=u'Content',widget=forms.Textarea())
def __init__(self, currentUser):
self.currentUser = currentUser
super(SendMessageForm, self).__init__(*args, **kwargs)
---
that init method in my custom form class won't change anything in the
already defined ShowValidContactList field

I also tried threadlocal's approach... but it didn't work either and
it's a weird way to do that...
I'm gonna go in a different direction, inspired by similar former
problem
Thank you alll, now I'll report with my status

On Aug 6, 1:40 am, Daniel Roseman  wrote:
> On Aug 6, 2:24 am, Julián C. Pérez  wrote:
>
>
>
> > Hi everyone
> > I'm in trouble because of a form class
> > I have a form class with attributes defined, but with one thing:
> > One of the attributes requires the current user, or al least its
> > username
>
> > The form definition in as shown below:
> > ---
> > class SendMessageForm(forms.Form):
> >         recipientUser = ShowValidContactList(label=u'Send to')
> >         messageSubject= forms.CharField(label=u'Subject')
> >         messageContent = forms.CharField(label=u'Content',
> > widget=forms.Textarea())
> > ---
>
> > As you can tell I'm trying to make a 'Send message' form to make
> > message sending available in my project... but the recipient user must
> > be in the contacts list of the current user...
> > The 'recipientUser' field is a ShowValidContactList
> > (forms.ModelChoiceField) instance... so it works with a fixed queryset
> > based on that user (the currently logged-in one)
>
> > My problem is that... how can I get the current user information
> > outside a view and without request objects??
> > Or... how can I make that form works with a different approach??
>
> > Any help would be appreciate!
>
> This is asked frequently on this group. The answer is to override the
> form's __init__ method and pass the request in there, and store it on
> a form attribute for later use.
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Get current user outside a view / without an request object

2009-08-06 Thread krylatij

> ..go back and read the original poster's
> message. Having the user in threadlocals doesn't solve any problem,
> since he's trying to create a form class based on information in the
> request and that only happens at import time, not every time something
> in the file is looked at.
Yes, my mistake
--~--~-~--~~~---~--~~
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: Get current user outside a view / without an request object

2009-08-06 Thread Malcolm Tredinnick

On Thu, 2009-08-06 at 03:33 -0700, krylatij wrote:
> Why do you think so?

It's bad encapsulation practice, for a start. It breaks Python's
namespacing habits.

In this particular case, however, go back and read the original poster's
message. Having the user in threadlocals doesn't solve any problem,
since he's trying to create a form class based on information in the
request and that only happens at import time, not every time something
in the file is looked at.

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: Get current user outside a view / without an request object

2009-08-06 Thread krylatij

Why do you think so?
--~--~-~--~~~---~--~~
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: Get current user outside a view / without an request object

2009-08-06 Thread Daniel Roseman

On Aug 6, 9:14 am, krylatij  wrote:
> You can also use threadlocals middleware (ask google about it =))
> to get current user without request object

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



Re: Get current user outside a view / without an request object

2009-08-06 Thread krylatij

You can also use threadlocals middleware (ask google about it =))
to get current user without request object
--~--~-~--~~~---~--~~
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: Get current user outside a view / without an request object

2009-08-05 Thread Daniel Roseman

On Aug 6, 2:24 am, Julián C. Pérez  wrote:
> Hi everyone
> I'm in trouble because of a form class
> I have a form class with attributes defined, but with one thing:
> One of the attributes requires the current user, or al least its
> username
>
> The form definition in as shown below:
> ---
> class SendMessageForm(forms.Form):
>         recipientUser = ShowValidContactList(label=u'Send to')
>         messageSubject= forms.CharField(label=u'Subject')
>         messageContent = forms.CharField(label=u'Content',
> widget=forms.Textarea())
> ---
>
> As you can tell I'm trying to make a 'Send message' form to make
> message sending available in my project... but the recipient user must
> be in the contacts list of the current user...
> The 'recipientUser' field is a ShowValidContactList
> (forms.ModelChoiceField) instance... so it works with a fixed queryset
> based on that user (the currently logged-in one)
>
> My problem is that... how can I get the current user information
> outside a view and without request objects??
> Or... how can I make that form works with a different approach??
>
> Any help would be appreciate!

This is asked frequently on this group. The answer is to override the
form's __init__ method and pass the request in there, and store it on
a form attribute for later use.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---