mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Organize funs
This commit is contained in:
parent
48c6f4a744
commit
5541435a30
10 changed files with 43 additions and 24 deletions
|
@ -8,7 +8,7 @@ from flask_sqlalchemy import SQLAlchemy
|
|||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from .independent_funs import parse_bool
|
||||
from .advlabdb_independent_funs import parse_bool
|
||||
|
||||
|
||||
def set_from_env(app, var):
|
||||
|
|
|
@ -31,6 +31,7 @@ from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
|
|||
from wtforms.widgets import NumberInput
|
||||
|
||||
from . import adminSpace, app, assistantSpace, db, user_datastore
|
||||
from .advlabdb_independent_funs import flashRandomPassword, randomPassword
|
||||
from .configUtils import getConfig
|
||||
from .customClasses import (
|
||||
CustomIdEndpointLinkRowAction,
|
||||
|
@ -38,15 +39,13 @@ from .customClasses import (
|
|||
SecureAdminModelView,
|
||||
)
|
||||
from .database_import import importFromFile
|
||||
from .dependent_funs import (
|
||||
flashRandomPassword,
|
||||
from .exceptions import DataBaseException, ModelViewException
|
||||
from .model_dependent_funs import (
|
||||
initActiveSemesterMenuLinks,
|
||||
setUserActiveSemester,
|
||||
sortedSemestersStartingWithNewest,
|
||||
userActiveSemester,
|
||||
)
|
||||
from .exceptions import DataBaseException, ModelViewException
|
||||
from .independent_funs import randomPassword
|
||||
from .models import (
|
||||
MAX_MARK,
|
||||
MAX_YEAR,
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
# Functions not dependent on advlabdb
|
||||
|
||||
from random import choice
|
||||
from string import ascii_letters, digits
|
||||
|
||||
from flask import flash
|
||||
|
||||
|
||||
def randomPassword():
|
||||
return "".join(choice(ascii_letters + digits) for i in range(15))
|
||||
|
||||
|
||||
def flashRandomPassword(password):
|
||||
flash(f"Random password: {password}", category="warning")
|
||||
|
||||
|
||||
def parse_bool(str):
|
||||
str_lower = str.lower()
|
||||
|
@ -10,7 +22,3 @@ def parse_bool(str):
|
|||
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(15))
|
|
@ -8,14 +8,10 @@ from wtforms.fields import DateField
|
|||
from wtforms.validators import NumberRange, Optional
|
||||
|
||||
from . import assistantSpace, db
|
||||
from .advlabdb_independent_funs import flashRandomPassword, randomPassword
|
||||
from .customClasses import SecureAssistantBaseView, SecureAssistantModelView
|
||||
from .dependent_funs import (
|
||||
flashRandomPassword,
|
||||
initActiveSemesterMenuLinks,
|
||||
userActiveSemester,
|
||||
)
|
||||
from .exceptions import DataBaseException, ModelViewException
|
||||
from .independent_funs import randomPassword
|
||||
from .model_dependent_funs import initActiveSemesterMenuLinks, userActiveSemester
|
||||
from .models import (
|
||||
MAX_MARK,
|
||||
MIN_MARK,
|
||||
|
|
|
@ -8,8 +8,9 @@ from flask_security import current_user
|
|||
from sqlalchemy import and_, select
|
||||
|
||||
from . import db
|
||||
from .dependent_funs import get_count, reportBadAttempt, userActiveSemester
|
||||
from .exceptions import DataBaseException, ModelViewException
|
||||
from .model_dependent_funs import userActiveSemester
|
||||
from .model_independent_funs import get_count, reportBadAttempt
|
||||
from .models import (
|
||||
Assistant,
|
||||
ExperimentMark,
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
# Functions dependent on advlabdb.models
|
||||
|
||||
from flask import flash, url_for
|
||||
from flask_admin.menu import MenuLink
|
||||
from flask_security import current_user
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy import select
|
||||
|
||||
from . import app, db
|
||||
from .models import Semester
|
||||
|
||||
|
||||
def flashRandomPassword(password):
|
||||
flash(f"Random password: {password}", category="warning")
|
||||
|
||||
|
||||
def sortedSemestersStartingWithNewest(limit=0):
|
||||
# Inserting an older semester is not allowed!
|
||||
# Therefore, the id is enough.
|
17
advlabdb/model_independent_funs.py
Normal file
17
advlabdb/model_independent_funs.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Functions not dependent on advlabdb.models
|
||||
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from . import db
|
||||
|
||||
|
||||
def reportBadAttempt(message):
|
||||
print("BAD ATTEMPT:", message) # TODO: Log
|
||||
|
||||
|
||||
def get_count(table):
|
||||
return db.session.scalar(select(func.count()).select_from(table))
|
||||
|
||||
|
||||
def get_first(table):
|
||||
return db.session.execute(table.limit(1)).scalars().first()
|
|
@ -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 . import app
|
||||
from .dependent_funs import setUserActiveSemester, userActiveSemester
|
||||
from .model_dependent_funs import setUserActiveSemester, userActiveSemester
|
||||
|
||||
|
||||
@app.context_processor
|
||||
|
|
|
@ -2,7 +2,7 @@ from flask_security import admin_change_password
|
|||
from sqlalchemy import select
|
||||
|
||||
from ... import app, db
|
||||
from ...independent_funs import randomPassword
|
||||
from ...advlabdb_independent_funs import randomPassword
|
||||
from ...models import Admin, User
|
||||
from ..terminal_utils import box, spaced_hl, validating_input
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from email_validator import validate_email
|
|||
from flask_security import hash_password
|
||||
|
||||
from ... import app, db, user_datastore
|
||||
from ...independent_funs import randomPassword
|
||||
from ...advlabdb_independent_funs import randomPassword
|
||||
from ...models import MAX_YEAR, MIN_YEAR, Admin, Semester
|
||||
from ..terminal_utils import box, confirm, validating_input
|
||||
|
||||
|
|
Loading…
Reference in a new issue