Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.8 KiB
41 lines
1.8 KiB
1 year ago
|
# Generated by Django 3.2.23 on 2023-12-11 19:40
|
||
|
|
||
|
from django.db import migrations
|
||
|
|
||
|
def oprav_prava_k_nastaveni(apps, schema_editor):
|
||
|
# Tohle je trošku hnus, nešlo by to snáz?
|
||
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||
|
Permission = apps.get_model('auth', 'Permission')
|
||
|
Group = apps.get_model('auth', 'Group')
|
||
|
old_ct = ContentType.objects.get_by_natural_key('seminar', 'nastaveni')
|
||
|
new_ct = ContentType.objects.get_by_natural_key('various', 'nastaveni')
|
||
|
old_perms = Permission.objects.filter(content_type=old_ct)
|
||
|
new_perms = Permission.objects.filter(content_type=new_ct)
|
||
|
for g in Group.objects.filter(permissions__in=old_perms):
|
||
|
old_codenames = Permission.objects.filter(group__in=[g], content_type=old_ct).values('codename')
|
||
|
g.permissions.add(*new_perms.filter(codename__in=old_codenames))
|
||
|
g.permissions.remove(*old_perms)
|
||
|
|
||
|
def obnov_prava_k_nastaveni(apps, schema_editor):
|
||
|
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||
|
Permission = apps.get_model('auth', 'Permission')
|
||
|
Group = apps.get_model('auth', 'Group')
|
||
|
old_ct = ContentType.objects.get_by_natural_key('seminar', 'nastaveni')
|
||
|
new_ct = ContentType.objects.get_by_natural_key('various', 'nastaveni')
|
||
|
old_perms = Permission.objects.filter(content_type=old_ct)
|
||
|
new_perms = Permission.objects.filter(content_type=new_ct)
|
||
|
for g in Group.objects.filter(permissions__in=old_perms):
|
||
|
new_codenames = Permission.objects.filter(group__in=[g], content_type=new_ct).values('codename')
|
||
|
g.permissions.add(*old_perms.filter(codename__in=new_codenames))
|
||
|
g.permissions.remove(*new_perms)
|
||
|
|
||
|
|
||
|
class Migration(migrations.Migration):
|
||
|
|
||
|
dependencies = [
|
||
|
('various', '0002_alter_nastaveni_options'),
|
||
|
]
|
||
|
|
||
|
operations = [
|
||
|
]
|