Add groups and permissions for BDS staff & members

This commit is contained in:
Martin Pépin 2017-02-22 18:19:49 +01:00
parent 859f191894
commit d36d69238d
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.auth.models import Group, Permission
from django.db import migrations
def create_groups(apps, schema_editor):
from django.contrib.auth.management import create_permissions
apps.models_module = True
create_permissions(apps, verbosity=0)
apps.models_module = None
memberp = Permission.objects.get(
codename="member",
content_type__app_label="bds"
)
burop = Permission.objects.get(
codename="buro",
content_type__app_label="bds"
)
# Creates the groups for BDS members and staff
member = Group.objects.create(name="bds_members")
buro = Group.objects.create(name="bds_buro")
# Associates the permissions to the respective groups
member.permissions = [memberp]
buro.permissions = [memberp, burop]
class Migration(migrations.Migration):
dependencies = [
('bds', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='bdsprofile',
options={
'permissions': [
('member', 'Is a BDS member'),
('buro', 'Is part of the BDS staff')
],
'verbose_name': 'Profil BDS',
'verbose_name_plural': 'Profils BDS'
},
),
migrations.RunPython(create_groups, migrations.RunPython.noop),
]

View file

@ -55,3 +55,11 @@ class BdsProfile(models.Model):
default='CASH',
choices=PAYMENT_METHOD_CHOICES,
max_length=6)
class Meta:
verbose_name = "Profil BDS"
verbose_name_plural = "Profils BDS"
permissions = [
("member", "Is a BDS member"),
("buro", "Is part of the BDS staff")
]