Move view models in a different module.
This commit is contained in:
parent
53b961491b
commit
507c69d0b2
@ -25,27 +25,10 @@ from ..models.operations import Operation
|
|||||||
|
|
||||||
from ..fields import Object
|
from ..fields import Object
|
||||||
|
|
||||||
from .users import requires_auth
|
from .models import (account_model, solds_model, balance_model,
|
||||||
|
category_model, ohlc_model)
|
||||||
from .parsers import account_parser, range_parser
|
from .parsers import account_parser, range_parser
|
||||||
|
from .users import requires_auth
|
||||||
|
|
||||||
account_model = {
|
|
||||||
'id': fields.Integer(default=None),
|
|
||||||
'name': fields.String,
|
|
||||||
'authorized_overdraft': fields.Float,
|
|
||||||
}
|
|
||||||
|
|
||||||
solds_model = {
|
|
||||||
'current': fields.Float,
|
|
||||||
'pointed': fields.Float,
|
|
||||||
'future': fields.Float,
|
|
||||||
}
|
|
||||||
|
|
||||||
balance_model = {
|
|
||||||
'expenses': fields.Float,
|
|
||||||
'revenues': fields.Float,
|
|
||||||
'balance': fields.Float,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class AccountListResource(Resource):
|
class AccountListResource(Resource):
|
||||||
@ -167,13 +150,6 @@ class BalanceResource(Resource):
|
|||||||
return account.balance(**data), 200
|
return account.balance(**data), 200
|
||||||
|
|
||||||
|
|
||||||
category_model = {
|
|
||||||
'category': fields.String,
|
|
||||||
'expenses': fields.Float,
|
|
||||||
'revenues': fields.Float
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class CategoryResource(Resource):
|
class CategoryResource(Resource):
|
||||||
@requires_auth
|
@requires_auth
|
||||||
@marshal_with_field(fields.List(Object(category_model)))
|
@marshal_with_field(fields.List(Object(category_model)))
|
||||||
@ -183,15 +159,6 @@ class CategoryResource(Resource):
|
|||||||
return Operation.get_categories_for_range(id, **data).all()
|
return Operation.get_categories_for_range(id, **data).all()
|
||||||
|
|
||||||
|
|
||||||
ohlc_model = {
|
|
||||||
'operation_date': fields.DateTime(dt_format='iso8601'),
|
|
||||||
'open': fields.Float,
|
|
||||||
'high': fields.Float,
|
|
||||||
'low': fields.Float,
|
|
||||||
'close': fields.Float
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class OHLCResource(Resource):
|
class OHLCResource(Resource):
|
||||||
@requires_auth
|
@requires_auth
|
||||||
@marshal_with_field(fields.List(Object(ohlc_model)))
|
@marshal_with_field(fields.List(Object(ohlc_model)))
|
||||||
|
96
accountant/api/views/models.py
Normal file
96
accountant/api/views/models.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
"""
|
||||||
|
This file is part of Accountant.
|
||||||
|
|
||||||
|
Accountant is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Accountant is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with Accountant. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
from flask.ext.restful import fields
|
||||||
|
|
||||||
|
# Account model.
|
||||||
|
account_model = {
|
||||||
|
'id': fields.Integer(default=None),
|
||||||
|
'name': fields.String,
|
||||||
|
'authorized_overdraft': fields.Float,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Account status model.
|
||||||
|
solds_model = {
|
||||||
|
'current': fields.Float,
|
||||||
|
'pointed': fields.Float,
|
||||||
|
'future': fields.Float,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Account balance model.
|
||||||
|
balance_model = {
|
||||||
|
'expenses': fields.Float,
|
||||||
|
'revenues': fields.Float,
|
||||||
|
'balance': fields.Float,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Category with expenses and revenues.
|
||||||
|
category_model = {
|
||||||
|
'category': fields.String,
|
||||||
|
'expenses': fields.Float,
|
||||||
|
'revenues': fields.Float
|
||||||
|
}
|
||||||
|
|
||||||
|
# OHLC model.
|
||||||
|
ohlc_model = {
|
||||||
|
'operation_date': fields.DateTime(dt_format='iso8601'),
|
||||||
|
'open': fields.Float,
|
||||||
|
'high': fields.Float,
|
||||||
|
'low': fields.Float,
|
||||||
|
'close': fields.Float
|
||||||
|
}
|
||||||
|
|
||||||
|
# Operation with sold model.
|
||||||
|
operation_with_sold_model = {
|
||||||
|
'id': fields.Integer(default=None),
|
||||||
|
'operation_date': fields.DateTime(dt_format='iso8601'),
|
||||||
|
'label': fields.String,
|
||||||
|
'value': fields.Float,
|
||||||
|
'pointed': fields.Boolean,
|
||||||
|
'category': fields.String,
|
||||||
|
'account_id': fields.Integer,
|
||||||
|
'scheduled_operation_id': fields.Integer(default=None),
|
||||||
|
'sold': fields.Float,
|
||||||
|
'confirmed': fields.Boolean,
|
||||||
|
'canceled': fields.Boolean,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Scheduled operation model.
|
||||||
|
scheduled_operation_model = {
|
||||||
|
'id': fields.Integer,
|
||||||
|
'start_date': fields.DateTime(dt_format='iso8601'),
|
||||||
|
'stop_date': fields.DateTime(dt_format='iso8601'),
|
||||||
|
'day': fields.Integer,
|
||||||
|
'frequency': fields.Integer,
|
||||||
|
'label': fields.String,
|
||||||
|
'value': fields.Float,
|
||||||
|
'category': fields.String,
|
||||||
|
'account_id': fields.Integer,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Token with expiration time and type.
|
||||||
|
token_model = {
|
||||||
|
'token': fields.String,
|
||||||
|
'expiration': fields.DateTime(dt_format='iso8601'),
|
||||||
|
'token_type': fields.String
|
||||||
|
}
|
||||||
|
|
||||||
|
# User model.
|
||||||
|
user_model = {
|
||||||
|
'id': fields.Integer(default=None),
|
||||||
|
'email': fields.String,
|
||||||
|
'active': fields.Boolean
|
||||||
|
}
|
@ -22,29 +22,13 @@ from .. import api
|
|||||||
|
|
||||||
from ..models.operations import Operation
|
from ..models.operations import Operation
|
||||||
|
|
||||||
from .users import requires_auth
|
from .models import operation_model, operation_with_sold_model
|
||||||
from .parsers import operation_parser, account_range_parser
|
from .parsers import operation_parser, account_range_parser
|
||||||
|
from .users import requires_auth
|
||||||
|
|
||||||
from ..fields import Object
|
from ..fields import Object
|
||||||
|
|
||||||
|
|
||||||
operation_with_sold_model = {
|
|
||||||
'id': fields.Integer(default=None),
|
|
||||||
'operation_date': fields.DateTime(dt_format='iso8601'),
|
|
||||||
'label': fields.String,
|
|
||||||
'value': fields.Float,
|
|
||||||
'pointed': fields.Boolean,
|
|
||||||
'category': fields.String,
|
|
||||||
'account_id': fields.Integer,
|
|
||||||
'scheduled_operation_id': fields.Integer(default=None),
|
|
||||||
'sold': fields.Float,
|
|
||||||
'confirmed': fields.Boolean,
|
|
||||||
'canceled': fields.Boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
operation_model = operation_with_sold_model
|
|
||||||
|
|
||||||
|
|
||||||
class OperationListResource(Resource):
|
class OperationListResource(Resource):
|
||||||
@requires_auth
|
@requires_auth
|
||||||
@marshal_with_field(fields.List(Object(operation_with_sold_model)))
|
@marshal_with_field(fields.List(Object(operation_with_sold_model)))
|
||||||
|
@ -25,25 +25,13 @@ from ..models.operations import Operation
|
|||||||
|
|
||||||
from .. import api
|
from .. import api
|
||||||
|
|
||||||
from .users import requires_auth
|
from .models import scheduled_operation_model
|
||||||
from .parsers import account_id_parser, scheduled_operation_parser
|
from .parsers import account_id_parser, scheduled_operation_parser
|
||||||
|
from .users import requires_auth
|
||||||
|
|
||||||
from ..fields import Object
|
from ..fields import Object
|
||||||
|
|
||||||
|
|
||||||
scheduled_operation_model = {
|
|
||||||
'id': fields.Integer,
|
|
||||||
'start_date': fields.DateTime(dt_format='iso8601'),
|
|
||||||
'stop_date': fields.DateTime(dt_format='iso8601'),
|
|
||||||
'day': fields.Integer,
|
|
||||||
'frequency': fields.Integer,
|
|
||||||
'label': fields.String,
|
|
||||||
'value': fields.Float,
|
|
||||||
'category': fields.String,
|
|
||||||
'account_id': fields.Integer,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ScheduledOperationListResource(Resource):
|
class ScheduledOperationListResource(Resource):
|
||||||
@requires_auth
|
@requires_auth
|
||||||
@marshal_with_field(fields.List(Object(scheduled_operation_model)))
|
@marshal_with_field(fields.List(Object(scheduled_operation_model)))
|
||||||
|
@ -20,7 +20,7 @@ import arrow
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
from flask import request, g
|
from flask import request, g
|
||||||
from flask.ext.restful import Resource, fields, marshal_with, marshal_with_field
|
from flask.ext.restful import Resource, marshal_with, marshal_with_field
|
||||||
|
|
||||||
from accountant import app
|
from accountant import app
|
||||||
|
|
||||||
@ -30,6 +30,7 @@ from ..fields import Object
|
|||||||
|
|
||||||
from ..models.users import User
|
from ..models.users import User
|
||||||
|
|
||||||
|
from .models import token_model, user_model
|
||||||
from .parsers import login_parser
|
from .parsers import login_parser
|
||||||
|
|
||||||
|
|
||||||
@ -63,19 +64,6 @@ def requires_auth(f):
|
|||||||
return wrapped
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
token_model = {
|
|
||||||
'token': fields.String,
|
|
||||||
'expiration': fields.DateTime(dt_format='iso8601'),
|
|
||||||
'token_type': fields.String
|
|
||||||
}
|
|
||||||
|
|
||||||
user_model = {
|
|
||||||
'id': fields.Integer(default=None),
|
|
||||||
'email': fields.String,
|
|
||||||
'active': fields.Boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class LoginResource(Resource):
|
class LoginResource(Resource):
|
||||||
@marshal_with(token_model)
|
@marshal_with(token_model)
|
||||||
def post(self):
|
def post(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user