Re: Get current user in model signal pre_save

2015-09-10 Thread Xavier Palacín Ayuso
Thanks

El miércoles, 9 de septiembre de 2015, 17:27:25 (UTC+2), Tom Evans escribió:
>
> On Wed, Sep 9, 2015 at 4:11 PM, Xavier Palacín Ayuso 
> <xpal...@adncomunicacio.com > wrote: 
> > I want to collects current user in model signal pre_save, to prevent 
> remove 
> > super user permission to current super users. 
>
> Hi Xavier. This mailing list is for discussing the development of 
> django itself, not for discussing how to develop in django. 
>
> For help with developing in django, please use django-users mailing 
> list (and be patient - just because no-one has answered you in 6 hours 
> does not mean you should kick it up to django-developers). 
>
> Cheers 
>
> Tom 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/f514bc25-9c1b-4fdc-bbc7-bb8886148fe8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Hide specific users from auth user model for non super users

2015-09-09 Thread Xavier Palacín Ayuso
I need hide a super admin's users from auth user model of Django of list 
users template for a normal users or no super admin users.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/e1c56f2b-c2ec-4314-88ad-c341d193e836%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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 django.dispatch.dispatcher import receiver
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied


@receiver(pre_save, sender=User)
def save_user(sender, instance, **kwargs):
if instance._state.adding is True:
# we would need to create the object
print "Creating an object"
else:
#we are updating the object
if instance.is_superuser:
raise PermissionDenied

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/1b710450-6d76-46ce-a8bf-1a0a49c55cf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.