Docstring, pylint.

This commit is contained in:
Alexis Lahouze 2017-05-04 14:44:22 +02:00
parent f77843b2bb
commit 36af37d611
4 changed files with 23 additions and 0 deletions

View File

@ -21,6 +21,8 @@ from .operations import Operation
class Account(db.Model):
"Model class to handle accounts."
# pylint: disable=invalid-name
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(200), nullable=False)
authorized_overdraft = db.Column(db.Integer, nullable=True, default=0)
@ -31,6 +33,7 @@ class Account(db.Model):
@classmethod
def query(cls, begin=None, end=None):
"Return a query for this class method."
return db.session.query(
cls
).order_by(
@ -38,6 +41,8 @@ class Account(db.Model):
)
def solds(self):
"Return the solds of this account."
# TODO Alexis Lahouze 2017-05-04 Rename to "balances"
return db.session.query(
db.func.sum(Operation.value).label("future"),
db.func.sum(
@ -59,6 +64,8 @@ class Account(db.Model):
).one()
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(
db.func.sum(
db.case(
@ -89,6 +96,7 @@ class Account(db.Model):
@db.validates('authorized_overdraft')
def validate_authorized_overdraft(self, key, authorized_overdraft):
"Validator for authorized_overdraft : must be negative."
assert authorized_overdraft <= 0
return authorized_overdraft

View File

@ -22,7 +22,10 @@ import arrow
from . import db
# pylint: disable=too-many-instance-attributes
class Operation(db.Model):
"Class used to handle operations."
# pylint: disable=invalid-name
id = db.Column(db.Integer, primary_key=True)
operation_date = db.Column(

View File

@ -26,6 +26,8 @@ from .operations import Operation
class ScheduledOperation(db.Model):
"Class used to handle scheduled operations."
# pylint: disable=invalid-name
id = db.Column(db.Integer, primary_key=True)
start_date = db.Column(db.Date, nullable=False)
@ -49,6 +51,7 @@ class ScheduledOperation(db.Model):
backref=db.backref('scheduled_operation', lazy="dynamic")
)
# pylint: disable=too-many-arguments
def __init__(self, start_date, stop_date, day, frequency, label, value,
account_id, category=None):
self.start_date = start_date
@ -62,6 +65,7 @@ class ScheduledOperation(db.Model):
@classmethod
def query(cls):
"Return base query for this class."
return db.session.query(
cls
).order_by(
@ -71,6 +75,7 @@ class ScheduledOperation(db.Model):
)
def reschedule(self):
"Reschedule a scheduled operation."
# 1) delete unconfirmed operations for this account.
db.session.query(
Operation

View File

@ -28,6 +28,8 @@ from . import db
class User(UserMixin, db.Model):
"Class used to handle users."
# pylint: disable=invalid-name
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(200), nullable=False, unique=True, index=True)
password = db.Column(db.String(100), nullable=True)
@ -39,22 +41,27 @@ class User(UserMixin, db.Model):
@classmethod
def query(cls):
"Return a query for this class."
return db.session.query(cls)
@classmethod
def hash_password(cls, password):
"Password hash function."
return crypt.encrypt(password)
def verify_password(self, password):
"Verify password passed in argument with the user's one."
return crypt.verify(password, self.password)
def generate_auth_token(self):
"Generate authentication token used to identify the session."
serializer = Serializer(app.secret_key)
return serializer.dumps({'id': self.id})
@classmethod
def verify_auth_token(cls, token):
"Verify the authentication token and return the associated user."
serializer = Serializer(app.config['SECRET_KEY'])
try: