diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index 4fd9a67..bcb1c4d 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -38,7 +38,15 @@ from advlabdb.customClasses import ( SecureAdminModelView, ) from advlabdb.database_import import importFromFile +from advlabdb.dependent_funs import ( + flashRandomPassword, + initActiveSemesterMenuLinks, + setUserActiveSemester, + sortedSemestersStartingWithNewest, + userActiveSemester, +) from advlabdb.exceptions import DataBaseException, ModelViewException +from advlabdb.independent_funs import randomPassword from advlabdb.models import ( MAX_MARK, MIN_MARK, @@ -58,14 +66,6 @@ from advlabdb.models import ( Student, User, ) -from advlabdb.utils import ( - flashRandomPassword, - initActiveSemesterMenuLinks, - randomPassword, - setUserActiveSemester, - sortedSemestersStartingWithNewest, - userActiveSemester, -) def semesterExperimentQueryFactory(): diff --git a/advlabdb/assistantModelViews.py b/advlabdb/assistantModelViews.py index e49a0f2..f695c5b 100644 --- a/advlabdb/assistantModelViews.py +++ b/advlabdb/assistantModelViews.py @@ -9,7 +9,13 @@ from wtforms.validators import NumberRange from advlabdb import assistantSpace, db from advlabdb.customClasses import SecureAssistantBaseView, SecureAssistantModelView +from advlabdb.dependent_funs import ( + flashRandomPassword, + initActiveSemesterMenuLinks, + userActiveSemester, +) from advlabdb.exceptions import DataBaseException, ModelViewException +from advlabdb.independent_funs import randomPassword from advlabdb.models import ( MAX_MARK, MIN_MARK, @@ -28,12 +34,6 @@ from advlabdb.models import ( Student, User, ) -from advlabdb.utils import ( - flashRandomPassword, - initActiveSemesterMenuLinks, - randomPassword, - userActiveSemester, -) class AssistantAppointmentView(SecureAssistantModelView): diff --git a/advlabdb/customClasses.py b/advlabdb/customClasses.py index 04d977b..e35a89f 100644 --- a/advlabdb/customClasses.py +++ b/advlabdb/customClasses.py @@ -6,6 +6,7 @@ from flask_admin.model.template import EndpointLinkRowAction from flask_security import current_user from sqlalchemy import and_ +from advlabdb.dependent_funs import reportBadAttempt, userActiveSemester from advlabdb.exceptions import DataBaseException, ModelViewException from advlabdb.models import ( Assistant, @@ -15,7 +16,6 @@ from advlabdb.models import ( PartStudent, SemesterExperiment, ) -from advlabdb.utils import reportBadAttempt, userActiveSemester def adminViewIsAccessible(): diff --git a/advlabdb/utils.py b/advlabdb/dependent_funs.py similarity index 93% rename from advlabdb/utils.py rename to advlabdb/dependent_funs.py index d21ed23..75ac4c6 100644 --- a/advlabdb/utils.py +++ b/advlabdb/dependent_funs.py @@ -1,6 +1,3 @@ -from random import choice -from string import ascii_letters, digits - from flask import flash, url_for from flask_admin.menu import MenuLink from flask_security import current_user @@ -9,10 +6,6 @@ from advlabdb import app, db from advlabdb.models import Semester -def randomPassword(): - return "".join(choice(ascii_letters + digits) for i in range(12)) - - def flashRandomPassword(password): flash(f"Random password: {password}", category="warning") diff --git a/advlabdb/independent_funs.py b/advlabdb/independent_funs.py new file mode 100644 index 0000000..61a62cc --- /dev/null +++ b/advlabdb/independent_funs.py @@ -0,0 +1,16 @@ +from random import choice +from string import ascii_letters, digits + + +def parse_bool(str): + str_lower = str.lower() + if str_lower == "false": + return False + elif str_lower == "true": + return True + else: + raise (ValueError(f'Can not parse a bool from "{str}"')) + + +def randomPassword(): + return "".join(choice(ascii_letters + digits) for i in range(12)) diff --git a/advlabdb/routes.py b/advlabdb/routes.py index a093b62..8291b33 100644 --- a/advlabdb/routes.py +++ b/advlabdb/routes.py @@ -2,7 +2,7 @@ from flask import flash, redirect, render_template, request, url_for from flask_security import auth_required, current_user, roles_accepted, roles_required from advlabdb import app -from advlabdb.utils import setUserActiveSemester, userActiveSemester +from advlabdb.dependent_funs import setUserActiveSemester, userActiveSemester @app.context_processor