[WIP] Added dao method and rest endpoint for getting template

statistics by service.

Some cosmetic changes to imports.

Added fix for job rest not correctly returning errors.
This commit is contained in:
Adam Shimali
2016-04-04 12:21:38 +01:00
parent e2d0d39ea7
commit 0d06be05e1
10 changed files with 390 additions and 44 deletions

View File

@@ -1,15 +1,27 @@
from flask_marshmallow.fields import fields
from . import ma
from . import models
from app.dao.permissions_dao import permission_dao
from marshmallow import (post_load, ValidationError, validates, validates_schema, pre_load)
from marshmallow import (
post_load,
ValidationError,
validates,
validates_schema,
pre_load
)
from marshmallow_sqlalchemy import field_for
from utils.recipients import (
validate_email_address, InvalidEmailError,
validate_phone_number, InvalidPhoneError,
validate_email_address,
InvalidEmailError,
validate_phone_number,
InvalidPhoneError,
validate_and_format_phone_number
)
from app import ma
from app import models
from app.dao.permissions_dao import permission_dao
# TODO I think marshmallow provides a better integration and error handling.
# Would be better to replace functionality in dao with the marshmallow supported
@@ -19,7 +31,7 @@ from utils.recipients import (
class BaseSchema(ma.ModelSchema):
def __init__(self, *args, load_json=False, **kwargs):
def __init__(self, load_json=False, *args, **kwargs):
self.load_json = load_json
super(BaseSchema, self).__init__(*args, **kwargs)
@@ -241,6 +253,14 @@ class NotificationsFilterSchema(ma.Schema):
raise ValidationError("Not a positive integer")
class TemplateStatisticsSchema(BaseSchema):
template = fields.Nested(TemplateSchema, only=["id", "name", "template_type"], dump_only=True)
class Meta:
model = models.TemplateStatistics
user_schema = UserSchema()
user_schema_load_json = UserSchema(load_json=True)
service_schema = ServiceSchema()
@@ -264,3 +284,4 @@ permission_schema = PermissionSchema()
email_data_request_schema = EmailDataSchema()
notifications_statistics_schema = NotificationsStatisticsSchema()
notifications_filter_schema = NotificationsFilterSchema()
template_statistics_schema = TemplateStatisticsSchema()