Passed
Push — master ( e32157...9a4845 )
by Alexander
04:03
created

backwards()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
from django.db import migrations
2
3
4
def forwards_add_perms(apps, schema_editor):
5
    """
6
        Adds permissions for this app to the group 'Tester'.
7
        This is useful in case that is an existing installation
8
        upgrading post 7.0.
9
    """
10
    Group = apps.get_model('auth', 'Group')
11
    Permission = apps.get_model('auth', 'Permission')
12
13
    tester = Group.objects.get(name='Tester')
14
    app_perms = Permission.objects.filter(content_type__app_label__contains='bugs')
15
    tester.permissions.add(*app_perms)
16
17
18
def backwards(apps, schema_editor):
19
    Group = apps.get_model('auth', 'Group')
20
    Permission = apps.get_model('auth', 'Permission')
21
    tester = Group.objects.get(name='Tester')
22
    app_perms = Permission.objects.filter(content_type__app_label__contains='bugs')
23
    tester.permissions.remove(*app_perms)
24
25
26
class Migration(migrations.Migration):
27
    dependencies = [
28
        ('bugs', '0001_initial'),
29
        ('core', '0001_squashed'),
30
    ]
31
32
    operations = [
33
        migrations.RunPython(forwards_add_perms, backwards),
34
    ]
35