1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

Use relative imports

This commit is contained in:
Mo 2022-05-08 21:26:25 +02:00
parent 11602ec39a
commit 11fb5f5428
21 changed files with 52 additions and 58 deletions

View file

@ -8,7 +8,7 @@ from flask_sqlalchemy import SQLAlchemy
from dotenv import load_dotenv from dotenv import load_dotenv
from advlabdb.independent_funs import parse_bool from .independent_funs import parse_bool
def set_from_env(app, var): def set_from_env(app, var):
@ -39,7 +39,7 @@ db = SQLAlchemy(app)
fsqla.FsModels.set_db_info(db) fsqla.FsModels.set_db_info(db)
from advlabdb import customClasses from . import customClasses
adminSpace = Admin( adminSpace = Admin(
app, app,
@ -58,14 +58,14 @@ assistantSpace = Admin(
index_view=customClasses.SecureAssistantIndexView(name="Assistant", url="/assistant", endpoint="assistantSpace"), index_view=customClasses.SecureAssistantIndexView(name="Assistant", url="/assistant", endpoint="assistantSpace"),
) )
from advlabdb import models from . import models
# Setup Flask-Security # Setup Flask-Security
user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role) user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role)
Security(app, user_datastore) Security(app, user_datastore)
try: try:
from advlabdb import routes, adminModelViews, assistantModelViews from . import routes, adminModelViews, assistantModelViews
except Exception as ex: except Exception as ex:
print( print(
"\nYou are probably initializing the database with a script. If not, then you have to worry about not being able to import in __init__.py!\n" "\nYou are probably initializing the database with a script. If not, then you have to worry about not being able to import in __init__.py!\n"

View file

@ -30,24 +30,24 @@ from wtforms.fields import (
from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional from wtforms.validators import URL, DataRequired, Email, NumberRange, Optional
from wtforms.widgets import NumberInput from wtforms.widgets import NumberInput
from advlabdb import adminSpace, app, assistantSpace, db, user_datastore from . import adminSpace, app, assistantSpace, db, user_datastore
from advlabdb.configUtils import getConfig from .configUtils import getConfig
from advlabdb.customClasses import ( from .customClasses import (
CustomIdEndpointLinkRowAction, CustomIdEndpointLinkRowAction,
SecureAdminBaseView, SecureAdminBaseView,
SecureAdminModelView, SecureAdminModelView,
) )
from advlabdb.database_import import importFromFile from .database_import import importFromFile
from advlabdb.dependent_funs import ( from .dependent_funs import (
flashRandomPassword, flashRandomPassword,
initActiveSemesterMenuLinks, initActiveSemesterMenuLinks,
setUserActiveSemester, setUserActiveSemester,
sortedSemestersStartingWithNewest, sortedSemestersStartingWithNewest,
userActiveSemester, userActiveSemester,
) )
from advlabdb.exceptions import DataBaseException, ModelViewException from .exceptions import DataBaseException, ModelViewException
from advlabdb.independent_funs import randomPassword from .independent_funs import randomPassword
from advlabdb.models import ( from .models import (
MAX_MARK, MAX_MARK,
MAX_YEAR, MAX_YEAR,
MIN_MARK, MIN_MARK,

View file

@ -7,16 +7,16 @@ from wtforms import BooleanField, Form, RadioField, SelectField, StringField
from wtforms.fields import DateField from wtforms.fields import DateField
from wtforms.validators import NumberRange from wtforms.validators import NumberRange
from advlabdb import assistantSpace, db from . import assistantSpace, db
from advlabdb.customClasses import SecureAssistantBaseView, SecureAssistantModelView from .customClasses import SecureAssistantBaseView, SecureAssistantModelView
from advlabdb.dependent_funs import ( from .dependent_funs import (
flashRandomPassword, flashRandomPassword,
initActiveSemesterMenuLinks, initActiveSemesterMenuLinks,
userActiveSemester, userActiveSemester,
) )
from advlabdb.exceptions import DataBaseException, ModelViewException from .exceptions import DataBaseException, ModelViewException
from advlabdb.independent_funs import randomPassword from .independent_funs import randomPassword
from advlabdb.models import ( from .models import (
MAX_MARK, MAX_MARK,
MIN_MARK, MIN_MARK,
Appointment, Appointment,

View file

@ -7,9 +7,9 @@ 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 .dependent_funs import reportBadAttempt, userActiveSemester
from advlabdb.exceptions import DataBaseException, ModelViewException from .exceptions import DataBaseException, ModelViewException
from advlabdb.models import ( from .models import (
Assistant, Assistant,
ExperimentMark, ExperimentMark,
GroupExperiment, GroupExperiment,

View file

@ -5,9 +5,9 @@ from shutil import copy2
from flask import flash, has_request_context from flask import flash, has_request_context
from advlabdb import db from . import db
from advlabdb.exceptions import DataBaseImportException from .exceptions import DataBaseImportException
from advlabdb.models import ( from .models import (
Appointment, Appointment,
Assistant, Assistant,
Experiment, Experiment,

View file

@ -2,8 +2,8 @@ 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
from advlabdb import app, db from . import app, db
from advlabdb.models import Semester from .models import Semester
def flashRandomPassword(password): def flashRandomPassword(password):

View file

@ -12,9 +12,9 @@ from flask import flash
from flask_security import current_user from flask_security import current_user
from flask_security.models.fsqla_v2 import FsRoleMixin, FsUserMixin from flask_security.models.fsqla_v2 import FsRoleMixin, FsUserMixin
from advlabdb import db from . import db
from advlabdb.configUtils import getConfig from .configUtils import getConfig
from advlabdb.exceptions import DataBaseException from .exceptions import DataBaseException
MIN_MARK = 0 MIN_MARK = 0
MAX_MARK = 15 MAX_MARK = 15

View file

@ -1,8 +1,8 @@
from flask import flash, redirect, render_template, request, url_for 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 . import app
from advlabdb.dependent_funs import setUserActiveSemester, userActiveSemester from .dependent_funs import setUserActiveSemester, userActiveSemester
@app.context_processor @app.context_processor

View file

View file

View file

@ -1,5 +1,5 @@
from advlabdb.scripts.maintain.shared import show_update_datetime from ..terminal_utils import box, run
from advlabdb.scripts.terminal_utils import box, run from .shared import show_update_datetime
def main(): def main():

View file

@ -1,6 +1,6 @@
from datetime import datetime from datetime import datetime
from advlabdb.scripts.terminal_utils import box, spaced_hl from ..terminal_utils import box, spaced_hl
def show_update_datetime(): def show_update_datetime():

View file

@ -1,6 +1,6 @@
from advlabdb.scripts.maintain.shared import show_update_datetime from ..setup.shared import LOCAL_BIN, install_latest_pipx, poetry_update
from advlabdb.scripts.setup.shared import LOCAL_BIN, install_latest_pipx, poetry_update from ..terminal_utils import box, run
from advlabdb.scripts.terminal_utils import box, run from .shared import show_update_datetime
def main(): def main():

View file

View file

@ -1,10 +1,10 @@
from email_validator import validate_email from email_validator import validate_email
from flask_security import hash_password from flask_security import hash_password
from advlabdb import app, db, user_datastore from ... import app, db, user_datastore
from advlabdb.independent_funs import randomPassword from ...independent_funs import randomPassword
from advlabdb.models import MAX_YEAR, MIN_YEAR, Admin, Semester from ...models import MAX_YEAR, MIN_YEAR, Admin, Semester
from advlabdb.scripts.terminal_utils import box, confirm, validating_input from ..terminal_utils import box, confirm, validating_input
def main(): def main():

View file

@ -1,12 +1,7 @@
from pathlib import Path from pathlib import Path
from advlabdb.scripts.setup.shared import ( from ..terminal_utils import run, step
LOCAL_BIN, from .shared import LOCAL_BIN, LOGS_DIR, install_latest_pipx, poetry_update
LOGS_DIR,
install_latest_pipx,
poetry_update,
)
from advlabdb.scripts.terminal_utils import run, step
def main(): def main():

View file

@ -1,8 +1,6 @@
from advlabdb.scripts.setup.logged_server_setup import ( from ..terminal_utils import run
__file__ as logged_server_setup_script, from .logged_server_setup import __file__ as logged_server_setup_script
) from .shared import LOGS_DIR
from advlabdb.scripts.setup.shared import LOGS_DIR
from advlabdb.scripts.terminal_utils import run
def main(): def main():

View file

@ -1,7 +1,7 @@
from pathlib import Path from pathlib import Path
from advlabdb import __file__ as advlabdb_init_path # Points to __init__.py from ... import __file__ as advlabdb_init_path # Points to __init__.py
from advlabdb.scripts.terminal_utils import run from ..terminal_utils import run
LOCAL_BIN = Path("/home/admin/.local/bin/") LOCAL_BIN = Path("/home/admin/.local/bin/")
LOGS_DIR = Path("/var/log/advlabdb") LOGS_DIR = Path("/var/log/advlabdb")

View file

View file

@ -2,8 +2,8 @@ from datetime import date
from flask_security import hash_password from flask_security import hash_password
from advlabdb import app, db, user_datastore from ... import app, db, user_datastore
from advlabdb.models import * from ...models import *
def main(): def main():

View file

@ -43,7 +43,8 @@ Run the following:
[source,bash] [source,bash]
---- ----
# Run server setup script # Run server setup script
python3 ~/advlabdb/advlabdb/scripts/setup/server_setup.py cd ~/advlabdb
python3 -m advlabdb.scripts.setup.init_db
---- ----
Change server_name in advlabdb.conf Change server_name in advlabdb.conf