Loading Pipfile +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ flask-restplus = "*" celery = {extras = ["auth", "yaml", "msgpack", "redis"]} python-ldap = "*" mockredispy = "*" python-slugify = "*" [dev-packages] pylint = "*" Loading portal/database/mixins.py +6 −3 Original line number Diff line number Diff line Loading @@ -23,8 +23,8 @@ class EntityBase(object): class NamedMixin(object): _name = db.Column('name', db.String(50), required=True) _codename = db.Column('codename', db.String(25), required=True) _name = db.Column('name', db.String(50), nullable=False) _codename = db.Column('codename', db.String(25), nullable=False) description = db.Column(db.Text) @hybrid_property Loading @@ -33,7 +33,10 @@ class NamedMixin(object): @codename.setter def codename(self, value): if value: self._codename = gen_code_name(value) if self._name is None: self._name = self._codename @hybrid_property def name(self): Loading portal/database/models.py +1 −8 Original line number Diff line number Diff line Loading @@ -394,14 +394,6 @@ class Project(db.Model, EntityBase, NamedMixin): db.UniqueConstraint('course_id', 'codename', name='p_course_unique_name'), ) @hybrid_property def codename(self): return self._codename @codename.setter def codename(self, value): self._codename = value def state(self, timestamp=time.current_time()) -> ProjectState: """Gets project state based on the timestamp Args: Loading Loading @@ -460,6 +452,7 @@ class Project(db.Model, EntityBase, NamedMixin): self.codename = codename self.description = description self.assignment_url = assignment_url self.config = ProjectConfig(project=self) def __repr__(self): return _repr(self) Loading portal/rest/schemas.py +4 −3 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ class NestedCollection: def __init__(self, mod_name): self.mod_name = mod_name self.collection = {} self.__build_nested() def class_path(self, schema_name: str): return f'{self.mod_name}.{schema_name}Schema' Loading @@ -26,7 +27,7 @@ class NestedCollection: def _set_nested(self, schema_name: str, params, many=False): lower = schema_name.lower() if many: lower = schema_name + 's' lower = lower + 's' self.collection[lower] = self.nested(schema_name, params, many=False) def _set_nested_and_list(self, schema_name, params): Loading @@ -34,7 +35,7 @@ class NestedCollection: self._set_nested(schema_name=schema_name, params=params, many=True) def __build_nested(self): for (name, params) in self.entities: for (name, params) in self.entities.items(): self._set_nested_and_list(name, params=params) @property Loading Loading @@ -377,7 +378,7 @@ course_import_schema = CourseImportSchema(strict=True) group_schema = GroupSchema(strict=True) groups_schema = GroupSchema(many=True, only=(*CODENAME_W_DESC, 'course')) project_schema = ProjectSchema(strict=True) projects_schema = ProjectSchema(many=True, only=(CODENAME_W_DESC, 'course')) projects_schema = ProjectSchema(many=True, only=(*CODENAME_W_DESC, 'course')) config_schema = ProjectConfigSchema() config_schema_reduced = ProjectConfigSchema(only=('id', 'project', 'submissions_allowed_from', 'submissions_allowed_to', 'file_whitelist')) Loading portal/tools/naming.py +1 −12 Original line number Diff line number Diff line import re from unicodedata import normalize def slugify(string): name = normalize('NFKD', string).encode('ascii', 'ignore').replace(' ', '-').lower() # remove `other` characters name = re.sub('[^a-zA-Z0-9_-]', '', name) # nomalize dashes name = re.sub('-+', '-', name) return name from slugify import slugify def gen_code_name(string: str, max_len: int = 25) -> str: Loading Loading
Pipfile +1 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ flask-restplus = "*" celery = {extras = ["auth", "yaml", "msgpack", "redis"]} python-ldap = "*" mockredispy = "*" python-slugify = "*" [dev-packages] pylint = "*" Loading
portal/database/mixins.py +6 −3 Original line number Diff line number Diff line Loading @@ -23,8 +23,8 @@ class EntityBase(object): class NamedMixin(object): _name = db.Column('name', db.String(50), required=True) _codename = db.Column('codename', db.String(25), required=True) _name = db.Column('name', db.String(50), nullable=False) _codename = db.Column('codename', db.String(25), nullable=False) description = db.Column(db.Text) @hybrid_property Loading @@ -33,7 +33,10 @@ class NamedMixin(object): @codename.setter def codename(self, value): if value: self._codename = gen_code_name(value) if self._name is None: self._name = self._codename @hybrid_property def name(self): Loading
portal/database/models.py +1 −8 Original line number Diff line number Diff line Loading @@ -394,14 +394,6 @@ class Project(db.Model, EntityBase, NamedMixin): db.UniqueConstraint('course_id', 'codename', name='p_course_unique_name'), ) @hybrid_property def codename(self): return self._codename @codename.setter def codename(self, value): self._codename = value def state(self, timestamp=time.current_time()) -> ProjectState: """Gets project state based on the timestamp Args: Loading Loading @@ -460,6 +452,7 @@ class Project(db.Model, EntityBase, NamedMixin): self.codename = codename self.description = description self.assignment_url = assignment_url self.config = ProjectConfig(project=self) def __repr__(self): return _repr(self) Loading
portal/rest/schemas.py +4 −3 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ class NestedCollection: def __init__(self, mod_name): self.mod_name = mod_name self.collection = {} self.__build_nested() def class_path(self, schema_name: str): return f'{self.mod_name}.{schema_name}Schema' Loading @@ -26,7 +27,7 @@ class NestedCollection: def _set_nested(self, schema_name: str, params, many=False): lower = schema_name.lower() if many: lower = schema_name + 's' lower = lower + 's' self.collection[lower] = self.nested(schema_name, params, many=False) def _set_nested_and_list(self, schema_name, params): Loading @@ -34,7 +35,7 @@ class NestedCollection: self._set_nested(schema_name=schema_name, params=params, many=True) def __build_nested(self): for (name, params) in self.entities: for (name, params) in self.entities.items(): self._set_nested_and_list(name, params=params) @property Loading Loading @@ -377,7 +378,7 @@ course_import_schema = CourseImportSchema(strict=True) group_schema = GroupSchema(strict=True) groups_schema = GroupSchema(many=True, only=(*CODENAME_W_DESC, 'course')) project_schema = ProjectSchema(strict=True) projects_schema = ProjectSchema(many=True, only=(CODENAME_W_DESC, 'course')) projects_schema = ProjectSchema(many=True, only=(*CODENAME_W_DESC, 'course')) config_schema = ProjectConfigSchema() config_schema_reduced = ProjectConfigSchema(only=('id', 'project', 'submissions_allowed_from', 'submissions_allowed_to', 'file_whitelist')) Loading
portal/tools/naming.py +1 −12 Original line number Diff line number Diff line import re from unicodedata import normalize def slugify(string): name = normalize('NFKD', string).encode('ascii', 'ignore').replace(' ', '-').lower() # remove `other` characters name = re.sub('[^a-zA-Z0-9_-]', '', name) # nomalize dashes name = re.sub('-+', '-', name) return name from slugify import slugify def gen_code_name(string: str, max_len: int = 25) -> str: Loading