Commit a5a365e85d2ad37e259244e69a9580849dd48c01

Authored by hitier
1 parent 775de511

Move User model to auth module

app/__init__.py
... ... @@ -8,7 +8,8 @@ import logging
8 8 from logging.handlers import RotatingFileHandler
9 9 from flask.logging import default_handler
10 10  
11   -from app.models import db, User
  11 +from app.models import db
  12 +from app.auth.models import User
12 13  
13 14 from dotenv import load_dotenv
14 15  
... ...
app/auth/models.py 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +from flask_login import UserMixin
  2 +from app.models import db
  3 +
  4 +
  5 +class User(UserMixin, db.Model):
  6 + id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
  7 + email = db.Column(db.String(100), unique=True)
  8 + name = db.Column(db.String(100))
  9 + login = db.Column(db.String(100), unique=True)
  10 + password = db.Column(db.String(100))
  11 +
  12 + def __repr__(self):
  13 + return "i: {}, n: {}, e: {}, l: {}".format(self.id, self.name, self.email, self.login)
  14 +
... ...
app/auth/routes.py
1 1 from flask import render_template, request, redirect, url_for, flash
2 2 from flask_login import login_user, logout_user
3   -from app.models import User
  3 +from .models import User
4 4  
5 5 from . import bp
6 6  
... ...
app/commands/commands.py
... ... @@ -9,7 +9,8 @@ from sqlalchemy.ext.automap import automap_base
9 9 from sqlalchemy.orm import Session
10 10 from sqlalchemy import create_engine
11 11  
12   -from app.models import db, User, Agent, Service, Project, Capacity, Period, Charge
  12 +from app.models import db, Agent, Service, Project, Capacity, Period, Charge
  13 +from app.auth.models import User
13 14  
14 15 from . import bp
15 16  
... ... @@ -32,7 +33,6 @@ def feed_from_lesia():
32 33 print("Please, configure the mysql database (see db_config.py)")
33 34 sys.exit(-1)
34 35  
35   -
36 36 # mapped classes are now created with names by default
37 37 # matching that of the table name.
38 38 LesiaAgent = Base.classes.agent
... ... @@ -96,7 +96,7 @@ def feed_random_charges(agent):
96 96 .filter(Charge.agent_id == agent_id,
97 97 Charge.period_id == period_id
98 98 ).scalar()
99   - if total_charge is not None and (total_charge + percent)>= 100:
  99 + if total_charge is not None and (total_charge + percent) >= 100:
100 100 print("Skipping agent {} for period {}".format(agent_id, period_id))
101 101 continue
102 102 charge = Charge(agent_id=agent_id,
... ...
app/models.py
1   -from flask_login import UserMixin
2 1 from flask_sqlalchemy import SQLAlchemy
3 2  
4 3 db = SQLAlchemy()
5 4  
6 5  
7   -class User(UserMixin, db.Model):
8   - id = db.Column(db.Integer, primary_key=True) # primary keys are required by SQLAlchemy
9   - email = db.Column(db.String(100), unique=True)
10   - name = db.Column(db.String(100))
11   - login = db.Column(db.String(100), unique=True)
12   - password = db.Column(db.String(100))
13   -
14   - def __repr__(self):
15   - return "i: {}, n: {}, e: {}, l: {}".format(self.id, self.name, self.email, self.login)
16   -
17   -
18 6 class Agent(db.Model):
19 7 id = db.Column(db.Integer, primary_key=True)
20 8 firstname = db.Column(db.String(100))
... ...