fix the circular import hell
This commit is contained in:
parent
1de078d47e
commit
4e7d8bc743
12 changed files with 38 additions and 41 deletions
|
@ -4,10 +4,9 @@ from flask_login import fresh_login_required, login_user, logout_user
|
|||
|
||||
from . import admin
|
||||
|
||||
from .. import db
|
||||
from ..mailsender import send_email
|
||||
from ..models import User, Item
|
||||
from ..decorators import admin_required, permission_required
|
||||
from mailsender import send_email
|
||||
from models import db, User, Item
|
||||
from decorators import admin_required, permission_required
|
||||
|
||||
import base64
|
||||
import string
|
||||
|
|
|
@ -17,26 +17,18 @@ from waitress import serve
|
|||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_bootstrap import Bootstrap
|
||||
from flask_mail import Mail
|
||||
from flask_login import LoginManager
|
||||
from flask_wtf.csrf import CSRFProtect, CSRFError
|
||||
from flask_moment import Moment
|
||||
|
||||
from models import lm
|
||||
|
||||
sys.stderr.write("worker uid={} gid={}".format(os.getuid(), os.getgid()))
|
||||
sys.stderr.flush()
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object("config.Config")
|
||||
|
||||
db = SQLAlchemy(app)
|
||||
#db.init_app(app)
|
||||
|
||||
#apiauth = HTTPBasicAuth()
|
||||
lm = LoginManager()
|
||||
lm.init_app(app)
|
||||
lm.login_view = 'auth.login'
|
||||
lm.login_message = 'Login Required.'
|
||||
lm.session_protection = 'strong'
|
||||
#lm.session_protection = 'basic'
|
||||
|
||||
mail = Mail()
|
||||
mail.init_app(app)
|
||||
|
|
|
@ -3,8 +3,8 @@ from flask_wtf import FlaskForm, RecaptchaField
|
|||
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
|
||||
from wtforms import validators, ValidationError
|
||||
from wtforms.fields import EmailField
|
||||
from ..models import User
|
||||
|
||||
from models import User
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
email = EmailField('E-Mail', [validators.DataRequired(), validators.Length(1,64), validators.Email()])
|
||||
|
|
|
@ -2,11 +2,11 @@ from flask import render_template, redirect, request, url_for, flash, session, a
|
|||
from flask_login import login_required, login_user, logout_user, current_user
|
||||
|
||||
from . import auth
|
||||
from .. import db
|
||||
from ..models import User
|
||||
from ..mailsender import send_email
|
||||
from .forms import LoginForm, TwoFAForm, RegistrationForm, ChangePasswordForm, PasswordResetRequestForm, PasswordResetForm
|
||||
from ..decorators import admin_required, permission_required
|
||||
|
||||
from decorators import admin_required, permission_required
|
||||
from mailsender import send_email
|
||||
from models import db, User
|
||||
|
||||
from io import BytesIO
|
||||
import pyqrcode
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from functools import wraps
|
||||
from flask import abort
|
||||
from flask_login import current_user
|
||||
from .models import Permission
|
||||
from threading import Thread
|
||||
|
||||
def asyncfn(f):
|
||||
|
@ -21,5 +20,6 @@ def permission_required(permission):
|
|||
return decorator
|
||||
|
||||
def admin_required(f):
|
||||
from models import Permission
|
||||
return permission_required(Permission.ADMINISTER)(f)
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
from threading import Thread
|
||||
from flask import current_app, render_template
|
||||
from flask_mail import Message
|
||||
from . import app, mail
|
||||
from .decorators import asyncfn
|
||||
from decorators import asyncfn
|
||||
|
||||
@asyncfn
|
||||
def send_async_email(app, msg):
|
||||
|
|
|
@ -3,7 +3,7 @@ from flask_wtf import FlaskForm, RecaptchaField
|
|||
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
|
||||
from wtforms import validators, ValidationError
|
||||
from wtforms.fields import EmailField
|
||||
from ..models import User
|
||||
from models import User
|
||||
|
||||
class LoginForm(FlaskForm):
|
||||
email = EmailField('', [validators.DataRequired(), validators.Length(1,64), validators.Email()], render_kw={"placeholder": "username"})
|
||||
|
@ -22,4 +22,4 @@ class RegistrationForm(FlaskForm):
|
|||
accept_tos = BooleanField('I accept the <a href="/terms">Terms of Service</a>', [validators.DataRequired()])
|
||||
recaptcha = RecaptchaField()
|
||||
submit = SubmitField('REGISTER')
|
||||
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ from flask_login import login_required, login_user, logout_user, current_user
|
|||
|
||||
from . import main
|
||||
from .forms import LoginForm, RegistrationForm
|
||||
from .. import db
|
||||
from ..mailsender import send_email
|
||||
from ..models import User, Permission, Item
|
||||
|
||||
from mailsender import send_email
|
||||
from models import db, User, Permission, Item
|
||||
|
||||
import base64
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
|
||||
from itsdangerous import URLSafeTimedSerializer as Serializer
|
||||
|
||||
from flask import current_app, request, url_for
|
||||
from flask_login import UserMixin, AnonymousUserMixin
|
||||
from . import db, lm
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import LoginManager, UserMixin, AnonymousUserMixin
|
||||
|
||||
import os
|
||||
import random
|
||||
|
@ -14,6 +14,14 @@ import json
|
|||
from datetime import date, time, datetime, timedelta
|
||||
import onetimepass
|
||||
|
||||
db = SQLAlchemy()
|
||||
|
||||
lm = LoginManager()
|
||||
lm.login_view = 'auth.login'
|
||||
lm.login_message = 'Login Required.'
|
||||
lm.session_protection = 'strong'
|
||||
lm.anonymous_user = AnonymousUserMixin
|
||||
|
||||
class Permission:
|
||||
DEPLOY = 0x01
|
||||
ADMINISTER = 0xff
|
||||
|
@ -189,8 +197,6 @@ class AnonymousUser(AnonymousUserMixin):
|
|||
def is_administrator(self):
|
||||
return False
|
||||
|
||||
lm.anonymous_user = AnonymousUser
|
||||
|
||||
@lm.user_loader
|
||||
def load_user(user_id):
|
||||
return User.query.get(int(user_id))
|
||||
|
@ -202,4 +208,4 @@ class Item(db.Model):
|
|||
user_id = db.Column(db.ForeignKey('users.id')) #FK
|
||||
key = db.Column(db.Integer, default=0)
|
||||
description = db.Column(db.Unicode)
|
||||
date_created = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
date_created = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
flask import render_template, abort, redirect, url_for, abort, flash, request, current_app, make_response, g
|
||||
from flask import render_template, abort, redirect, url_for, abort, flash, request, current_app, make_response, g
|
||||
from flask_login import login_required, login_user, logout_user, current_user
|
||||
#from flask_sqlalchemy import get_recorded_queries
|
||||
|
||||
from . import panel
|
||||
from .. import db
|
||||
from ..mailsender import send_email
|
||||
from ..models import User, Permission, Item
|
||||
|
||||
from mailsender import send_email
|
||||
from models import db, User, Permission, Item
|
||||
|
||||
import base64
|
||||
from datetime import date, time, datetime
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from iso3166 import countries
|
||||
import string
|
||||
import random
|
||||
from ..models import User, Role
|
||||
|
||||
from models import User, Role
|
||||
|
||||
from flask_wtf import FlaskForm, RecaptchaField
|
||||
from wtforms import StringField, PasswordField, BooleanField, SubmitField, SelectField, DecimalField
|
||||
|
|
|
@ -5,9 +5,9 @@ from sqlalchemy import desc
|
|||
from . import settings
|
||||
from .forms import EditProfileForm, EditProfileAdminForm
|
||||
|
||||
from ..mailsender import send_email
|
||||
from .. import db
|
||||
from ..models import User
|
||||
from mailsender import send_email
|
||||
from models import db, User
|
||||
|
||||
import sys
|
||||
|
||||
#PROFILE
|
||||
|
|
Loading…
Reference in a new issue