Beispiel #1
0
class UserSchema(Schema):
    username = fields.String()
    password = fields.String(validate=lambda n: len(n) >= 5)

    @post_load
    def make_object(self, data):
        return User(**data)
Beispiel #2
0
class UpdateUserSchema(Schema):
    first_name = fields.String(required=True, validate=validate.Length(1, 50))
    last_name = fields.String(required=True, validate=validate.Length(1, 50))
    email = fields.Email(required=True)
    enabled = fields.Boolean(required=True)

    @post_load
    def make_object(self, data):
        return User(**data)
Beispiel #3
0
class UserSchema(Schema):
    id = fields.Integer(dump_only=True)
    email = fields.String(required=True)
    password = fields.String(required=True)
    enabled = fields.Boolean(dump_only=True)
    updated_at = fields.DateTime(dump_only=True)
    created_at = fields.DateTime(dump_only=True)

    @post_dump
    def make_object(self, data):
        return User(**data)
Beispiel #4
0
class UserSchema(Schema):
    username = fields.String(required=True, validate=validate.Length(5, 30))
    first_name = fields.String(required=True, validate=validate.Length(1, 50))
    last_name = fields.String(required=True, validate=validate.Length(1, 50))
    email = fields.Email(required=True)
    enabled = fields.Boolean(required=True)
    created_at = fields.DateTime(dump_only=True)

    @post_load
    def make_object(self, data):
        return User(**data)
class CompanySchema(Schema):
    id = fields.Integer(dump_only=True)
    name = fields.String(required=True)
    country_code = fields.String(required=True)
    website = fields.String(allow_none=True)
    enabled = fields.Boolean(required=True)
    updated_at = fields.DateTime(dump_only=True)
    created_at = fields.DateTime(dump_only=True)

    @post_load
    def make_object(self, data):
        return Company(**data)
Beispiel #6
0
class AppointmentSchema(Schema):
    """
    Appointment Schema
    """

    id = fields.Integer(dump_only=True)
    client_name = fields.String(required=True)
    request_date = fields.Date(required=False)
    appointment_date = fields.Date(required=False)
    appointment_time = fields.Time(required=False)
    preferred_clinician = fields.String(required=True)
    appointment_reason = fields.String(required=True)
Beispiel #7
0
class ImageSchema(Schema):
    id = fields.Integer(dump_only=True)
    height = fields.Integer(required=True)
    width = fields.Integer(required=True)
    time = fields.Integer(required=True)
    timestamp = fields.DateTime(dump_only=True)
    pic_num = fields.Integer(required=True)
    filename = fields.String(dump_only=True)
    image_path = fields.String(required=True, load_only=True)

    @pre_dump
    def _pre_dump(self, obj):
        obj.timestamp = obj.time
Beispiel #8
0
class TesterSchema(Schema):
    id = fields.Integer(dump_only=True)
    test_id = fields.Integer(required=True)
    time = fields.DateTime(required=True)
    phone_manufacturer = fields.String(required=True)
    phone_model = fields.String(required=True)
    phone_screen_height = fields.String(required=True)
    phone_screen_width = fields.String(required=True)
    images_count = fields.Integer(dump_only=True)
    images = fields.Nested(ImageSchema, many=True, dump_only=True)

    @post_load
    def _make_object(self, data):
        return Tester(**data)
Beispiel #9
0
class IoTSchema(Schema):
    id = fields.Integer(dump_only=True)
    hmt = fields.String(allow_none=True)
    tmp = fields.String(allow_none=True)
    ppm = fields.String(allow_none=True)
    lx = fields.String(allow_none=True)
    ld = fields.String(allow_none=True)
    time = fields.String(required=True)
    date = fields.String(required=True)
    timestamp = fields.String(required=True)
    device  = fields.String(required=False)

    @post_dump
    def make_object(self, data):
        return IoTs(**data)
Beispiel #10
0
class ContactSchema(Schema):
    """
    serialization-deserialization-validation class for Contacts.
    """
    id = fields.UUID(dump_only=True)
    first_name = fields.String(50, required=True)
    surname = fields.String(50, required=True)
    username = fields.String(required=True, validator=validate_username,
                             error_messages={'validator_failed':
                                             {'message': 'Username must be 6-52 characters length and'
                                                         ' can only contain: a-zA-Z0-9.'}})
    inserted = fields.DateTime(dump_only=True)
    emails = fields.Nested(EmailSchema, exlude=('contact_id',), many=True)

    @post_load
    def _post_load(self, data):
        if self.partial:
            return data
        return Contact(**data)
Beispiel #11
0
class ProblemSchema(Schema):
    id = fields.Integer(dump_only=True)
    question = fields.String(required=True)
    answer = fields.String(required=True)
    distraction1 = fields.String(required=False)
    distraction2 = fields.String(required=False)
    distraction3 = fields.String(required=False)
    distraction4 = fields.String(required=False)
    distraction5 = fields.String(required=False)

    @post_dump
    def make_object(self, data):
        return data
Beispiel #12
0
class ContactSchema(Schema):
    """
    serialization-deserialization-validation class for Contacts.
    """
    id = fields.UUID(dump_only=True)
    first_name = fields.String(50, required=True)
    surname = fields.String(50, required=True)
    username = fields.String(
        required=True,
        validator=validate_username,
        error_messages={
            'validator_failed': {
                'message':
                'Username must be 6-52 characters length and'
                ' can only contain: a-zA-Z0-9.'
            }
        })
    email = fields.Email(required=True, validate=validate.Length(5, 128))

    @post_load
    def _post_load(self, data):
        if self.partial:
            return data
        return Contact(**data)
Beispiel #13
0
    def test_strip(self):
        field = fields.String(strip=True)
        self.assertEqual('b', field.deserialize(' b '))

        field = fields.String(allow_none=True, none_if_empty=True, strip=True)
        self.assertIsNone(field.deserialize(' '))
Beispiel #14
0
    def test_none_if_empty(self):
        field = fields.String(none_if_empty=True)
        self.assertRaises(ValidationError, field.deserialize, '')

        field = fields.String(allow_none=True, none_if_empty=True)
        self.assertIsNone(field.deserialize(''))
Beispiel #15
0
    def test_allow_empty(self):
        field = fields.String()
        self.assertEqual('', field.deserialize(''))

        field = fields.String(allow_empty=False)
        self.assertRaises(ValidationError, field.deserialize, '')
Beispiel #16
0
class FilterSchema(Schema):
    search = fields.String(required=False)
    sort = fields.String(required=False)
    limit = fields.Integer(required=False)
    page_start = fields.Integer(required=False)
    return io.no_content()


@app.route('/<int:id>', methods=['GET'])
@io.marshal_with(CompanySchema)
def get_company(id):
    company = Company.query.filter_by(id=id).first()

    if not company:
        return io.not_found('Company not found: ' + str(id))

    return company


@app.route('/', methods=['GET'])
@io.from_query('name', fields.String())
@io.from_query('order_by', fields.String(missing='name'))
@io.from_query('offset', fields.Integer(missing=0))
@io.from_query('limit', fields.Integer(missing=10))
@io.marshal_with(CompanySchema)
def list_companies(name, order_by, offset, limit):
    query = Company.query

    if name:
        query = query.filter(
            func.lower(Company.name).contains(func.lower(name)))
    if order_by:
        query = sort_query(query, order_by)
    if offset:
        query = query.offset(offset)
    if limit:
Beispiel #18
0
class PatchUserSchema(Schema):
    first_name = fields.String(validate=validate.Length(1, 50))
    last_name = fields.String(validate=validate.Length(1, 50))
    email = fields.Email()
    enabled = fields.Boolean()
Beispiel #19
0
class VideoSchema(Schema):
    id = fields.Integer(dump_only=True)
    tester_id = fields.Integer(dump_only=True)
    duration = fields.Integer(dump_only=True)
    time = fields.DateTime(dump_only=True)
    filename = fields.String(dump_only=True)
Beispiel #20
0
 def test_strip(self):
     field = fields.String(strip=True)
     self.assertEqual('b', field.deserialize(' b '))
Beispiel #21
0

@app.route('/users', methods=['POST'])
@io.from_body('user', UserSchema)
@io.marshal_with(UserSchema)
def add_user(user):
    if store.get(user.username):
        return io.conflict('User already exists: ' + user.username)

    user.created_at = datetime.now()
    store[user.username] = user
    return user


@app.route('/users')
@io.from_query('username', fields.String())
@io.from_query('max_results', fields.Integer(missing=10))
@io.marshal_with(UserSchema)
def get_users(username, max_results):
    users = list(store.values())

    if username:
        users = [user for user in users if user.username.find(username) > -1]

    return users[:max_results]


@app.route('/users/<username>', methods=['POST'])
@io.from_body('new_user', UpdateUserSchema)
@io.marshal_with(UserSchema)
def update_user(username, new_user):
Beispiel #22
0
class UserSchema(Schema):
    username = fields.String()
    password = fields.String()
Beispiel #23
0
 def test_only_numeric(self):
     field = fields.String(only_numeric=True)
     self.assertEqual('12345', field.deserialize('12345'))
     self.assertRaises(ValidationError, field.deserialize, 'abcde')
Beispiel #24
0
    return jsonify(result=g.current_user)


@app.route('/<int:id>', methods=['GET'])
@io.marshal_with(UserSchema)
def get_user(id):
    user = User.query.with_entities(User.id, User.email, User.created_at,
                                    User.enabled).filter_by(id=id).first()
    if not user:
        return io.not_found('User not found: ' + str(id))

    return jsonify(result=user)


@app.route('/', methods=['GET'])
@io.from_query('email', fields.String())
@io.from_query('order_by', fields.String(missing='email'))
@io.from_query('offset', fields.Integer(missing=0))
@io.from_query('limit', fields.Integer(missing=10))
@io.marshal_with(UserSchema)
def list_users(email, order_by, offset, limit):
    query = User.query.with_entities(User.id, User.email, User.created_at,
                                     User.enabled)

    if email:
        query = query.filter(
            func.lower(User.email).contains(func.lower(email)))
    if order_by:
        query = sort_query(query, order_by)
    if offset:
        query = query.offset(offset)
Beispiel #25
0
 def test_upper(self):
     field = fields.String(upper=True)
     self.assertEqual('ABC', field.deserialize('abc'))
Beispiel #26
0
        'page': page,
        'entries_per_page': entries_per_page,
        'num_pages': num_entries // entries_per_page + 1,
        'num_entries': num_entries
    }


#-------------------#
# Work API Requests #
#-------------------#


@app.route('/work/', methods=['GET'])
@io.from_query('page', fields.Integer(missing=1))
@io.from_query('entries_per_page', fields.Integer(missing=25))
@io.from_query('order_by', fields.String(missing="name"))
@io.from_query('order', fields.String(missing="ascending"))
@io.from_query('startswith', fields.String(missing=None))
@io.from_query('art_type', fields.String(missing=None))
@io.from_query('medium', fields.String(missing=None))
@io.from_query('venue', fields.String(missing=None))
def get_works(page, entries_per_page, **kwargs):
    """
    API GET request for all works of art in the database
    """
    works = Work.query

    # order results according to passed arguments
    if kwargs['order_by']:
        if kwargs['order'] == 'ascending':
            works = works.order_by(getattr(Work, kwargs['order_by']))