2015-09-24 09:02:45 +00:00
|
|
|
from django.db.models import signals
|
2014-05-23 08:02:34 +00:00
|
|
|
from django.apps import AppConfig
|
2014-11-21 19:16:39 +00:00
|
|
|
|
2014-11-21 19:08:20 +00:00
|
|
|
|
2014-05-23 08:02:34 +00:00
|
|
|
class ConstanceConfig(AppConfig):
|
|
|
|
|
name = 'constance'
|
2017-11-06 16:43:08 +00:00
|
|
|
verbose_name = 'Constance'
|
2015-08-25 11:54:11 +00:00
|
|
|
|
|
|
|
|
def ready(self):
|
2019-12-23 21:20:41 +00:00
|
|
|
super().ready()
|
2015-09-24 09:02:45 +00:00
|
|
|
signals.post_migrate.connect(self.create_perm,
|
|
|
|
|
dispatch_uid='constance.create_perm')
|
|
|
|
|
|
2017-02-04 16:58:58 +00:00
|
|
|
def create_perm(self, using=None, *args, **kwargs):
|
2015-09-24 09:02:45 +00:00
|
|
|
"""
|
|
|
|
|
Creates a fake content type and permission
|
|
|
|
|
to be able to check for permissions
|
|
|
|
|
"""
|
2018-03-02 23:40:41 +00:00
|
|
|
from django.conf import settings
|
2015-09-24 09:02:45 +00:00
|
|
|
from django.contrib.auth.models import Permission
|
|
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
|
|
2018-03-02 23:40:41 +00:00
|
|
|
constance_dbs = getattr(settings, 'CONSTANCE_DBS', None)
|
|
|
|
|
if constance_dbs is not None and using not in constance_dbs:
|
|
|
|
|
return
|
2015-09-24 09:02:45 +00:00
|
|
|
if ContentType._meta.installed and Permission._meta.installed:
|
2017-02-04 16:58:58 +00:00
|
|
|
content_type, created = ContentType.objects.using(using).get_or_create(
|
2015-09-24 09:02:45 +00:00
|
|
|
app_label='constance',
|
|
|
|
|
model='config',
|
2016-09-14 17:22:32 +00:00
|
|
|
)
|
2015-09-24 09:02:45 +00:00
|
|
|
|
2017-02-04 16:58:58 +00:00
|
|
|
permission, created = Permission.objects.using(using).get_or_create(
|
2015-09-24 09:02:45 +00:00
|
|
|
content_type=content_type,
|
2018-04-20 09:50:20 +00:00
|
|
|
codename='change_config',
|
|
|
|
|
defaults={'name': 'Can change config'})
|