def post_save_user_handler(sender, **kwargs): user = kwargs['instance'] if user.is_staff: # only give add_staffprofile permissions to staff
p_add_perm = Permission.objects.get (codename='add_staffprofile') p_change_perm = Permission.objects.get (codename='change_staffprofile') try: user.get_profile() # See if there is a profile already (raises exception if there isn't) except: # user doesn't have a profile, give them add_staffprofile permissions if p_add_perm not in user.user_permissions.all(): user.user_permissions.add(p_add_perm) else: # user has a profile already, remove add_staffprofile and add change_staffprofile if p_add_perm in user.user_permissions.all(): user.user_permissions.remove(p_add_perm) if p_change_perm not in user.user_permissions.all(): user.user_permissions.add(p_change_perm) signals.post_save.connect(post_save_user_handler, sender=User) # Hopefully User is setup by now... ####### I have a new user who is a staff member but doesn't have a profile yet. Each time the user is edited (saved) I want to check if they are still staff and if they have a profile created. If they do, I want to remove their add_staffprofile permission and give them a change_staffprofile permission instead. If they don't have a profile, I want to make sure they have an add_staffprofile permissions. I can run this from the interactive prompt (python manage.py runserver) and it works as expected (user gets add_staffprofile permission). But when I save the user in the admin (as a staff member without a profile) the permission is never added. Thanks for any pointers... Andrew. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---