From e53373ab99a5ec30bd4958b103f6a3c751050f1a Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Thu, 25 Nov 2021 23:21:48 +0000 Subject: [PATCH] Refactor to have all models in the models package. --- ref-test/admin/auth.py | 12 ++++++------ ref-test/admin/{user => models}/__init__.py | 0 ref-test/admin/{ => models}/forms.py | 0 ref-test/admin/{models.py => models/tests.py} | 0 ref-test/admin/{user/models.py => models/users.py} | 0 ref-test/admin/views.py | 14 +++++++------- 6 files changed, 13 insertions(+), 13 deletions(-) rename ref-test/admin/{user => models}/__init__.py (100%) rename ref-test/admin/{ => models}/forms.py (100%) rename ref-test/admin/{models.py => models/tests.py} (100%) rename ref-test/admin/{user/models.py => models/users.py} (100%) diff --git a/ref-test/admin/auth.py b/ref-test/admin/auth.py index fd9e854..2c6e259 100644 --- a/ref-test/admin/auth.py +++ b/ref-test/admin/auth.py @@ -1,7 +1,7 @@ from flask import Blueprint, render_template, request, session, redirect from flask.helpers import flash, url_for from flask.json import jsonify -from .user.models import User +from .models.users import User from uuid import uuid4 from security.database import decrypt_find_one, encrypted_update from werkzeug.security import check_password_hash @@ -21,7 +21,7 @@ auth = Blueprint( @admin_account_required @login_required def account(): - from .forms import UpdateAccountForm + from .models.forms import UpdateAccountForm form = UpdateAccountForm() _id = get_id_from_cookie() user = decrypt_find_one(db.users, {'_id': _id}) @@ -46,7 +46,7 @@ def account(): @admin_account_required @disable_if_logged_in def login(): - from .forms import LoginForm + from .models.forms import LoginForm form = LoginForm() if request.method == 'GET': return render_template('/admin/auth/login.html', form=form) @@ -72,7 +72,7 @@ def logout(): @auth.route('/register/', methods=['GET','POST']) @disable_on_registration def register(): - from .forms import RegistrationForm + from .models.forms import RegistrationForm form = RegistrationForm() if request.method == 'GET': return render_template('/admin/auth/register.html', form=form) @@ -93,7 +93,7 @@ def register(): @admin_account_required @disable_if_logged_in def reset(): - from .forms import ResetPasswordForm + from .models.forms import ResetPasswordForm form = ResetPasswordForm() if request.method == 'GET': return render_template('/admin/auth/reset.html', form=form) @@ -128,7 +128,7 @@ def reset_gateway(token1,token2): @admin_account_required @disable_if_logged_in def update_password_(): - from .forms import UpdatePasswordForm + from .models.forms import UpdatePasswordForm form = UpdatePasswordForm() if request.method == 'GET': if 'reset_validated' not in session: diff --git a/ref-test/admin/user/__init__.py b/ref-test/admin/models/__init__.py similarity index 100% rename from ref-test/admin/user/__init__.py rename to ref-test/admin/models/__init__.py diff --git a/ref-test/admin/forms.py b/ref-test/admin/models/forms.py similarity index 100% rename from ref-test/admin/forms.py rename to ref-test/admin/models/forms.py diff --git a/ref-test/admin/models.py b/ref-test/admin/models/tests.py similarity index 100% rename from ref-test/admin/models.py rename to ref-test/admin/models/tests.py diff --git a/ref-test/admin/user/models.py b/ref-test/admin/models/users.py similarity index 100% rename from ref-test/admin/user/models.py rename to ref-test/admin/models/users.py diff --git a/ref-test/admin/views.py b/ref-test/admin/views.py index c6f4fc2..6bc4ce4 100644 --- a/ref-test/admin/views.py +++ b/ref-test/admin/views.py @@ -4,14 +4,14 @@ from functools import wraps from werkzeug.security import check_password_hash from security.database import decrypt_find, decrypt_find_one -from .user.models import User +from .models.users import User from flask_mail import Message from main import db from uuid import uuid4 import secrets from main import mail from datetime import datetime, date, timedelta -from .models import Test +from .models.tests import Test views = Blueprint( 'admin_views', @@ -82,7 +82,7 @@ def settings(): @admin_account_required @login_required def users(): - from .forms import CreateUserForm + from .models.forms import CreateUserForm form = CreateUserForm() if request.method == 'GET': users_list = decrypt_find(db.users, {}) @@ -132,7 +132,7 @@ def delete_user(_id:str): if _id == get_id_from_cookie(): flash('Cannot delete your own user account.', 'error') return redirect(url_for('admin_views.users')) - from .forms import DeleteUserForm + from .models.forms import DeleteUserForm form = DeleteUserForm() user = decrypt_find_one(db.users, {'_id': _id}) if request.method == 'GET': @@ -181,7 +181,7 @@ def update_user(_id:str): if _id == get_id_from_cookie(): flash('Cannot delete your own user account.', 'error') return redirect(url_for('admin_views.users')) - from .forms import UpdateUserForm + from .models.forms import UpdateUserForm form = UpdateUserForm() user = decrypt_find_one( db.users, {'_id': _id}) if request.method == 'GET': @@ -251,7 +251,7 @@ def tests(filter=''): if filter not in ['', 'create', 'active', 'scheduled', 'expired', 'all']: return abort(404) if filter == 'create': - from .forms import CreateTest + from .models.forms import CreateTest form = CreateTest() form.time_limit.default='none' form.process() @@ -281,7 +281,7 @@ def tests(filter=''): @admin_account_required @login_required def _tests(): - from .forms import CreateTest + from .models.forms import CreateTest form = CreateTest() form.time_limit.default='none' form.process()