Verified Commit 93895747 authored by Peter Stanko's avatar Peter Stanko
Browse files

Fix when course state is None

parent 5ece2f58
Pipeline #31395 passed with stage
in 7 minutes and 26 seconds
import logging
from datetime import datetime from datetime import datetime
from typing import Dict, List from typing import Dict, List
import marshmallow import marshmallow
from portal.database import Course, Group, Project, Role from portal.database import Course, Group, Project, Role
from portal.database.enums import CourseState from portal.database.enums import CourseState
from portal.service.general import GeneralService from portal.service.general import GeneralService
log = logging.getLogger(__name__)
class ResourceDefinitionService(GeneralService): class ResourceDefinitionService(GeneralService):
def sync_course(self, definition: Dict, save: bool = True): def sync_course(self, definition: Dict, save: bool = True):
...@@ -17,7 +21,11 @@ class ResourceDefinitionService(GeneralService): ...@@ -17,7 +21,11 @@ class ResourceDefinitionService(GeneralService):
""" """
definition = definition.get('course') or definition definition = definition.get('course') or definition
if 'state' in definition: if 'state' in definition:
definition['state'] = CourseState(definition['state']) try:
definition['state'] = CourseState(definition['state'])
except Exception as ex:
log.error(f"State error: {ex}")
course = self._get_course(definition['codename']) course = self._get_course(definition['codename'])
params = self._course_params params = self._course_params
...@@ -129,7 +137,7 @@ class ResourceDefinitionService(GeneralService): ...@@ -129,7 +137,7 @@ class ResourceDefinitionService(GeneralService):
Returns(Dict): Course dump Returns(Dict): Course dump
""" """
schema = _extract_params(course, self._course_params) schema = _extract_params(course, self._course_params)
schema['state'] = course.state.value schema['state'] = course.state.value if course.state else None
schema['projects'] = [self.dump_project(project) for project in course.projects] schema['projects'] = [self.dump_project(project) for project in course.projects]
schema['roles'] = [self.dump_role(role, with_clients=with_users) for role in course.roles] schema['roles'] = [self.dump_role(role, with_clients=with_users) for role in course.roles]
schema['groups'] = [ schema['groups'] = [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment