Beispiel #1
0
class AddAdminParse(BaseMarshmallow):
    username = fields.String(validate=[validate.str_range(6, 16)], required=True)
    password = fields.String(validate=[validate.str_range(8, 16)], required=True)
    password_ = fields.String(validate=[validate.str_range(8, 16)], required=True)
    nickname = fields.String(validate=[validate.str_range(0, 32)], missing="admin")
    remark = fields.String(validate=[validate.str_range(0, 255)])
    image_id = fields.Integer(validate=[validate.image_exist])
Beispiel #2
0
class UserRegisterParse(BaseMarshmallow):
    email = fields.Email(validate=[validate.str_range(0, 128)], required=True)
    password = fields.String(validate=[validate.str_range(8, 16)],
                             required=True)
    password_ = fields.String(validate=[validate.str_range(8, 16)],
                              required=True)
    code = fields.String(validate=[validate.str_range(6, 6)], required=True)
Beispiel #3
0
class NotificationWithTemplateSchema(BaseSchema):
    class Meta:
        model = models.Notification
        strict = True
        exclude = ('_personalisation', 'scheduled_notification')

    template = fields.Nested(TemplateSchema,
                             only=[
                                 'id', 'version', 'name', 'template_type',
                                 'content', 'subject',
                                 'redact_personalisation',
                                 'is_precompiled_letter'
                             ],
                             dump_only=True)
    job = fields.Nested(JobSchema,
                        only=["id", "original_file_name"],
                        dump_only=True)
    created_by = fields.Nested(UserSchema,
                               only=['id', 'name', 'email_address'],
                               dump_only=True)
    status = fields.String(required=False)
    personalisation = fields.Dict(required=False)
    key_type = field_for(models.Notification, 'key_type', required=True)
    key_name = fields.String()

    @pre_dump
    def add_api_key_name(self, in_data):
        if in_data.api_key:
            in_data.key_name = in_data.api_key.name
        else:
            in_data.key_name = None
        return in_data
Beispiel #4
0
class AddDownloadParse(BaseMarshmallow):
    title = fields.String(validate=[validate.str_range(0, 128)], required=True)
    description = fields.String()
    version = fields.String(validate=[validate.str_range(0, 64)])
    language = fields.String(validate=[validate.str_range(0, 128)])
    file_id = fields.Integer(validate=[validate.data_exist(Upload)],
                             required=True)
    category_id = fields.Integer(
        validate=[validate.category_exist("download")], required=True)
    cover_id = fields.Integer(validate=[validate.image_exist], required=True)
Beispiel #5
0
class ServiceHistorySchema(ma.Schema):
    id = fields.UUID()
    name = fields.String()
    created_at = fields.DateTime()
    updated_at = fields.DateTime()
    active = fields.Boolean()
    message_limit = fields.Integer()
    restricted = fields.Boolean()
    email_from = fields.String()
    created_by_id = fields.UUID()
    version = fields.Integer()
Beispiel #6
0
class DownloadListSchema(BaseMarshmallow):
    class Meta:
        fields = ("id", "title", "description", "version", "frequency",
                  "language", "size", "image", "category_structure",
                  "category_id", "category", "update_time")

    update_time = fields.DateTime("%Y-%m-%d")
    image = fields.String(attribute="cover.url")
    category = fields.Nested(CategoryInfoSchema)
    category_structure = fields.Nested(CategoryInfoSchema,
                                       attribute="category.structure")
    size = fields.String(attribute="file.size")
Beispiel #7
0
class NotificationsFilterSchema(ma.Schema):
    class Meta:
        strict = True

    template_type = fields.Nested(BaseTemplateSchema,
                                  only=['template_type'],
                                  many=True)
    status = fields.Nested(NotificationModelSchema, only=['status'], many=True)
    page = fields.Int(required=False)
    page_size = fields.Int(required=False)
    limit_days = fields.Int(required=False)
    include_jobs = fields.Boolean(required=False)
    include_from_test_key = fields.Boolean(required=False)
    older_than = fields.UUID(required=False)
    format_for_csv = fields.String()
    to = fields.String()
    include_one_off = fields.Boolean(required=False)
    count_pages = fields.Boolean(required=False)

    @pre_load
    def handle_multidict(self, in_data):
        if isinstance(in_data, dict) and hasattr(in_data, 'getlist'):
            out_data = dict([(k, in_data.get(k)) for k in in_data.keys()])
            if 'template_type' in in_data:
                out_data['template_type'] = [{
                    'template_type': x
                } for x in in_data.getlist('template_type')]
            if 'status' in in_data:
                out_data['status'] = [{
                    "status": x
                } for x in in_data.getlist('status')]

        return out_data

    @post_load
    def convert_schema_object_to_field(self, in_data):
        if 'template_type' in in_data:
            in_data['template_type'] = [
                x.template_type for x in in_data['template_type']
            ]
        if 'status' in in_data:
            in_data['status'] = [x.status for x in in_data['status']]
        return in_data

    @validates('page')
    def validate_page(self, value):
        _validate_positive_number(value)

    @validates('page_size')
    def validate_page_size(self, value):
        _validate_positive_number(value)
Beispiel #8
0
class NotificationModelSchema(BaseSchema):
    class Meta:
        model = models.Notification
        strict = True
        exclude = ('_personalisation', 'job', 'service', 'template', 'api_key')

    status = fields.String(required=False)
Beispiel #9
0
class NotificationSchema(ma.Schema):

    class Meta:
        strict = True

    status = fields.String(required=False)
    personalisation = fields.Dict(required=False)
Beispiel #10
0
class ApiKeyHistorySchema(ma.Schema):
    id = fields.UUID()
    name = fields.String()
    service_id = fields.UUID()
    expiry_date = fields.DateTime()
    created_at = fields.DateTime()
    updated_at = fields.DateTime()
    created_by_id = fields.UUID()
Beispiel #11
0
class NewValueSchema(Schema):
    name = fields.String(required=True,
                         allow_none=False,
                         validate=validate.Length(min=1))

    # noinspection PyUnusedLocal
    @post_load()
    def get_name(self, item, many, **kwargs):
        return item['name']
Beispiel #12
0
class TaskSchema(EndDateValidationMixin, Schema):
    _id = fields.Str(dump_only=True, required=True)
    description = fields.Str(required=True,
                             allow_none=False,
                             validate=not_empty)
    end_date = fields.DateTime(required=True)
    created_at = fields.DateTime(missing=datetime.utcnow())
    done = fields.Boolean(missing=False)
    user_id = fields.String()
Beispiel #13
0
class NewParameterSchema(Schema):
    uid = fields.Integer(load_only=True)
    name = fields.String(required=True,
                         allow_none=False,
                         validate=validate.Length(min=1))
    values = fields.List(fields.String(validate=validate.Length(min=1)))
    parameter_set = fields.Pluck('ParameterSetSchema', 'uid', allow_none=True)
    position = fields.Integer(load_only=True)
    excluded = fields.Pluck("ParameterSchema", "uid", many=True)
    excluded_by = fields.Pluck("ParameterSchema", "uid", many=True)

    @validates('uid')
    def validate_uid(self, data, **kwargs):
        raise ValidationError("Cannot modify read-only field")

    @validates('position')
    def validate_position(self, data, **kwargs):
        raise ValidationError("Cannot modify read-only field")
Beispiel #14
0
class PictureAlbumListSchema(BaseMarshmallow):
    class Meta:
        fields = ("id", "title", "description", "category", "image",
                  "category_structure")

    image = fields.String(attribute="cover.url")
    category = fields.Nested(CategoryInfoSchema)
    category_structure = fields.Nested(CategoryInfoSchema,
                                       attribute="category.structure",
                                       many=True)
Beispiel #15
0
class ValueSchema(ma_sq.schema.SQLAlchemySchema):
    class Meta:
        model = ValueDao
        include_relationships = True
        load_instance = True
        sqla_session = orm_utils.orm_session()

    uid = fields.Integer()
    name = fields.String(required=True,
                         allow_none=False,
                         validate=validate.Length(min=1))
    parameter = fields.Pluck('ParameterSchema', 'uid', allow_none=True)
    position = fields.Integer(allow_none=True)
Beispiel #16
0
class ParameterExclusionSchema(ma_sq.SQLAlchemySchema):
    class Meta:
        model = ParameterDao
        include_relationships = True
        include_fk = True
        load_instance = True
        sqla_session = orm_utils.orm_session()

    uid = fields.Integer()
    name = fields.String(required=True)
    excluded = fields.Nested(ParameterSchema(only=("name", "uid")),
                             many=True,
                             dump_only=True)
    excluded_by = fields.Nested(ParameterSchema(only=("name", "uid")),
                                many=True,
                                dump_only=True)
Beispiel #17
0
class UpdateValueSchema(Schema):
    uid = fields.Integer(load_only=True)
    name = fields.String(required=True,
                         allow_none=False,
                         validate=validate.Length(min=1))
    parameter = fields.Pluck('UpdateNestedParameterSchema',
                             'uid',
                             allow_none=True)
    position = fields.Integer(load_only=True)

    @validates('uid')
    def validate_uid(self, data, **kwargs):
        raise ValidationError("Cannot modify read-only field")

    @validates('position')
    def validate_position(self, data, **kwargs):
        raise ValidationError("Cannot modify read-only field")
Beispiel #18
0
class ParameterSchema(ma_sq.SQLAlchemySchema):
    class Meta:
        model = ParameterDao
        include_relationships = True
        include_fk = True
        load_instance = True
        sqla_session = orm_utils.orm_session()

    uid = fields.Integer()
    name = fields.String(required=True,
                         allow_none=False,
                         validate=validate.Length(min=1))
    values = fields.Nested(ValueSchema, many=True)
    parameter_set = fields.Pluck('ParameterSetSchema', 'uid', allow_none=True)
    position = fields.Integer(allow_none=True)
    excluded = fields.Pluck("ParameterSchema", "uid", many=True)
    excluded_by = fields.Pluck("ParameterSchema", "uid", many=True)
Beispiel #19
0
class PictureInfoParse(BaseMarshmallow):
    description = fields.String()
    image_id = fields.Integer(validate=[validate.image_exist], required=True)
Beispiel #20
0
class JobEmailTemplateNotificationSchema(EmailNotificationSchema):
    template = fields.Str(required=True)
    job = fields.String(required=True)
Beispiel #21
0
class JobSmsTemplateNotificationSchema(SmsNotificationSchema):
    template = fields.Str(required=True)
    job = fields.String(required=True)
Beispiel #22
0
class RegisterSchema(Schema):
    name = fields.String(required=False, validate=Length(min=3, max=50))
    email = fields.Email(required=True, validate=Length(min=3, max=50))
    password = fields.String(required=True, validate=Length(min=3, max=50))
Beispiel #23
0
class UpdateAdminInfoParse(BaseMarshmallow):
    password = fields.String(validate=[validate.str_range(8, 16)])
    password_ = fields.String(validate=[validate.str_range(8, 16)])
    nickname = fields.String(validate=[validate.str_range(0, 32)], missing="admin")
    remark = fields.String(validate=[validate.str_range(0, 255)])
    image_id = fields.Integer(validate=[validate.image_exist])
Beispiel #24
0
class AddPictureParse(BaseMarshmallow):
    description = fields.String()
    image_id = fields.Integer(validate=[validate.image_exist], required=True)
    picture_album_id = fields.Integer(
        validate=[validate.data_exist(PictureAlbum)], required=True)
Beispiel #25
0
class PictureAdminSchema(BaseMarshmallow):
    class Meta:
        fields = ("id", "description", "image", "update_time", "image_id")

    image = fields.String(attribute="image.url")
    update_time = fields.DateTime("%Y-%m-%d %H:%M")
Beispiel #26
0
class AddAlbumParse(BaseMarshmallow):
    title = fields.String(validate=[validate.str_range(0, 128)], required=True)
    description = fields.String()
    category_id = fields.Integer(validate=[validate.category_exist("picture")],
                                 required=True)
    cover_id = fields.Integer(validate=[validate.image_exist], required=True)
Beispiel #27
0
class AdminLoginParse(BaseMarshmallow):
    username = fields.String(validate=[validate.str_range(6, 16)], required=True)
    password = fields.String(validate=[validate.str_range(8, 16)], required=True)
Beispiel #28
0
class PictureAlbumListParse(BaseMarshmallow):
    page = fields.Integer(validate=[validate.positive], missing=1)
    rows = fields.Integer(validate=[validate.positive], missing=10)
    word = fields.String()
    category = fields.Integer(
        validate=[validate.category_exist(module="picture")])
Beispiel #29
0
class LoginSchema(Schema):
    email = fields.Email(required=True, validate=Length(min=3, max=50))
    password = fields.String(required=True, validate=Length(min=3, max=50))
    remember_me = fields.Boolean(required=False, default=False, missing=False)
Beispiel #30
0
class AdminInfoSchema(BaseMarshmallow):
    class Meta:
        fields = ("id", "username", "nickname", "remark", "image_id", "avatar")
    avatar = fields.String(attribute="image.url")