Docstring, pylint.
This commit is contained in:
parent
f77843b2bb
commit
36af37d611
@ -21,6 +21,8 @@ from .operations import Operation
|
|||||||
|
|
||||||
|
|
||||||
class Account(db.Model):
|
class Account(db.Model):
|
||||||
|
"Model class to handle accounts."
|
||||||
|
# pylint: disable=invalid-name
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(200), nullable=False)
|
name = db.Column(db.String(200), nullable=False)
|
||||||
authorized_overdraft = db.Column(db.Integer, nullable=True, default=0)
|
authorized_overdraft = db.Column(db.Integer, nullable=True, default=0)
|
||||||
@ -31,6 +33,7 @@ class Account(db.Model):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def query(cls, begin=None, end=None):
|
def query(cls, begin=None, end=None):
|
||||||
|
"Return a query for this class method."
|
||||||
return db.session.query(
|
return db.session.query(
|
||||||
cls
|
cls
|
||||||
).order_by(
|
).order_by(
|
||||||
@ -38,6 +41,8 @@ class Account(db.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def solds(self):
|
def solds(self):
|
||||||
|
"Return the solds of this account."
|
||||||
|
# TODO Alexis Lahouze 2017-05-04 Rename to "balances"
|
||||||
return db.session.query(
|
return db.session.query(
|
||||||
db.func.sum(Operation.value).label("future"),
|
db.func.sum(Operation.value).label("future"),
|
||||||
db.func.sum(
|
db.func.sum(
|
||||||
@ -59,6 +64,8 @@ class Account(db.Model):
|
|||||||
).one()
|
).one()
|
||||||
|
|
||||||
def balance(self, begin, end):
|
def balance(self, begin, end):
|
||||||
|
"Return the balance for a specific time period."
|
||||||
|
# TODO Alexis Lahouze 2017-05-04 Rename to "flow" or "cash flow"
|
||||||
query = db.session.query(
|
query = db.session.query(
|
||||||
db.func.sum(
|
db.func.sum(
|
||||||
db.case(
|
db.case(
|
||||||
@ -89,6 +96,7 @@ class Account(db.Model):
|
|||||||
|
|
||||||
@db.validates('authorized_overdraft')
|
@db.validates('authorized_overdraft')
|
||||||
def validate_authorized_overdraft(self, key, authorized_overdraft):
|
def validate_authorized_overdraft(self, key, authorized_overdraft):
|
||||||
|
"Validator for authorized_overdraft : must be negative."
|
||||||
assert authorized_overdraft <= 0
|
assert authorized_overdraft <= 0
|
||||||
|
|
||||||
return authorized_overdraft
|
return authorized_overdraft
|
||||||
|
@ -22,7 +22,10 @@ import arrow
|
|||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=too-many-instance-attributes
|
||||||
class Operation(db.Model):
|
class Operation(db.Model):
|
||||||
|
"Class used to handle operations."
|
||||||
|
# pylint: disable=invalid-name
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
operation_date = db.Column(
|
operation_date = db.Column(
|
||||||
|
@ -26,6 +26,8 @@ from .operations import Operation
|
|||||||
|
|
||||||
|
|
||||||
class ScheduledOperation(db.Model):
|
class ScheduledOperation(db.Model):
|
||||||
|
"Class used to handle scheduled operations."
|
||||||
|
# pylint: disable=invalid-name
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
|
|
||||||
start_date = db.Column(db.Date, nullable=False)
|
start_date = db.Column(db.Date, nullable=False)
|
||||||
@ -49,6 +51,7 @@ class ScheduledOperation(db.Model):
|
|||||||
backref=db.backref('scheduled_operation', lazy="dynamic")
|
backref=db.backref('scheduled_operation', lazy="dynamic")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# pylint: disable=too-many-arguments
|
||||||
def __init__(self, start_date, stop_date, day, frequency, label, value,
|
def __init__(self, start_date, stop_date, day, frequency, label, value,
|
||||||
account_id, category=None):
|
account_id, category=None):
|
||||||
self.start_date = start_date
|
self.start_date = start_date
|
||||||
@ -62,6 +65,7 @@ class ScheduledOperation(db.Model):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def query(cls):
|
def query(cls):
|
||||||
|
"Return base query for this class."
|
||||||
return db.session.query(
|
return db.session.query(
|
||||||
cls
|
cls
|
||||||
).order_by(
|
).order_by(
|
||||||
@ -71,6 +75,7 @@ class ScheduledOperation(db.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def reschedule(self):
|
def reschedule(self):
|
||||||
|
"Reschedule a scheduled operation."
|
||||||
# 1) delete unconfirmed operations for this account.
|
# 1) delete unconfirmed operations for this account.
|
||||||
db.session.query(
|
db.session.query(
|
||||||
Operation
|
Operation
|
||||||
|
@ -28,6 +28,8 @@ from . import db
|
|||||||
|
|
||||||
|
|
||||||
class User(UserMixin, db.Model):
|
class User(UserMixin, db.Model):
|
||||||
|
"Class used to handle users."
|
||||||
|
# pylint: disable=invalid-name
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
email = db.Column(db.String(200), nullable=False, unique=True, index=True)
|
email = db.Column(db.String(200), nullable=False, unique=True, index=True)
|
||||||
password = db.Column(db.String(100), nullable=True)
|
password = db.Column(db.String(100), nullable=True)
|
||||||
@ -39,22 +41,27 @@ class User(UserMixin, db.Model):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def query(cls):
|
def query(cls):
|
||||||
|
"Return a query for this class."
|
||||||
return db.session.query(cls)
|
return db.session.query(cls)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def hash_password(cls, password):
|
def hash_password(cls, password):
|
||||||
|
"Password hash function."
|
||||||
return crypt.encrypt(password)
|
return crypt.encrypt(password)
|
||||||
|
|
||||||
def verify_password(self, password):
|
def verify_password(self, password):
|
||||||
|
"Verify password passed in argument with the user's one."
|
||||||
return crypt.verify(password, self.password)
|
return crypt.verify(password, self.password)
|
||||||
|
|
||||||
def generate_auth_token(self):
|
def generate_auth_token(self):
|
||||||
|
"Generate authentication token used to identify the session."
|
||||||
serializer = Serializer(app.secret_key)
|
serializer = Serializer(app.secret_key)
|
||||||
|
|
||||||
return serializer.dumps({'id': self.id})
|
return serializer.dumps({'id': self.id})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def verify_auth_token(cls, token):
|
def verify_auth_token(cls, token):
|
||||||
|
"Verify the authentication token and return the associated user."
|
||||||
serializer = Serializer(app.config['SECRET_KEY'])
|
serializer = Serializer(app.config['SECRET_KEY'])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user