From 8301cbdb4d9d9b0bbb8a68d859be1178886a5a61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Thu, 10 Aug 2023 15:41:29 +0200 Subject: [PATCH] =?UTF-8?q?U=C5=BE=20nebude=20pot=C5=99eba=20(pak=20to=20u?= =?UTF-8?q?d=C4=9Bl=C3=A1m=20pomoc=C3=AD=20loaddata)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/load_org_permissions.py | 31 ------------------- .../commands/save_org_permissions.py | 21 ------------- 2 files changed, 52 deletions(-) delete mode 100644 seminar/management/commands/load_org_permissions.py delete mode 100644 seminar/management/commands/save_org_permissions.py diff --git a/seminar/management/commands/load_org_permissions.py b/seminar/management/commands/load_org_permissions.py deleted file mode 100644 index 15e00429..00000000 --- a/seminar/management/commands/load_org_permissions.py +++ /dev/null @@ -1,31 +0,0 @@ - -from django.core.management.base import BaseCommand -from django.contrib.sessions.models import Session -from django.contrib.auth.models import Group, Permission -from django.contrib.contenttypes.models import ContentType -from django.core.exceptions import ObjectDoesNotExist -import json -import argparse - -class Command(BaseCommand): - """ - - """ - def add_arguments(self, parser): - parser.add_argument('file', nargs=1, type=argparse.FileType('r', encoding='utf8')) - - - def handle(self, *args, **options): - try: - orgroup = Group.objects.get(name='org') - except ObjectDoesNotExist: - orgroup = Group(name='org') - orgroup.save() - permissions = json.load(options['file'][0]) - orgroup.permissions.clear() - for jp in permissions: - ct = ContentType.objects.get(app_label = jp['ct_app_label'], model = jp['ct_model']) - perm = Permission.objects.get(content_type = ct, codename = jp['codename']) - orgroup.permissions.add(perm) - orgroup.save() - diff --git a/seminar/management/commands/save_org_permissions.py b/seminar/management/commands/save_org_permissions.py deleted file mode 100644 index 023c4bd1..00000000 --- a/seminar/management/commands/save_org_permissions.py +++ /dev/null @@ -1,21 +0,0 @@ - -from django.core.management.base import BaseCommand -from django.contrib.sessions.models import Session -from django.contrib.auth.models import Group, Permission -import json - -class Command(BaseCommand): - """ - Dump permissions for group 'org' such that them can be used on an other machine. - - """ - def handle(self, *args, **options): - orgroup = Group.objects.get(name='org') - permissions = [] - for p in orgroup.permissions.all(): - permissions.append({ - 'codename': p.codename, - 'ct_app_label': p.content_type.app_label, - 'ct_model': p.content_type.model}) - print(json.dumps(permissions)) -