1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +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 advlabdb.independent_funs import parse_bool
from .independent_funs import parse_bool
def set_from_env(app, var):
@ -39,7 +39,7 @@ db = SQLAlchemy(app)
fsqla.FsModels.set_db_info(db)
from advlabdb import customClasses
from . import customClasses
adminSpace = Admin(
app,
@ -58,14 +58,14 @@ assistantSpace = Admin(
index_view=customClasses.SecureAssistantIndexView(name="Assistant", url="/assistant", endpoint="assistantSpace"),
)
from advlabdb import models
from . import models
# Setup Flask-Security
user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role)
Security(app, user_datastore)
try:
from advlabdb import routes, adminModelViews, assistantModelViews
from . import routes, adminModelViews, assistantModelViews
except Exception as ex:
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"

View file

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

View file

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

View file

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

View file

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

View file

@ -2,8 +2,8 @@ from flask import flash, url_for
from flask_admin.menu import MenuLink
from flask_security import current_user
from advlabdb import app, db
from advlabdb.models import Semester
from . import app, db
from .models import Semester
def flashRandomPassword(password):

View file

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

View file

@ -1,8 +1,8 @@
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.dependent_funs import setUserActiveSemester, userActiveSemester
from . import app
from .dependent_funs import setUserActiveSemester, userActiveSemester
@app.context_processor

View file

View file

View file

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

View file

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

View file

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

View file

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
from pathlib import Path
from advlabdb import __file__ as advlabdb_init_path # Points to __init__.py
from advlabdb.scripts.terminal_utils import run
from ... import __file__ as advlabdb_init_path # Points to __init__.py
from ..terminal_utils import run
LOCAL_BIN = Path("/home/admin/.local/bin/")
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 advlabdb import app, db, user_datastore
from advlabdb.models import *
from ... import app, db, user_datastore
from ...models import *
def main():

View file

@ -43,7 +43,8 @@ Run the following:
[source,bash]
----
# 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