Commit a5a365e85d2ad37e259244e69a9580849dd48c01

Authored by hitier
1 parent 775de511

Move User model to auth module

app/__init__.py
@@ -8,7 +8,8 @@ import logging @@ -8,7 +8,8 @@ import logging
8 from logging.handlers import RotatingFileHandler 8 from logging.handlers import RotatingFileHandler
9 from flask.logging import default_handler 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 from dotenv import load_dotenv 14 from dotenv import load_dotenv
14 15
app/auth/models.py 0 → 100644
@@ -0,0 +1,14 @@ @@ -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 from flask import render_template, request, redirect, url_for, flash 1 from flask import render_template, request, redirect, url_for, flash
2 from flask_login import login_user, logout_user 2 from flask_login import login_user, logout_user
3 -from app.models import User 3 +from .models import User
4 4
5 from . import bp 5 from . import bp
6 6
app/commands/commands.py
@@ -9,7 +9,8 @@ from sqlalchemy.ext.automap import automap_base @@ -9,7 +9,8 @@ from sqlalchemy.ext.automap import automap_base
9 from sqlalchemy.orm import Session 9 from sqlalchemy.orm import Session
10 from sqlalchemy import create_engine 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 from . import bp 15 from . import bp
15 16
@@ -32,7 +33,6 @@ def feed_from_lesia(): @@ -32,7 +33,6 @@ def feed_from_lesia():
32 print("Please, configure the mysql database (see db_config.py)") 33 print("Please, configure the mysql database (see db_config.py)")
33 sys.exit(-1) 34 sys.exit(-1)
34 35
35 -  
36 # mapped classes are now created with names by default 36 # mapped classes are now created with names by default
37 # matching that of the table name. 37 # matching that of the table name.
38 LesiaAgent = Base.classes.agent 38 LesiaAgent = Base.classes.agent
@@ -96,7 +96,7 @@ def feed_random_charges(agent): @@ -96,7 +96,7 @@ def feed_random_charges(agent):
96 .filter(Charge.agent_id == agent_id, 96 .filter(Charge.agent_id == agent_id,
97 Charge.period_id == period_id 97 Charge.period_id == period_id
98 ).scalar() 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 print("Skipping agent {} for period {}".format(agent_id, period_id)) 100 print("Skipping agent {} for period {}".format(agent_id, period_id))
101 continue 101 continue
102 charge = Charge(agent_id=agent_id, 102 charge = Charge(agent_id=agent_id,
1 -from flask_login import UserMixin  
2 from flask_sqlalchemy import SQLAlchemy 1 from flask_sqlalchemy import SQLAlchemy
3 2
4 db = SQLAlchemy() 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 class Agent(db.Model): 6 class Agent(db.Model):
19 id = db.Column(db.Integer, primary_key=True) 7 id = db.Column(db.Integer, primary_key=True)
20 firstname = db.Column(db.String(100)) 8 firstname = db.Column(db.String(100))