From 029cc974e3878573bc86985f4f6cdee7692bbb13 Mon Sep 17 00:00:00 2001 From: mo8it Date: Thu, 2 Nov 2023 19:24:14 +0100 Subject: [PATCH] Apply RET --- advlabdb/adminModelViews.py | 15 ++++++++------- advlabdb/config.py | 6 ++---- advlabdb/custom_classes.py | 2 ++ advlabdb/models.py | 6 +++--- pyproject.toml | 3 ++- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index 33441f6..dbcbfa8 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -323,16 +323,16 @@ class SemesterView(SecureAdminModelView): last_semester = Semester.lastSemester() if last_semester.label == "WS": return "SS" - else: - return "WS" + + return "WS" @staticmethod def defaultFormYear(): last_semester = Semester.lastSemester() if last_semester.label == "WS": return last_semester.year + 1 - else: - return last_semester.year + + return last_semester.year label = RadioField( "Semester", @@ -857,8 +857,8 @@ def userHasRoleFilterFactory(column, role_name): query = query.join(User) if bool(int(value)): # value is string "0" or "1" return query.join(User.roles).where(Role.name == role_name) - else: - return query.where(not_(User.roles.any(Role.name == role_name))) + + return query.where(not_(User.roles.any(Role.name == role_name))) return UserHasRoleFilter(column, f"Currently has {role_name} role") @@ -1392,7 +1392,8 @@ class AnalysisView(SecureAdminBaseView): if form.validate_on_submit(): if form.assistant_marks_submit.data: return assistant_marks_analysis(self) - elif form.final_part_marks_submit.data: + + if form.final_part_marks_submit.data: return final_part_marks_analysis(self) return self.render("analysis/analysis.jinja.html", form=form) diff --git a/advlabdb/config.py b/advlabdb/config.py index 4dca911..c498382 100644 --- a/advlabdb/config.py +++ b/advlabdb/config.py @@ -34,16 +34,14 @@ def load_config(file_name: str, data_dir: Path): def get_secrets(data_dir: Path): config = load_config("secrets.ini", data_dir) - secrets = config["Secrets"] - return secrets + return config["Secrets"] def get_settings(data_dir: Path): config = load_config("settings.ini", data_dir) - settings = config["Settings"] - return settings + return config["Settings"] def set_config(app, data_dir: Path): diff --git a/advlabdb/custom_classes.py b/advlabdb/custom_classes.py index e03ed77..a707371 100644 --- a/advlabdb/custom_classes.py +++ b/advlabdb/custom_classes.py @@ -280,6 +280,8 @@ class SecureAssistantModelView(CustomModelView): self.handle_view_exception(ModelViewException("Unauthorized action!")) return redirect(self.url) + return None + def on_model_delete(self, model): reportBadAttempt("An assistant tried to delete a model!") raise ModelViewException("Assistants can not delete models!") diff --git a/advlabdb/models.py b/advlabdb/models.py index 8c8e356..ee8ca59 100644 --- a/advlabdb/models.py +++ b/advlabdb/models.py @@ -657,9 +657,9 @@ class ExperimentMark(db.Model): def check(part_student, group_experiment): if not part_student.group: raise DatabaseException("The part student does not have a group yet!") - else: - if group_experiment not in part_student.group.group_experiments: - raise DatabaseException("The group of the part student does not have the given group experiment!") + + if group_experiment not in part_student.group.group_experiments: + raise DatabaseException("The group of the part student does not have the given group experiment!") def __init__(self, part_student, group_experiment, **kwargs): ExperimentMark.check(part_student, group_experiment) diff --git a/pyproject.toml b/pyproject.toml index f86bfe2..2b9e371 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,8 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.ruff] -select = ["E1", "E4", "E7", "E9", "W", "F", "I", "UP", "YTT", "S1", "S5", "S7", "B", "C4"] +select = ["E", "W", "F", "I", "UP", "YTT", "S", "B", "C4", "ICN", "PIE", "Q", "RET"] +ignore = ["E5", "S3", "S6", "RET504"] line-length = 120 [tool.ruff.per-file-ignores]