Refactor to have all models in the models package.

This commit is contained in:
Vivek Santayana 2021-11-25 23:21:48 +00:00
parent c745e3c27c
commit 408aa965fd
6 changed files with 13 additions and 13 deletions

View File

@ -1,7 +1,7 @@
from flask import Blueprint, render_template, request, session, redirect from flask import Blueprint, render_template, request, session, redirect
from flask.helpers import flash, url_for from flask.helpers import flash, url_for
from flask.json import jsonify from flask.json import jsonify
from .user.models import User from .models.users import User
from uuid import uuid4 from uuid import uuid4
from security.database import decrypt_find_one, encrypted_update from security.database import decrypt_find_one, encrypted_update
from werkzeug.security import check_password_hash from werkzeug.security import check_password_hash
@ -21,7 +21,7 @@ auth = Blueprint(
@admin_account_required @admin_account_required
@login_required @login_required
def account(): def account():
from .forms import UpdateAccountForm from .models.forms import UpdateAccountForm
form = UpdateAccountForm() form = UpdateAccountForm()
_id = get_id_from_cookie() _id = get_id_from_cookie()
user = decrypt_find_one(db.users, {'_id': _id}) user = decrypt_find_one(db.users, {'_id': _id})
@ -46,7 +46,7 @@ def account():
@admin_account_required @admin_account_required
@disable_if_logged_in @disable_if_logged_in
def login(): def login():
from .forms import LoginForm from .models.forms import LoginForm
form = LoginForm() form = LoginForm()
if request.method == 'GET': if request.method == 'GET':
return render_template('/admin/auth/login.html', form=form) return render_template('/admin/auth/login.html', form=form)
@ -72,7 +72,7 @@ def logout():
@auth.route('/register/', methods=['GET','POST']) @auth.route('/register/', methods=['GET','POST'])
@disable_on_registration @disable_on_registration
def register(): def register():
from .forms import RegistrationForm from .models.forms import RegistrationForm
form = RegistrationForm() form = RegistrationForm()
if request.method == 'GET': if request.method == 'GET':
return render_template('/admin/auth/register.html', form=form) return render_template('/admin/auth/register.html', form=form)
@ -93,7 +93,7 @@ def register():
@admin_account_required @admin_account_required
@disable_if_logged_in @disable_if_logged_in
def reset(): def reset():
from .forms import ResetPasswordForm from .models.forms import ResetPasswordForm
form = ResetPasswordForm() form = ResetPasswordForm()
if request.method == 'GET': if request.method == 'GET':
return render_template('/admin/auth/reset.html', form=form) return render_template('/admin/auth/reset.html', form=form)
@ -128,7 +128,7 @@ def reset_gateway(token1,token2):
@admin_account_required @admin_account_required
@disable_if_logged_in @disable_if_logged_in
def update_password_(): def update_password_():
from .forms import UpdatePasswordForm from .models.forms import UpdatePasswordForm
form = UpdatePasswordForm() form = UpdatePasswordForm()
if request.method == 'GET': if request.method == 'GET':
if 'reset_validated' not in session: if 'reset_validated' not in session:

View File

@ -4,14 +4,14 @@ from functools import wraps
from werkzeug.security import check_password_hash from werkzeug.security import check_password_hash
from security.database import decrypt_find, decrypt_find_one 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 flask_mail import Message
from main import db from main import db
from uuid import uuid4 from uuid import uuid4
import secrets import secrets
from main import mail from main import mail
from datetime import datetime, date, timedelta from datetime import datetime, date, timedelta
from .models import Test from .models.tests import Test
views = Blueprint( views = Blueprint(
'admin_views', 'admin_views',
@ -82,7 +82,7 @@ def settings():
@admin_account_required @admin_account_required
@login_required @login_required
def users(): def users():
from .forms import CreateUserForm from .models.forms import CreateUserForm
form = CreateUserForm() form = CreateUserForm()
if request.method == 'GET': if request.method == 'GET':
users_list = decrypt_find(db.users, {}) users_list = decrypt_find(db.users, {})
@ -132,7 +132,7 @@ def delete_user(_id:str):
if _id == get_id_from_cookie(): if _id == get_id_from_cookie():
flash('Cannot delete your own user account.', 'error') flash('Cannot delete your own user account.', 'error')
return redirect(url_for('admin_views.users')) return redirect(url_for('admin_views.users'))
from .forms import DeleteUserForm from .models.forms import DeleteUserForm
form = DeleteUserForm() form = DeleteUserForm()
user = decrypt_find_one(db.users, {'_id': _id}) user = decrypt_find_one(db.users, {'_id': _id})
if request.method == 'GET': if request.method == 'GET':
@ -181,7 +181,7 @@ def update_user(_id:str):
if _id == get_id_from_cookie(): if _id == get_id_from_cookie():
flash('Cannot delete your own user account.', 'error') flash('Cannot delete your own user account.', 'error')
return redirect(url_for('admin_views.users')) return redirect(url_for('admin_views.users'))
from .forms import UpdateUserForm from .models.forms import UpdateUserForm
form = UpdateUserForm() form = UpdateUserForm()
user = decrypt_find_one( db.users, {'_id': _id}) user = decrypt_find_one( db.users, {'_id': _id})
if request.method == 'GET': if request.method == 'GET':
@ -251,7 +251,7 @@ def tests(filter=''):
if filter not in ['', 'create', 'active', 'scheduled', 'expired', 'all']: if filter not in ['', 'create', 'active', 'scheduled', 'expired', 'all']:
return abort(404) return abort(404)
if filter == 'create': if filter == 'create':
from .forms import CreateTest from .models.forms import CreateTest
form = CreateTest() form = CreateTest()
form.time_limit.default='none' form.time_limit.default='none'
form.process() form.process()
@ -281,7 +281,7 @@ def tests(filter=''):
@admin_account_required @admin_account_required
@login_required @login_required
def _tests(): def _tests():
from .forms import CreateTest from .models.forms import CreateTest
form = CreateTest() form = CreateTest()
form.time_limit.default='none' form.time_limit.default='none'
form.process() form.process()