Update data migration

This commit is contained in:
Ramon Wenger 2021-08-31 13:28:37 +02:00
parent 84b646ed0a
commit da7adcbb4c
2 changed files with 10 additions and 7 deletions

View File

@ -9,7 +9,7 @@ def set_default_school_class(apps, schema_editor):
bulk_projects = []
for project in projects:
owner = project.student
selected_class = owner.selected_class
selected_class = owner._get_selected_class()
if selected_class is not None:
project.school_class = selected_class
bulk_projects.append(project)

View File

@ -1,20 +1,20 @@
import random
import re
from datetime import datetime, timedelta, date
import string
from datetime import date, datetime, timedelta
from typing import Union
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AbstractUser, Permission
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.utils.functional import cached_property
from django.utils.timezone import make_aware, is_aware
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from typing import Union
from django.utils.functional import cached_property
from django.utils.timezone import is_aware, make_aware
from django.utils.translation import ugettext_lazy as _
from users.licenses import MYSKILLBOX_LICENSES
from users.managers import RoleManager, UserRoleManager, UserManager, LicenseManager
from users.managers import LicenseManager, RoleManager, UserManager, UserRoleManager
DEFAULT_SCHOOL_ID = 1
@ -79,6 +79,9 @@ class User(AbstractUser):
@cached_property
def selected_class(self) -> Union['SchoolClass', None]:
return self._get_selected_class()
def _get_selected_class(self) -> Union['SchoolClass', None]:
try:
settings = UserSetting.objects.get(user=self)
return settings.selected_class