2016-01-25 14:48:00 +01:00
|
|
|
from django.contrib.auth.models import Permission
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
from django.db.models import Q
|
2015-02-12 20:57:05 +01:00
|
|
|
from django.dispatch import Signal
|
2013-03-11 21:32:09 +01:00
|
|
|
|
2015-02-12 20:57:05 +01:00
|
|
|
# This signal is sent when the migrate command is done. That means it is sent
|
|
|
|
# after post_migrate sending and creating all Permission objects. Don't use it
|
|
|
|
# for other things than dealing with Permission objects.
|
|
|
|
post_permission_creation = Signal()
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
|
2016-01-25 14:48:00 +01:00
|
|
|
def delete_django_app_permissions(sender, **kwargs):
|
|
|
|
"""
|
|
|
|
Deletes the permissions, Django creates by default. Only required
|
|
|
|
for auth, contenttypes and sessions.
|
|
|
|
"""
|
|
|
|
contenttypes = ContentType.objects.filter(
|
|
|
|
Q(app_label='auth') |
|
|
|
|
Q(app_label='contenttypes') |
|
|
|
|
Q(app_label='sessions'))
|
2016-10-01 01:30:55 +02:00
|
|
|
Permission.objects.filter(content_type__in=contenttypes).delete()
|