Total Complexity | 2 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |