Bugfix - když skupina 'org' neexistuje, přidej ji.
This commit is contained in:
parent
97ae472d2e
commit
4284cbd35c
1 changed files with 6 additions and 1 deletions
|
@ -4,6 +4,7 @@ from django.core.management.base import BaseCommand
|
||||||
from django.contrib.sessions.models import Session
|
from django.contrib.sessions.models import Session
|
||||||
from django.contrib.auth.models import Group, Permission
|
from django.contrib.auth.models import Group, Permission
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
@ -16,7 +17,11 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
orgroup = Group.objects.get(name='org')
|
try:
|
||||||
|
orgroup = Group.objects.get(name='org')
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
orgroup = Group(name='org')
|
||||||
|
orgroup.save()
|
||||||
permissions = json.load(options['file'][0])
|
permissions = json.load(options['file'][0])
|
||||||
orgroup.permissions.clear()
|
orgroup.permissions.clear()
|
||||||
for jp in permissions:
|
for jp in permissions:
|
||||||
|
|
Loading…
Reference in a new issue