From 2da2a67b944fc86ca1e15c95521f9a179f34dcec Mon Sep 17 00:00:00 2001 From: Mo8it Date: Wed, 1 Jun 2022 23:02:17 +0200 Subject: [PATCH] Apply str instead of repr --- advlabdb/adminModelViews.py | 26 ++++++++++++-------------- advlabdb/database_import.py | 8 ++++---- advlabdb/model_dependent_funs.py | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index 8dda622..b7f6c82 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -73,7 +73,7 @@ class SemesterRowFilter(FilterEqual): return tuple() semesters = Semester.sortedSemestersStartingWithNewest() - return tuple((semester.id, semester.repr()) for semester in semesters) + return tuple((semester.id, str(semester)) for semester in semesters) class UserView(SecureAdminModelView): @@ -327,7 +327,7 @@ class SemesterView(SecureAdminModelView): def addMenuLink(space, newSemester): categoryText = "Active semester" link = MenuLink( - name=newSemester.repr(), + name=str(newSemester), url=url_for("set_semester") + "?semester_id=" + str(newSemester.id), category=categoryText, ) @@ -447,7 +447,7 @@ class PartRowFilter(FilterEqual): return tuple() parts = db.session.execute(select(Part).where(Part.semester == current_user.active_semester)).scalars() - return tuple((part.id, f"{part.program.repr()}{part.number}") for part in parts) + return tuple((part.id, part.str_without_semester()) for part in parts) class PartStudentView(SecureAdminModelView): @@ -543,7 +543,7 @@ class ProgramRowFilter(FilterEqual): return tuple() programs = db.session.execute(select(Program)).scalars() - return tuple((program.id, program.repr()) for program in programs) + return tuple((program.id, str(program)) for program in programs) class GroupView(SecureAdminModelView): @@ -801,8 +801,7 @@ class AssistantView(SecureAdminModelView): can_view_details = True column_list = [ - "user.first_name", - "user.last_name", + "user", "semester_experiments", ] column_details_list = column_list + [ @@ -864,8 +863,7 @@ class AdminView(SecureAdminModelView): can_delete = False column_list = [ - "user.first_name", - "user.last_name", + "user", ] column_filters = ( userHasRoleFilterFactory(Admin, "admin"), @@ -893,7 +891,7 @@ class ExperimentRowFilter(FilterEqual): return tuple( ( f"{activeExperiment.number},{activeExperiment.program_id}", - f"{activeExperiment.number} {activeExperiment.program.repr()}", + f"{activeExperiment.number} {activeExperiment.program}", ) for activeExperiment in activeExperiments ) @@ -1032,7 +1030,7 @@ class AssistantRowFilter(FilterEqual): return tuple() activeAssistants = assistantQueryFactory() - return tuple((assistant.id, assistant.repr()) for assistant in activeAssistants) + return tuple((assistant.id, str(assistant)) for assistant in activeAssistants) class AppointmentView(SecureAdminModelView): @@ -1166,7 +1164,7 @@ class ExperimentMarkView(SecureAdminModelView): return tuple() admins = db.session.execute(select(Admin).join(User).where(User.active == True)).scalars() - return tuple((admin.id, admin.repr()) for admin in admins) + return tuple((admin.id, str(admin)) for admin in admins) def apply(self, query, value, alias=None): return query.where(ExperimentMark.admin_id == int(value)) @@ -1440,7 +1438,7 @@ class AnalysisView(SecureAdminBaseView): hists = [ AnalysisView.markHist( data=marks[i], - title=activeAssistants[i].repr() + markTypeTitleAddition, + title=str(activeAssistants[i]) + markTypeTitleAddition, ) for i in range(len(marks)) ] @@ -1486,13 +1484,13 @@ class AnalysisView(SecureAdminBaseView): activeSemesterFinalPartMarksHists = [ AnalysisView.markHist( data=AnalysisView.get_final_part_marks(part), - title=part.repr(), + title=str(part), ) for part in parts ] semesters = Semester.sortedSemestersStartingWithNewest() - semesterLabels = [semester.repr() for semester in semesters] + semesterLabels = [str(semester) for semester in semesters] meanFinalPartMarks = np.flip( [ np.mean( diff --git a/advlabdb/database_import.py b/advlabdb/database_import.py index 598d864..7288a36 100644 --- a/advlabdb/database_import.py +++ b/advlabdb/database_import.py @@ -251,7 +251,7 @@ def importFromFile(filePath): if dbExperiment is None: # TODO: Check if experimentProgram is None raise DataBaseImportException( - f"Experiment with number {experimentNumber} and program {experimentProgram.repr()} does not exist in the database. Please make sure that experiments are created from the web interface." + f"Experiment with number {experimentNumber} and program {experimentProgram} does not exist in the database. Please make sure that experiments are created from the web interface." ) dbSemesterExperiment = get_first( @@ -262,7 +262,7 @@ def importFromFile(filePath): if dbSemesterExperiment is None: raise DataBaseImportException( - f"No semester experiment exists in the database to the experiment with number {experimentNumber} and program {experimentProgram.repr()}. Please make sure that semester experiments are created in the web interface. The problem might be that the experiment was not active while creating a new semester" + f"No semester experiment exists in the database to the experiment with number {experimentNumber} and program {experimentProgram}. Please make sure that semester experiments are created in the web interface. The problem might be that the experiment was not active while creating a new semester" ) dbSemesterExperiments[id] = dbSemesterExperiment @@ -302,7 +302,7 @@ def importFromFile(filePath): db.session.add(dbAppointment) # Backup - dest = relative_db_bk_dir / f"before_{dbSemester.repr()}_import_{now()}.db" + dest = relative_db_bk_dir / f"before_{dbSemester}_import_{now()}.db" copy2(relative_db_path, dest) show(f"Made a backup of the database before commiting the import at {dest}") @@ -313,7 +313,7 @@ def importFromFile(filePath): raise ex - dest = relative_db_bk_dir / f"after_{dbSemester.repr()}_import_{now()}.db" + dest = relative_db_bk_dir / f"after_{dbSemester}_import_{now()}.db" copy2(relative_db_path, dest) show(f"Made a backup of the database after the import at {dest}") diff --git a/advlabdb/model_dependent_funs.py b/advlabdb/model_dependent_funs.py index a49e65d..a2fa9ed 100644 --- a/advlabdb/model_dependent_funs.py +++ b/advlabdb/model_dependent_funs.py @@ -16,7 +16,7 @@ def initActiveSemesterMenuLinks(space): for semester in semesters: space.add_link( MenuLink( - name=semester.repr(), + name=str(semester), url=url_for("set_semester") + "?semester_id=" + str(semester.id), category="Active semester", )