Re: Custom form validation request or user-based

2009-09-02 Thread Daniel Roseman

On Sep 2, 10:59 am, Matthias Kestenholz
 wrote:
> On Wed, Sep 2, 2009 at 10:38 AM, Enrico
>
> Sartorello wrote:
> >> if you need this only for the administration site you'd hvae other
> >> hooks that you could override. Either take a look at the documentation
> >> or at django/contrib/admin/options.py
>
> > If you mean overriding the ModelAdmin.form object, that doesn't solve the
> > problem as far as i can see, cause i can't provide arguments there (in that
> > case, the user).
>
> That's correct, but luckily there are more customization hooks available.
>
> Matthias

In particular, you want to look at overriding add_view and change_view
in the ModelAdmin class.
--
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: Custom form validation request or user-based

2009-09-02 Thread Matthias Kestenholz

On Wed, Sep 2, 2009 at 10:38 AM, Enrico
Sartorello wrote:
>> if you need this only for the administration site you'd hvae other
>> hooks that you could override. Either take a look at the documentation
>> or at django/contrib/admin/options.py
>>
>
> If you mean overriding the ModelAdmin.form object, that doesn't solve the
> problem as far as i can see, cause i can't provide arguments there (in that
> case, the user).

That's correct, but luckily there are more customization hooks available.

Matthias

--~--~-~--~~~---~--~~
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: Custom form validation request or user-based

2009-09-02 Thread Enrico Sartorello
On Wed, Sep 2, 2009 at 10:25 AM, Matthias Kestenholz  wrote:

>
> On Wed, Sep 2, 2009 at 9:15 AM, Enrico
> Sartorello wrote:
> > Up.
> >
>
> Already?
>
>
Yes, cause it seemed to me that a message buried by other 30 messages was
about to be left unanswered :-)


>
>
>

> > On Tue, Sep 1, 2009 at 11:06 AM, Enrico Sartorello
> >  wrote:
> >>
> >> Wait a moment: this solution doesn't solve my problem.
> >> Remember that the form I need has to be used on the admin site, so I
> can't
> >> deal with it directly (in fact, I can't instantiate it and provide
> >> additional arguments).
> >>
>
> if you need this only for the administration site you'd hvae other
> hooks that you could override. Either take a look at the documentation
> or at django/contrib/admin/options.py
>
>
If you mean overriding the ModelAdmin.form object, that doesn't solve the
problem as far as i can see, cause i can't provide arguments there (in that
case, the user).


>
> Matthias
>
> >
>


-- 
Enrico Sartorello

--~--~-~--~~~---~--~~
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: Custom form validation request or user-based

2009-09-02 Thread Matthias Kestenholz

On Wed, Sep 2, 2009 at 9:15 AM, Enrico
Sartorello wrote:
> Up.
>

Already?


> On Tue, Sep 1, 2009 at 11:06 AM, Enrico Sartorello
>  wrote:
>>
>> Wait a moment: this solution doesn't solve my problem.
>> Remember that the form I need has to be used on the admin site, so I can't
>> deal with it directly (in fact, I can't instantiate it and provide
>> additional arguments).
>>

if you need this only for the administration site you'd hvae other
hooks that you could override. Either take a look at the documentation
or at django/contrib/admin/options.py


Matthias

--~--~-~--~~~---~--~~
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: Custom form validation request or user-based

2009-09-02 Thread Enrico Sartorello
Up.

On Tue, Sep 1, 2009 at 11:06 AM, Enrico Sartorello <
enrico.sartore...@gmail.com> wrote:

> Wait a moment: this solution doesn't solve my problem.
> Remember that the form I need has to be used on the admin site, so I can't
> deal with it directly (in fact, I can't instantiate it and provide
> additional arguments).
>
> Are there any other way to accomplish that?
>
>
> On Tue, Sep 1, 2009 at 10:48 AM, Enrico Sartorello <
> enrico.sartore...@gmail.com> wrote:
>
>> Thank you very much, your solution is simple and efficient :-)
>>
>>
>> On Mon, Aug 31, 2009 at 10:57 PM, Matthias Kestenholz <
>> matthias.kestenh...@gmail.com> wrote:
>>
>>>
>>> On Fri, Aug 28, 2009 at 10:34 AM, Enrico
>>> Sartorello wrote:
>>> > Hi,
>>> > i'm developing a Django application where i need to differentiate the
>>> > validation of an admin-site model form between different users: some
>>> user
>>> > must respect some particular restrictions (imposed via "clean_*"
>>> methods)
>>> > while others should do what they want without them.
>>> >
>>> > The problem arises because during form validation i cannot access any
>>> > request object (so i can't build a permission-based criteria), and
>>> checking
>>> > everything in other places (like Model_admin.save_model() method or
>>> with
>>> > signals) can't do the job because there i can't raise form's validation
>>> > errors.
>>> >
>>> > I've searched on the net but seems i cannot find any solution for that
>>> > problem.
>>> >
>>> > Any hints?
>>> >
>>>
>>> Simple: Pass the current user to the form:
>>>
>>> class MyForm(forms.ModelForm):
>>>def __init__(self, *args, **kwargs):
>>>self.saved_user = kwargs.pop('user')
>>>super(MyForm, self).__init__(*args, **kwargs)
>>>
>>> Somewhere else in the code:
>>>
>>> form = MyForm(request.POST, user=request.user)
>>>
>>> resp.
>>>
>>> form = MyForm(user=request.user)
>>>
>>>
>>>
>>> Of course that isn't the only possibility to achieve what you want,
>>> but it's quite straightforward to do it like this.
>>>
>>>
>>> Matthias
>>>
>>>
>>> --
>>> FeinCMS Django CMS building toolkit: http://spinlock.ch/pub/feincms/
>>>
>>> >>>
>>>
>>
>>
>> --
>> Enrico Sartorello
>>
>
>
>
> --
> Enrico Sartorello
>



-- 
Enrico Sartorello

--~--~-~--~~~---~--~~
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: Custom form validation request or user-based

2009-09-01 Thread Enrico Sartorello
Wait a moment: this solution doesn't solve my problem.
Remember that the form I need has to be used on the admin site, so I can't
deal with it directly (in fact, I can't instantiate it and provide
additional arguments).

Are there any other way to accomplish that?

On Tue, Sep 1, 2009 at 10:48 AM, Enrico Sartorello <
enrico.sartore...@gmail.com> wrote:

> Thank you very much, your solution is simple and efficient :-)
>
>
> On Mon, Aug 31, 2009 at 10:57 PM, Matthias Kestenholz <
> matthias.kestenh...@gmail.com> wrote:
>
>>
>> On Fri, Aug 28, 2009 at 10:34 AM, Enrico
>> Sartorello wrote:
>> > Hi,
>> > i'm developing a Django application where i need to differentiate the
>> > validation of an admin-site model form between different users: some
>> user
>> > must respect some particular restrictions (imposed via "clean_*"
>> methods)
>> > while others should do what they want without them.
>> >
>> > The problem arises because during form validation i cannot access any
>> > request object (so i can't build a permission-based criteria), and
>> checking
>> > everything in other places (like Model_admin.save_model() method or with
>> > signals) can't do the job because there i can't raise form's validation
>> > errors.
>> >
>> > I've searched on the net but seems i cannot find any solution for that
>> > problem.
>> >
>> > Any hints?
>> >
>>
>> Simple: Pass the current user to the form:
>>
>> class MyForm(forms.ModelForm):
>>def __init__(self, *args, **kwargs):
>>self.saved_user = kwargs.pop('user')
>>super(MyForm, self).__init__(*args, **kwargs)
>>
>> Somewhere else in the code:
>>
>> form = MyForm(request.POST, user=request.user)
>>
>> resp.
>>
>> form = MyForm(user=request.user)
>>
>>
>>
>> Of course that isn't the only possibility to achieve what you want,
>> but it's quite straightforward to do it like this.
>>
>>
>> Matthias
>>
>>
>> --
>> FeinCMS Django CMS building toolkit: http://spinlock.ch/pub/feincms/
>>
>> >>
>>
>
>
> --
> Enrico Sartorello
>



-- 
Enrico Sartorello

--~--~-~--~~~---~--~~
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: Custom form validation request or user-based

2009-09-01 Thread Enrico Sartorello
Thank you very much, your solution is simple and efficient :-)

On Mon, Aug 31, 2009 at 10:57 PM, Matthias Kestenholz <
matthias.kestenh...@gmail.com> wrote:

>
> On Fri, Aug 28, 2009 at 10:34 AM, Enrico
> Sartorello wrote:
> > Hi,
> > i'm developing a Django application where i need to differentiate the
> > validation of an admin-site model form between different users: some user
> > must respect some particular restrictions (imposed via "clean_*" methods)
> > while others should do what they want without them.
> >
> > The problem arises because during form validation i cannot access any
> > request object (so i can't build a permission-based criteria), and
> checking
> > everything in other places (like Model_admin.save_model() method or with
> > signals) can't do the job because there i can't raise form's validation
> > errors.
> >
> > I've searched on the net but seems i cannot find any solution for that
> > problem.
> >
> > Any hints?
> >
>
> Simple: Pass the current user to the form:
>
> class MyForm(forms.ModelForm):
>def __init__(self, *args, **kwargs):
>self.saved_user = kwargs.pop('user')
>super(MyForm, self).__init__(*args, **kwargs)
>
> Somewhere else in the code:
>
> form = MyForm(request.POST, user=request.user)
>
> resp.
>
> form = MyForm(user=request.user)
>
>
>
> Of course that isn't the only possibility to achieve what you want,
> but it's quite straightforward to do it like this.
>
>
> Matthias
>
>
> --
> FeinCMS Django CMS building toolkit: http://spinlock.ch/pub/feincms/
>
> >
>


-- 
Enrico Sartorello

--~--~-~--~~~---~--~~
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: Custom form validation request or user-based

2009-08-31 Thread Matthias Kestenholz

On Fri, Aug 28, 2009 at 10:34 AM, Enrico
Sartorello wrote:
> Hi,
> i'm developing a Django application where i need to differentiate the
> validation of an admin-site model form between different users: some user
> must respect some particular restrictions (imposed via "clean_*" methods)
> while others should do what they want without them.
>
> The problem arises because during form validation i cannot access any
> request object (so i can't build a permission-based criteria), and checking
> everything in other places (like Model_admin.save_model() method or with
> signals) can't do the job because there i can't raise form's validation
> errors.
>
> I've searched on the net but seems i cannot find any solution for that
> problem.
>
> Any hints?
>

Simple: Pass the current user to the form:

class MyForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.saved_user = kwargs.pop('user')
super(MyForm, self).__init__(*args, **kwargs)

Somewhere else in the code:

form = MyForm(request.POST, user=request.user)

resp.

form = MyForm(user=request.user)



Of course that isn't the only possibility to achieve what you want,
but it's quite straightforward to do it like this.


Matthias


-- 
FeinCMS Django CMS building toolkit: http://spinlock.ch/pub/feincms/

--~--~-~--~~~---~--~~
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: Custom form validation request or user-based

2009-08-31 Thread Enrico Sartorello
Up.

On Fri, Aug 28, 2009 at 10:34 AM, Enrico Sartorello <
enrico.sartore...@gmail.com> wrote:

> Hi,
> i'm developing a Django application where i need to differentiate the
> validation of an admin-site model form between different users: some user
> must respect some particular restrictions (imposed via "clean_*" methods)
> while others should do what they want without them.
>
> The problem arises because during form validation i cannot access any
> request object (so i can't build a permission-based criteria), and checking
> everything in other places (like Model_admin.save_model() method or with
> signals) can't do the job because there i can't raise form's validation
> errors.
>
> I've searched on the net but seems i cannot find any solution for that
> problem.
>
> Any hints?
>
> Thanks for the attention
>
>
> --
> Enrico Sartorello
>



-- 
Enrico Sartorello

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