Example #1
0
class NotificationSettingsSchema(ma.Schema):
    class Meta:
        ordered = True
        notification_modes = ['off', 'email', 'push']

    innostore = ma.Str(validate=validate.OneOf(Meta.notification_modes))
    volunteering = ma.Str(validate=validate.OneOf(Meta.notification_modes))
    project_creation = ma.Str(validate=validate.OneOf(Meta.notification_modes))
    administration = ma.Str(validate=validate.OneOf(Meta.notification_modes))
    service = ma.Str(validate=validate.OneOf(Meta.notification_modes))
Example #2
0
class ProductSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Product
        load_instance = True
        ordered = True
        include_relationships = True

    varieties = ma.Nested('VarietySchema',
                          many=True,
                          validate=validate.Length(min=1))
    name = ma.Str(validate=validate.Length(min=1, max=128))
    type = ma.Str(validate=validate.Length(min=1, max=128), allow_none=True)
    description = ma.Str(validate=validate.Length(max=1024))
    price = ma.Int(validate=validate.Range(min=1))
Example #3
0
class TimelineSchema(ma.Schema):
    class Meta:
        ordered = True

    entry_time = ma.DateTime(timezone=True)
    type = ma.Str()
    payload = ma.Dict()
Example #4
0
class ApplicationSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Application
        load_instance = True
        ordered = True
        include_relationships = True

    status = EnumField(ApplicationStatus)
    applicant = ma.Nested('AccountSchema', only=('full_name', 'email'))
    feedback = ma.Nested('FeedbackSchema', exclude=('time', ))
    reports = ma.Nested('VolunteeringReportSchema', many=True)
    telegram_username = ma.Str(data_key='telegram')
Example #5
0
class VolunteeringReportSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = VolunteeringReport
        load_instance = True
        ordered = True
        include_fk = True
        include_relationships = True

    reporter_email = ma.Str(dump_only=True)
    application_id = ma.Int(dump_only=True)
    application = ma.Nested('ApplicationActivitySchema',
                            data_key='application_on')
    rating = ma.Int(validate=validate.Range(min=1, max=5))
Example #6
0
class PayloadSchema(ma.Schema):
    project = ma.Nested('ProjectSchema',
                        only=('id', 'name', 'review_status', 'lifetime_stage',
                              'image_id'))
    activity = ma.Nested('ActivitySchema',
                         only=('id', 'name', 'internal', 'reward_rate'))
    product = ma.Nested('ProductSchema', only=('id', 'name', 'type', 'price'))
    variety = ma.Nested('VarietySchema',
                        only=('id', 'size', 'color', 'images'))
    account = ma.Nested('AccountSchema', only=('email', 'full_name'))
    application = ma.Nested('ApplicationSchema',
                            only=('id', 'status', 'actual_hours'))
    stock_change = ma.Nested('StockChangeSchema',
                             only=('id', 'amount', 'status'))
    transaction = ma.Nested('TransactionSchema', only=('id', 'change'))
    message = ma.Str()

    @pre_dump
    def fill_data(self, data, **_kwargs):
        if 'project_id' in data:
            data['project'] = Project.query.get(data.pop('project_id'))
        if 'activity_id' in data:
            data['activity'] = Activity.query.get(data.pop('activity_id'))
        if 'product_id' in data:
            data['product'] = Product.query.get(data.pop('product_id'))
        if 'variety_id' in data:
            data['variety'] = Variety.query.get(data.pop('variety_id'))
        if 'account_email' in data:
            data['account'] = Account.query.get(data.pop('account_email'))
        if 'application_id' in data:
            data['application'] = Application.query.get(
                data.pop('application_id'))
        if 'stock_change_id' in data:
            data['stock_change'] = StockChange.query.get(
                data.pop('stock_change_id'))
        if 'transaction_id' in data:
            data['transaction'] = Transaction.query.get(
                data.pop('transaction_id'))
        return data
Example #7
0
class FeedbackSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Feedback
        load_instance = True
        ordered = True
        include_relationships = True
        exclude = ('transaction', )

    @pre_load
    def wrap_competences(self, data, **_kwargs):
        """Turn a flat list of competence IDs into a list of objects."""
        data['competences'] = [{
            'id': comp_id
        } for comp_id in data['competences']]
        return data

    @validates('competences')
    def ensure_competence_amount(self, competences):
        if len(competences) not in range(1, 4):
            raise ValidationError('Must include 1-3 competences.')

    answers = ma.List(ma.Str(), required=True)
Example #8
0
class ProjectSchema(ma.SQLAlchemyAutoSchema):
    class Meta:
        model = Project
        load_instance = True
        ordered = True
        include_relationships = True

    name = ma.Str(allow_none=True,
                  validate=validate.Length(max=128),
                  error_messages={
                      'validator_failed':
                      'The name must be below 128 characters.'
                  })
    creator = ma.Nested('AccountSchema', only=('full_name', 'email'))
    image_id = ma.Int(allow_none=True)
    review_status = EnumField(ReviewStatus)
    lifetime_stage = EnumField(LifetimeStage)
    activities = ma.Nested('ActivitySchema', many=True)
    moderators = ma.Nested('AccountSchema',
                           only=('full_name', 'email'),
                           many=True)
    start_date = ma.DateTime()
    end_date = ma.DateTime()