Re: Get current user in model signal pre_save

2022-11-28 Thread Pankaja Withanachchi
I had an issue where the password field didn't match the password field used in the default User Model Admin. This fixed that issue: https://stackoverflow.com/questions/73816296/password-field-is-visible-and-not-encrypted-in-django-admin-site Hope it helps somebody else! On Thursday, September

Re: How can I get current user in my ModelForm, using inlineformset?

2015-10-19 Thread Mark Steadman
I think the answer you need is available through the docs, at https://docs.djangoproject.com/en/1.8/topics/forms/modelforms/#changing-the-queryset (I point to that because it does a much better job of explaining the answer than I can). You're passing in an object - an instantiated form -

How can I get current user in my ModelForm, using inlineformset?

2015-10-15 Thread Fellipe Henrique
Hello, I have my ModelForm... and I need to filter my products with Current User.. if a change my modelform init, doesn't show me any error, but when I use in my inlineformset, show me on error.. Here is my code: View: ofertasinlineformset = inlineformset_factory(Assinatura, Ofertas,

Re: Get current user in model signal pre_save

2015-09-10 Thread Xavier Palacín Ayuso
Finally overrite a UserAdmin ModelAdmin: from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User from django.utils.translation import ugettext, ugettext_lazy as _ from django.core.exceptions import PermissionDenied class UserAdmin(admin.ModelAdmin):

Get current user in model signal pre_save

2015-09-09 Thread Xavier Palacín Ayuso
I want to collects current user in model signal pre_save, to prevent remove super user permission to current super users. As I have now so I can not give administrative privileges to a normal user. from django.db.models.signals import pre_delete, pre_save, post_save from

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

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 =

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 =

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',

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

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)

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=

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

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

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

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

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

2009-08-06 Thread Daniel Roseman
On Aug 6, 9:14 am, krylatij <kryla...@gmail.com> 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 mes

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,

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

2009-08-06 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

Get current user outside a view / without an request object

2009-08-05 Thread Julián C . Pérez
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 =

Re: Get Current User

2009-03-09 Thread Alex Gaynor
On Mon, Mar 9, 2009 at 12:03 PM, Rajesh D wrote: > > > > On Mar 9, 12:48 pm, Adam Schmitz wrote: > > Hey All, > > > > I just setup my webapp to use the django user authentication and > everything > > works smoothly so far. The one thing I'm

Re: Get Current User

2009-03-09 Thread Rajesh D
On Mar 9, 12:48 pm, Adam Schmitz wrote: > Hey All, > > I just setup my webapp to use the django user authentication and everything > works smoothly so far. The one thing I'm wondering is: after the user logs > in, how do you access the user object from another app? > > The

Re: Get Current User

2009-03-09 Thread Briel
You can get the current user through the request object: request.user. If that fails, you need to have if you have AuthenticationMiddleware installed probably. ~Briel On 9 Mar., 17:48, Adam Schmitz wrote: > Hey All, > > I just setup my webapp to use the django user

Get Current User

2009-03-09 Thread Adam Schmitz
Hey All, I just setup my webapp to use the django user authentication and everything works smoothly so far. The one thing I'm wondering is: after the user logs in, how do you access the user object from another app? The main thing I'm trying to accomplish is I want to save a model with one of

Re: using threadlocals to get current user outside views

2008-04-03 Thread Mike Axiak
I wouldn't use it. For the admin, I find myself using javascript just fine to do what I want. I usually have a middleware that sets the current user id as a cookie, then run something like the following javascript in the admin on window load: (requires jquery with cookie plugin) /*

using threadlocals to get current user outside views

2008-04-03 Thread Aljosa Mohorovic
i'm using admin app and found myself in situation where i need to store current user when saving item so i've overwritten save method on model and with threadlocals middleware fetched current user. threadlocals middleware url: http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser is

Re: Get current user ID in _pre_save() function

2006-03-27 Thread bruno desthuilliers
Gacha wrote: > I created a simple model "articles" and I added field: > author= meta.ForeignKey(User,editable=False) > > When I add new artcicle I want to assign to this field the current user > ID, but so far no luck :( > > I tryed: > def _pre_save(self): > from

Re: Get current user ID in _pre_save() function

2006-03-26 Thread Gacha
I solved this problem by this patch: http://code.djangoproject.com/attachment/ticket/1132/current_user_field_patch.2.diff Now I use: author = meta.CurrentUserField(update_on_edit=False) -- But the problem about User management is not solved :(

Get current user ID in _pre_save() function

2006-03-25 Thread Gacha
I created a simple model "articles" and I added field: author = meta.ForeignKey(User,editable=False) When I add new artcicle I want to assign to this field the current user ID, but so far no luck :( I tryed: def _pre_save(self): from django.models.auth.users import User self.author =