From a5a365e85d2ad37e259244e69a9580849dd48c01 Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Fri, 26 Mar 2021 17:28:51 +0100 Subject: [PATCH] Move User model to auth module --- app/__init__.py | 3 ++- app/auth/models.py | 14 ++++++++++++++ app/auth/routes.py | 2 +- app/commands/commands.py | 6 +++--- app/models.py | 12 ------------ 5 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 app/auth/models.py diff --git a/app/__init__.py b/app/__init__.py index 26cd063..23739ce 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -8,7 +8,8 @@ import logging from logging.handlers import RotatingFileHandler from flask.logging import default_handler -from app.models import db, User +from app.models import db +from app.auth.models import User from dotenv import load_dotenv diff --git a/app/auth/models.py b/app/auth/models.py new file mode 100644 index 0000000..42b0066 --- /dev/null +++ b/app/auth/models.py @@ -0,0 +1,14 @@ +from flask_login import UserMixin +from app.models import db + + +class User(UserMixin, db.Model): + id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy + email = db.Column(db.String(100), unique=True) + name = db.Column(db.String(100)) + login = db.Column(db.String(100), unique=True) + password = db.Column(db.String(100)) + + def __repr__(self): + return "i: {}, n: {}, e: {}, l: {}".format(self.id, self.name, self.email, self.login) + diff --git a/app/auth/routes.py b/app/auth/routes.py index 09b4327..d550ee9 100644 --- a/app/auth/routes.py +++ b/app/auth/routes.py @@ -1,6 +1,6 @@ from flask import render_template, request, redirect, url_for, flash from flask_login import login_user, logout_user -from app.models import User +from .models import User from . import bp diff --git a/app/commands/commands.py b/app/commands/commands.py index 08e0615..2233caa 100644 --- a/app/commands/commands.py +++ b/app/commands/commands.py @@ -9,7 +9,8 @@ from sqlalchemy.ext.automap import automap_base from sqlalchemy.orm import Session from sqlalchemy import create_engine -from app.models import db, User, Agent, Service, Project, Capacity, Period, Charge +from app.models import db, Agent, Service, Project, Capacity, Period, Charge +from app.auth.models import User from . import bp @@ -32,7 +33,6 @@ def feed_from_lesia(): print("Please, configure the mysql database (see db_config.py)") sys.exit(-1) - # mapped classes are now created with names by default # matching that of the table name. LesiaAgent = Base.classes.agent @@ -96,7 +96,7 @@ def feed_random_charges(agent): .filter(Charge.agent_id == agent_id, Charge.period_id == period_id ).scalar() - if total_charge is not None and (total_charge + percent)>= 100: + if total_charge is not None and (total_charge + percent) >= 100: print("Skipping agent {} for period {}".format(agent_id, period_id)) continue charge = Charge(agent_id=agent_id, diff --git a/app/models.py b/app/models.py index 9dd485d..7b6c232 100644 --- a/app/models.py +++ b/app/models.py @@ -1,20 +1,8 @@ -from flask_login import UserMixin from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() -class User(UserMixin, db.Model): - id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy - email = db.Column(db.String(100), unique=True) - name = db.Column(db.String(100)) - login = db.Column(db.String(100), unique=True) - password = db.Column(db.String(100)) - - def __repr__(self): - return "i: {}, n: {}, e: {}, l: {}".format(self.id, self.name, self.email, self.login) - - class Agent(db.Model): id = db.Column(db.Integer, primary_key=True) firstname = db.Column(db.String(100)) -- libgit2 0.21.2