mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Split utils.py
This commit is contained in:
parent
3688bfc0ea
commit
11746b8c67
6 changed files with 32 additions and 23 deletions
|
@ -38,7 +38,15 @@ from advlabdb.customClasses import (
|
||||||
SecureAdminModelView,
|
SecureAdminModelView,
|
||||||
)
|
)
|
||||||
from advlabdb.database_import import importFromFile
|
from advlabdb.database_import import importFromFile
|
||||||
|
from advlabdb.dependent_funs import (
|
||||||
|
flashRandomPassword,
|
||||||
|
initActiveSemesterMenuLinks,
|
||||||
|
setUserActiveSemester,
|
||||||
|
sortedSemestersStartingWithNewest,
|
||||||
|
userActiveSemester,
|
||||||
|
)
|
||||||
from advlabdb.exceptions import DataBaseException, ModelViewException
|
from advlabdb.exceptions import DataBaseException, ModelViewException
|
||||||
|
from advlabdb.independent_funs import randomPassword
|
||||||
from advlabdb.models import (
|
from advlabdb.models import (
|
||||||
MAX_MARK,
|
MAX_MARK,
|
||||||
MIN_MARK,
|
MIN_MARK,
|
||||||
|
@ -58,14 +66,6 @@ from advlabdb.models import (
|
||||||
Student,
|
Student,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
from advlabdb.utils import (
|
|
||||||
flashRandomPassword,
|
|
||||||
initActiveSemesterMenuLinks,
|
|
||||||
randomPassword,
|
|
||||||
setUserActiveSemester,
|
|
||||||
sortedSemestersStartingWithNewest,
|
|
||||||
userActiveSemester,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def semesterExperimentQueryFactory():
|
def semesterExperimentQueryFactory():
|
||||||
|
|
|
@ -9,7 +9,13 @@ from wtforms.validators import NumberRange
|
||||||
|
|
||||||
from advlabdb import assistantSpace, db
|
from advlabdb import assistantSpace, db
|
||||||
from advlabdb.customClasses import SecureAssistantBaseView, SecureAssistantModelView
|
from advlabdb.customClasses import SecureAssistantBaseView, SecureAssistantModelView
|
||||||
|
from advlabdb.dependent_funs import (
|
||||||
|
flashRandomPassword,
|
||||||
|
initActiveSemesterMenuLinks,
|
||||||
|
userActiveSemester,
|
||||||
|
)
|
||||||
from advlabdb.exceptions import DataBaseException, ModelViewException
|
from advlabdb.exceptions import DataBaseException, ModelViewException
|
||||||
|
from advlabdb.independent_funs import randomPassword
|
||||||
from advlabdb.models import (
|
from advlabdb.models import (
|
||||||
MAX_MARK,
|
MAX_MARK,
|
||||||
MIN_MARK,
|
MIN_MARK,
|
||||||
|
@ -28,12 +34,6 @@ from advlabdb.models import (
|
||||||
Student,
|
Student,
|
||||||
User,
|
User,
|
||||||
)
|
)
|
||||||
from advlabdb.utils import (
|
|
||||||
flashRandomPassword,
|
|
||||||
initActiveSemesterMenuLinks,
|
|
||||||
randomPassword,
|
|
||||||
userActiveSemester,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AssistantAppointmentView(SecureAssistantModelView):
|
class AssistantAppointmentView(SecureAssistantModelView):
|
||||||
|
|
|
@ -6,6 +6,7 @@ from flask_admin.model.template import EndpointLinkRowAction
|
||||||
from flask_security import current_user
|
from flask_security import current_user
|
||||||
from sqlalchemy import and_
|
from sqlalchemy import and_
|
||||||
|
|
||||||
|
from advlabdb.dependent_funs import reportBadAttempt, userActiveSemester
|
||||||
from advlabdb.exceptions import DataBaseException, ModelViewException
|
from advlabdb.exceptions import DataBaseException, ModelViewException
|
||||||
from advlabdb.models import (
|
from advlabdb.models import (
|
||||||
Assistant,
|
Assistant,
|
||||||
|
@ -15,7 +16,6 @@ from advlabdb.models import (
|
||||||
PartStudent,
|
PartStudent,
|
||||||
SemesterExperiment,
|
SemesterExperiment,
|
||||||
)
|
)
|
||||||
from advlabdb.utils import reportBadAttempt, userActiveSemester
|
|
||||||
|
|
||||||
|
|
||||||
def adminViewIsAccessible():
|
def adminViewIsAccessible():
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
from random import choice
|
|
||||||
from string import ascii_letters, digits
|
|
||||||
|
|
||||||
from flask import flash, url_for
|
from flask import flash, url_for
|
||||||
from flask_admin.menu import MenuLink
|
from flask_admin.menu import MenuLink
|
||||||
from flask_security import current_user
|
from flask_security import current_user
|
||||||
|
@ -9,10 +6,6 @@ from advlabdb import app, db
|
||||||
from advlabdb.models import Semester
|
from advlabdb.models import Semester
|
||||||
|
|
||||||
|
|
||||||
def randomPassword():
|
|
||||||
return "".join(choice(ascii_letters + digits) for i in range(12))
|
|
||||||
|
|
||||||
|
|
||||||
def flashRandomPassword(password):
|
def flashRandomPassword(password):
|
||||||
flash(f"Random password: {password}", category="warning")
|
flash(f"Random password: {password}", category="warning")
|
||||||
|
|
16
advlabdb/independent_funs.py
Normal file
16
advlabdb/independent_funs.py
Normal file
|
@ -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))
|
|
@ -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 flask_security import auth_required, current_user, roles_accepted, roles_required
|
||||||
|
|
||||||
from advlabdb import app
|
from advlabdb import app
|
||||||
from advlabdb.utils import setUserActiveSemester, userActiveSemester
|
from advlabdb.dependent_funs import setUserActiveSemester, userActiveSemester
|
||||||
|
|
||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
|
|
Loading…
Reference in a new issue