From 31c22846f6549ee7a5f678759cbcb08ad65a02f1 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Thu, 4 Oct 2018 22:15:36 +0200 Subject: [PATCH] Added DEFAULT_SCHOOL_ID The DEFAULT_SCHOOL_ID is used as long as we have only one school. That simplifies some code for now. --- server/user/models.py | 8 +++++--- server/user/services.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/server/user/models.py b/server/user/models.py index 96027305..a6e86ba9 100644 --- a/server/user/models.py +++ b/server/user/models.py @@ -6,6 +6,8 @@ from django.db import models from django.db.models import Q from django.utils.translation import ugettext_lazy as _ +DEFAULT_SCHOOL_ID = 1 + class User(AbstractUser): def get_school_permissions(self, school): @@ -23,15 +25,15 @@ class User(AbstractUser): :return: django permissions and school permissions for single default school """ django_permissions = super().get_all_permissions(obj) - return django_permissions.union(self.get_school_permissions(School.objects.get(pk=1))) + return django_permissions.union(self.get_school_permissions(School.objects.get(pk=DEFAULT_SCHOOL_ID))) class School(models.Model): name = models.CharField(_(u'Name'), max_length=100, null=False, blank=False) @classmethod - def create_school(cls, name): - school = School(name=name) + def create_school(cls, name, id=None): + school = School(name=name, id=id) school.save() # Label.create_labels_for_school(school) SchoolRole.objects.create_default_roles_for_school(school) diff --git a/server/user/services.py b/server/user/services.py index 924c26cc..bc5403b9 100644 --- a/server/user/services.py +++ b/server/user/services.py @@ -1,10 +1,10 @@ from core.factories import UserFactory from user.factories import UserGroupFactory -from user.models import School, SchoolRole, UserSchoolRole +from user.models import School, SchoolRole, UserSchoolRole, DEFAULT_SCHOOL_ID def create_school_with_users(school_name): - school = School.create_school(school_name) + school = School.create_school(school_name, id=DEFAULT_SCHOOL_ID) teacher_role = SchoolRole.objects.get_default_teacher_role_for_school(school) teacher = UserFactory(username='teacher')