Exemple #1
0
class Ad(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    person_id = db.Column(db.Integer, db.ForeignKey('person.id'))
    person = db.relationship('Person', backref=db.backref('ads'))
    title = db.Column(db.String)
    info = db.Column(db.String)
    price = db.Column(db.Integer)
    city = db.Column(db.String)
    location = db.Column(db.String)
    email = fields.Email(load_only=True)
    phone = db.Column(db.String)
    pics = db.Column(db.ARRAY(db.String))

    category = db.Column(db.Enum(CategoryEnum))

    @hybrid_property
    def meta_category(self):
        mcat = null
        if ['car', 'moto', 'truck', 'stuff', 'heavy'].contains(self.category):
            mcat = 'vehicles'
        return mcat

    #Vehicle attrs
    year = db.Column(db.String)
    mile = db.Column(db.String)
    ##moto
    cylinder = db.Column(db.String)
    ##car && truck
    make = db.Column(db.String)
    model = db.Column(db.String)
    fuel = db.Column(db.String)
    drive = db.Column(db.String)
Exemple #2
0
class PersonSchema(Schema):
    class Meta:
        type_ = 'person'
        self_view = 'person_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'person_list'

    id = fields.Integer(as_string=True, dump_only=True)
    name = fields.String(required=True)
    email = fields.Email(load_only=True)
    display_name = fields.Function(
        lambda obj: "{} <{}>".format(obj.name.upper(), obj.email))
    computers = Relationship(
        self_view='person_computers',
        self_view_kwargs={'id': '<id>'},
        related_view='computer_list',
        related_view_kwargs={'id': '<id>'},
        many=True,
        schema='ComputerSchema',
        type_='computer',
    )

    @pre_load
    def remove_id_before_deserializing(self, data, **kwargs):
        """
        We don't want to allow editing ID on POST / PATCH

        Related issues:
        https://github.com/AdCombo/flask-combo-jsonapi/issues/34
        https://github.com/miLibris/flask-rest-jsonapi/issues/193
        """
        if 'id' in data:
            del data['id']
        return data
Exemple #3
0
class PersonSchema(Schema):
    class Meta:
        type_ = "person"
        self_view = "person_detail"
        self_view_kwargs = {"id": "<id>"}
        self_view_many = "person_list"

    id = fields.Integer(as_string=True, dump_only=True)
    first_name = fields.String(required=True)
    last_name = fields.String(required=True)
    full_name = fields.String(required=True, dump_only=True)
    email = fields.Email()
    computers = Relationship(
        nested="ComputerSchema",
        schema="ComputerSchema",
        self_view="person_detail",
        self_view_kwargs={"id": "<id>"},
        related_view="computer_list",
        many=True,
        type_="computer",
    )

    @pre_load
    def remove_id_before_deserializing(self, data, **kwargs):
        """
        We don't want to allow editing ID on POST / PATCH

        Related issues:
        https://github.com/AdCombo/flask-combo-jsonapi/issues/34
        https://github.com/miLibris/flask-rest-jsonapi/issues/193
        """
        if "id" in data:
            del data["id"]
        return data
Exemple #4
0
class UserSchemaPublic(SoftDeletionSchema):
    """
    Api schema for User Model which can be accessed by any resource to which user is related.
    Co-organizers of events to which the user will be related will have access to this info.
    """
    class Meta:
        """
        Meta class for User Api Schema
        """

        type_ = 'user'
        self_view = 'v1.user_detail'
        self_view_kwargs = {'id': '<id>'}
        inflect = dasherize

    id = fields.Str(dump_only=True)
    email = fields.Email(required=True)
    avatar_url = fields.Url(allow_none=True)
    first_name = fields.Str(allow_none=True)
    last_name = fields.Str(allow_none=True)
    original_image_url = fields.Url(dump_only=True, allow_none=True)
    thumbnail_image_url = fields.Url(dump_only=True, allow_none=True)
    small_image_url = fields.Url(dump_only=True, allow_none=True)
    icon_image_url = fields.Url(dump_only=True, allow_none=True)
    was_registered_with_order = fields.Boolean()
Exemple #5
0
class UsersSchema(Schema):

    not_blank = validate.Length(min=1, error='Field cannot be blank')
    # add validate=not_blank in required fields
    id = fields.Integer(dump_only=True)

    email = fields.Email(validate=not_blank)
    password = fields.String(validate=not_blank)
    name = fields.String(validate=not_blank)
    active = fields.Integer()
    classified = fields.Integer()
    in_queue = fields.Integer()
    creation_time = fields.DateTime(dump_only=True)
    modification_time = fields.DateTime(dump_only=True)
    role = fields.String(validate=not_blank)

    # self links
    def get_top_level_links(self, data, many):
        if many:
            self_link = "/users/"
        else:
            self_link = "/users/{}".format(data['id'])
        return {'self': self_link}

    class Meta:
        type_ = 'users'
Exemple #6
0
class UserEmailSchema(SoftDeletionSchema):
    """
    API Schema for user email Model
    """
    class Meta:
        """
        Meta class for user email API schema
        """
        type_ = 'user-email'
        self_view = 'v1.user_emails_detail'
        self_view_kwargs = {'id': '<id>'}
        inflect = dasherize

    id = fields.Str(dump_only=True)
    email_address = fields.Email(allow_none=False)
    type = fields.Str(
        allow_none=False,
        validate=validate.OneOf(
            choices=["home", "work", "business", "office", "other"]))
    user_id = fields.Integer(allow_none=False)
    user = Relationship(attribute='user',
                        self_view='v1.user_emails_user',
                        self_view_kwargs={'id': '<id>'},
                        related_view='v1.user_detail',
                        related_view_kwargs={'user_email_id': '<id>'},
                        schema='UserSchema',
                        type_='user')
Exemple #7
0
class UserSchema(Schema):
    class Meta:
        type_ = "user"
        self_view = "user_detail"
        self_view_kwargs = {"id": "<id>"}
        self_view_many = "user_list"
        strict = True

    id = fields.Integer(as_string=True, dump_only=True)
    name_first = fields.Str(required=True)
    name_last = fields.Str(required=True)
    email = fields.Email(required=True)
    zip = fields.Str(required=True)
class PersonSchema(Schema):
    class Meta:
        type_ = 'person'
        #self_view = 'person_detail'
        #self_view_kwargs = {'id': '<id>'}
        self_view_many = 'person_list'

    id = fields.Integer(as_string=True, dump_only=True)
    name = fields.Str(requried=True, load_only=True)
    email = fields.Email(load_only=True)
    #    birth_date = fields.Date()
    display_name = fields.Function(
        lambda obj: "{} <{}>".format(obj.name.upper(), obj.email))
class UsersSchema(Schema):
    not_blank = validate.Length(min=1, error='Field cannot be blank')
    id = fields.Integer(dump_only=True)
    email = fields.Email(validate=not_blank)
    name = fields.String(validate=not_blank)

    # self links
    def get_top_level_links(self, data, many):
        if many:
            self_link = "/users/"
        else:
            self_link = "/users/{}".format(data['id'])
        return {'self': self_link}

    class Meta:
        type_ = 'users'
Exemple #10
0
class UserSchema(BaseSchema):
    """
    Schema representing a :any:`User` resource.

    Attributes:
     id (``UUID``): User's id
     first_name (str): User's first name. If present must not be blank
     last_name (str): User's last name. If present must not be blank
     email (str): User's email. If present must be a valid email and not be blank
     password (str): User's password. If present must not be blank.
     admin (bool): wether the user is registered as admin or not

     orders (``Relationship``): field pointing to all the :any:`Order` created
        by the user.
     addresses (``Relationship``): field pointing to the user's :any:`Address` resources
    """
    class Meta:
        type_ = 'user'
        self_url_many = '/users/'
        self_url = '/users/{id}'
        self_url_kwargs = {'id': '<id>'}
        json_module = simplejson

    id = fields.Str(dump_only=True, attribute='uuid')
    first_name = fields.Str(required=True, validate=NOT_BLANK)
    last_name = fields.Str(required=True, validate=NOT_BLANK)
    email = fields.Email(required=True, validate=NOT_BLANK)
    password = fields.Str(required=True, validate=NOT_BLANK, load_only=True)
    admin = fields.Boolean(dump_only=True)

    orders = fields.Relationship(
        many=True,
        include_resource_linkage=True,
        type_='order',
        schema='OrderSchema',
        dump_only=True,
        id_field='uuid',
    )

    addresses = fields.Relationship(
        many=True,
        include_resource_linkage=True,
        type_='address',
        schema='AddressSchema',
        dump_only=True,
        id_field='uuid',
    )
Exemple #11
0
class DEPAccountSchema(Schema):
    """DEP Account Details"""
    class Meta:
        type_ = 'dep_accounts'
        self_view = 'dep_app.dep_account_detail'
        self_view_kwargs = {'dep_account_id': '<id>'}
        self_view_many = 'dep_app.dep_accounts_list'
        strict = True

    id = fields.Int(dump_only=True)

    # stoken
    consumer_key = fields.String()
    consumer_secret = fields.String(load_only=True)
    access_token = fields.String()
    access_secret = fields.String(load_only=True)
    access_token_expiry = fields.DateTime(dump_only=True)
    token_updated_at = fields.DateTime(dump_only=True)
    auth_session_token = fields.String(load_only=True)

    # org
    server_name = fields.String()
    server_uuid = fields.UUID()
    admin_id = fields.String()
    facilitator_id = fields.String()
    org_name = fields.String()
    org_email = fields.Email()
    org_phone = fields.String()
    org_address = fields.String()
    # urls = fields.Nested(MDMServiceURL, many=True)
    org_type = fields.String()
    org_version = fields.String()
    org_id = fields.String()
    org_id_hash = fields.String()
    url = fields.String()

    cursor = fields.String()
    more_to_follow = fields.Boolean()
    fetched_until = fields.DateTime()

    dep_profiles = Relationship(related_view='dep_app.dep_profile_detail',
                                related_view_kwargs={'dep_profile_id': '<id>'},
                                many=True,
                                include_resource_linkage=True,
                                schema='DEPProfileSchema',
                                type_='dep_profiles')
Exemple #12
0
class UsersSchema(Schema):
    not_blank = validate.Length(min=1, error='Field cannot be blank')
    id = fields.Integer(dump_only=True)
    username = fields.String(validate=not_blank)
    password = fields.String(validate=not_blank)
    email = fields.Email(validate=not_blank)
    age = fields.String()
    fullname = fields.String()

    movies = fields.Nested(MoviesSchema,
                           many=True,
                           only=('id', 'title', 'poster', 'year'),
                           dump_to='watchlist')

    class Meta:
        type_ = 'user'
        ordered = True
Exemple #13
0
class UserSchema(Schema):
    id = fields.String(dump_only=True, attribute='user_id')
    user_name = fields.String()
    email = fields.Email(dump_only=True)
    first_name = fields.String(allow_none=True)
    last_name = fields.String(allow_none=True)
    affiliation = fields.String(allow_none=True)
    url = fields.Url(allow_none=True)
    time_quota = Duration(dump_only=True)
    time_used = Duration(dump_only=True)
    disk_quota = DataSize(dump_only=True)
    disk_used = DataSize(dump_only=True)
    last_login = fields.LocalDateTime("%c", dump_only=True)
    date_joined = fields.LocalDateTime("%c", dump_only=True)

    class Meta:
        type_ = 'users'
Exemple #14
0
class UserSchema(Schema):
    class Meta:
        type_ = 'user'
        self_view = 'user_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'user_list'

    id = fields.Str(dump_only=True)  # write-only
    email = fields.Email(required=True)
    activated = fields.Boolean(required=True, default=False)

    role = Relationship(self_view='user_role',
                        self_view_kwargs={'id': '<id>'},
                        related_view='role_list',
                        related_view_kwargs={'id': '<id>'},
                        schema='RoleSchema',
                        type_='role')
Exemple #15
0
class UserSchema(Schema):
    """Flask-REST-JSONAPI: Logical data abstraction for User model"""
    class Meta:  # pylint: disable=too-few-public-methods
        """Define the details that come with HTTP Request"""
        type_ = 'user'
        # Note: For usage of api.user_details see this discussion:
        # https://github.com/miLibris/flask-rest-jsonapi/issues/35
        self_view = 'api.user_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'api.user_list'

    id = fields.Integer(as_string=True, dump_only=True)
    email = fields.Email(load_only=True)
    password = fields.Str(load_only=True)
    first_name = fields.Str()
    last_name = fields.Str()

    # Extra: a nicely formatted display name
    display_name = fields.Function(lambda obj: "{} {} <{}>".format(
        obj.first_name.upper(), obj.last_name.upper(), obj.email))
    # Extra: a message
    a_message = fields.Function(lambda obj: None if obj.confirmed else
                                'Please check your email to activate your '
                                'account.')

    # profile pic
    profile_pic = fields.Str(load_only=True)
    profile_pic_filename = fields.Str(load_only=True)
    profile_pic_url = fields.Str()

    categories = Relationship(self_view='api.user_categories',
                              self_view_kwargs={'id': '<id>'},
                              related_view='api.category_list',
                              related_view_kwargs={'id': '<id>'},
                              many=True,
                              schema='CategorySchema',
                              type_='category')

    items = Relationship(self_view='api.user_items',
                         self_view_kwargs={'id': '<id>'},
                         related_view='api.item_list',
                         related_view_kwargs={'id': '<id>'},
                         many=True,
                         schema='ItemSchema',
                         type_='item')
Exemple #16
0
class DEPProfileSchema(Schema):
    """marshmallow schema for a DEP profile.

    See Also:
          - `/profile endpoint <https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/MobileDeviceManagementProtocolRef/4-Profile_Management/ProfileManagement.html#//apple_ref/doc/uid/TP40017387-CH7-SW6>`_.
    """

    profile_name = fields.String(required=True)
    """str: A human-readable name for the profile."""
    url = fields.Url(required=True)
    """str: The URL of the MDM server."""
    allow_pairing = fields.Boolean(default=True)
    is_supervised = fields.Boolean(default=False)
    """bool: If true, the device must be supervised"""
    is_multi_user = fields.Boolean(default=False)
    """bool: If true, tells the device to configure for Shared iPad."""
    is_mandatory = fields.Boolean(default=False)
    """bool: If true, the user may not skip applying the profile returned by the MDM server"""
    await_device_configured = fields.Boolean()
    """bool: If true, Setup Assistant does not continue until the MDM server sends DeviceConfigured."""
    is_mdm_removable = fields.Boolean()
    """bool: If false, the MDM payload delivered by the configuration URL cannot be removed by the user via the user 
    interface on the device"""
    support_phone_number = fields.String()
    """str: A support phone number for the organization."""
    auto_advance_setup = fields.Boolean()
    """bool: If set to true, the device will tell tvOS Setup Assistant to automatically advance though its screens."""
    support_email_address = fields.Email()
    """str: A support email address for the organization."""
    org_magic = fields.String()
    """str: A string that uniquely identifies various services that are managed by a single organization."""
    anchor_certs = fields.List(fields.String())
    """List[str]: Each string should contain a DER-encoded certificate converted to Base64 encoding. If provided, 
    these certificates are used as trusted anchor certificates when evaluating the trust of the connection 
    to the MDM server URL."""
    supervising_host_certs = fields.List(fields.String())
    """List[str]: Each string contains a DER-encoded certificate converted to Base64 encoding. If provided, 
    the device will continue to pair with a host possessing one of these certificates even when allow_pairing 
    is set to false"""
    skip_setup_items = fields.Nested(SetupAssistantStep, many=True)
    """Set[SetupAssistantStep]: A list of setup panes to skip"""
    department = fields.String()
    """str: The user-defined department or location name."""
    devices = fields.List(fields.String())
Exemple #17
0
class PersonSchema(Schema):
    class Meta:
        type_ = 'person'
        self_view = 'person_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'person_list'

    id = fields.Str(dump_only=True)
    name = fields.Str(requried=True, load_only=True)
    email = fields.Email(load_only=True)
    birth_date = fields.Date()
    display_name = fields.Function(lambda obj: "{} <{}>".format(obj.name.upper(), obj.email))
    computers = Relationship(self_view='person_computers',
                             self_view_kwargs={'id': '<id>'},
                             related_view='computer_list',
                             related_view_kwargs={'id': '<id>'},
                             many=True,
                             schema='ComputerSchema',
                             type_='computer')
Exemple #18
0
class UserSchema(Schema):
    id = fields.Str()
    first_name = fields.Str()
    last_name = fields.Str()
    password = fields.Str(required=True,
                          validate=[validate.Length(min=6, max=36)],
                          load_only=True)
    email = fields.Email(
        allow_none=True,
        validate=validate.Email(error="Not a valid email address"))
    roles = fields.List(fields.String())
    active = fields.Boolean()
    created_at = fields.Date()

    class Meta:
        type_ = 'user'
        self_view = 'user_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'user_list'
Exemple #19
0
class UserSchema(Schema):
    class Meta:
        type_ = 'user'
        self_view = 'user_detail'
        self_view_kwargs = {'id': '<id>'}

    id = fields.Integer(as_string=True, dump_only=True)
    first_name = fields.Str(required=True, load_only=True)
    last_name = fields.Str(load_only=True)
    email = fields.Email(load_only=True)
    display_name = fields.Function(lambda obj: "{} {} <{}>".format(
        obj.first_name, obj.last_name, obj.email))
    client = Relationship(attribute='client',
                          self_view='user_client',
                          self_view_kwargs={'id': '<id>'},
                          related_view='client_detail',
                          related_view_kwargs={'user_id': '<id>'},
                          schema='ClientSchema',
                          type_='client')
Exemple #20
0
class UserSchema(Schema):

    id = fields.String(dump_only=True)
    username = ma.fields.String(required=True,
                                validator=ma.validate.Length(min=3, max=20))
    password = ma.fields.String(load_only=True,
                                required=True,
                                validator=ma.validate.Length(min=6, max=50))
    email = fields.Email(required=True)
    first_name = fields.String(title='first-name', required=True)
    last_name = fields.String(required=True)
    status = fields.String(requred=True, default='unregister')

    roles = fields.List(fields.String(), dump_only=True)

    class Meta:
        type_ = 'users'
        strict = True
        inflect = common.dasherize
Exemple #21
0
class DEPDeviceSchema(Schema):
    """The Device dictionary returned by the DEP Devices fetch endpoint.

    See Also:
          https://mdmenrollment.apple.com/server/devices
    """
    serial_number = fields.String()
    model = fields.String()
    description = fields.String()
    color = fields.String()
    asset_tag = fields.String()
    profile_status = fields.String()
    profile_uuid = fields.UUID()
    profile_assign_time = fields.DateTime()
    profile_push_time = fields.DateTime()
    device_assigned_date = fields.DateTime()
    device_assigned_by = fields.Email()
    os = fields.String()
    device_family = fields.String()
Exemple #22
0
class UserSchema(Schema):
    id = fields.String(dump_only=True, required=True)

    name = fields.String(required=True)
    password = fields.String(load_only=True, required=False, attribute="password_clear")
    new_password = fields.String(load_only=True, required=False)
    email = fields.Email(required=False)
    last_loggin = fields.String(required=False)
    privilege = fields.String(required=False)

    @post_load
    def make_user(self, data):
        return User(**data)

    def handle_error(self, exc, data):
        raise ValidationError('An error occurred with input: {0} \n {1}'.format(data, str(exc)))

    class Meta:
        type_ = 'users'
Exemple #23
0
class UserSchema(Schema):
    class Meta:
        type_ = 'users'
        self_view = 'user_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'user_list'

    id = fields.Integer(dump_only=True)
    created_at = fields.DateTime(dump_only=True)
    updated_at = fields.DateTime(dump_only=True)
    name = fields.String(required=True)
    email = fields.Email(required=True)
    password = fields.String(required=True, load_only=True)
    _role = fields.Integer(dump_only=True)
    status = fields.Integer(dump_only=True)
    friends = Relationship(self_view='user_friends',
                           self_view_kwargs={'id': '<id>'},
                           related_view='user_list',
                           related_view_kwargs={'user_id': '<id>'},
                           many=True,
                           schema='UserSchema',
                           type_='users')
    subscriptions = Relationship(self_view='user_subscriptions',
                                 self_view_kwargs={'id': '<id>'},
                                 related_view='subscription_list',
                                 related_view_kwargs={'user_id': '<id>'},
                                 many=True,
                                 schema='SubscriptionSchema',
                                 type_='subscriptions')
    posts = Relationship(self_view='user_posts',
                         self_view_kwargs={'id': '<id>'},
                         related_view='post_list',
                         related_view_kwargs={'user_id': '<id>'},
                         many=True,
                         schema='PostSchema',
                         type_='posts')
    comments = Relationship(self_view='user_comments',
                            self_view_kwargs={'id': '<id>'},
                            related_view='comment_list',
                            related_view_kwargs={'id': '<id>'},
                            many=True,
                            schema='CommentSchema',
                            type_='comments')
Exemple #24
0
class BookSchema(Schema):
    class Meta:
        type_ = 'book'
        self_view = 'book_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'book_list'

    id = fields.Integer(as_string=True, dump_only=True)
    name = fields.Str(required=True, load_only=True)
    email = fields.Email(load_only=True)
    publish_date = fields.Date()
    reviews = Relationship(
        self_view='book_reviews',
        self_view_kwargs={'id': '<id>'},
        related_view='review_list',
        related_view_kwargs={'id': '<id>'},
        many=True,
        schema='ReviewSchema',
        type_='review'
    )
class MailSchema(Schema):
    """
    Api schema for mail Model
    """
    class Meta:
        """
        Meta class for mail Api Schema
        """
        type_ = 'mail'
        self_view = 'v1.mail_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'v1.mail_list'
        inflect = dasherize

    id = fields.Str(dump_only=True)
    recipient = fields.Email(dump_only=True)
    time = fields.DateTime(dump_only=True)
    action = fields.Str(dump_only=True)
    subject = fields.Str(dump_only=True)
    message = fields.Str(dump_only=True)
Exemple #26
0
class UserSchema(Schema):
    class Meta:
        type_ = 'user'
        self_url = 'user_detail'
        self_url_kwargs = {'id': '<id>'}
        self_url_many = 'user_list'

    id = fields.Integer(as_string=True)
    username = fields.String(allow_none=False, required=True)
    email = fields.Email(allow_none=False, required=True)
    is_staff = fields.Boolean(allow_none=False)

    author = Relationship(
        nested='AuthorSchema',
        attribute='author',
        related_url='author_detail',
        related_url_kwargs={'id': '<id>'},
        schema='AuthorSchema',
        type_='author',
        many=False,
    )
Exemple #27
0
class UserSchema(Schema):
    class Meta:
        type_ = 'user'
        self_view = 'user_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'user_list'

    id = fields.Integer(as_string=True, dump_only=True)
    first_name = fields.Str(required=True)
    last_name = fields.Str(required=True)
    # Change "email_address" to this to make it read-only (won't be exposed in GET responses).
    # email_address = fields.Email(required=True, load_only=True)
    email_address = fields.Email(required=True)
    zip_code = fields.Str(required=True)
    exams = Relationship(self_view='user_exams',
                         self_view_kwargs={'id': '<id>'},
                         related_view='exam_list',
                         related_view_kwargs={'id': '<id>'},
                         many=True,
                         schema='ExamSchema',
                         type_='exam')
class PersonSchema(Schema):
    class Meta:
        type_ = "person"
        self_view = "person_detail"
        self_view_kwargs = {"id": "<id>"}
        self_view_many = "person_list"

    id = fields.Integer(as_string=True, dump_only=True)
    name = fields.Str(required=True, load_only=True)
    email = fields.Email(load_only=True)
    birth_date = fields.Date()
    display_name = fields.Function(
        lambda obj: f"{obj.name.upper()} <{obj.email}>")
    computers = Relationship(
        self_view="person_computers",
        self_view_kwargs={"id": "<id>"},
        related_view="computer_list",
        related_view_kwargs={"id": "<id>"},
        many=True,
        schema="ComputerSchema",
        type_="computer",
    )
Exemple #29
0
class UsersSchema(Schema):

    #not_blank = validate.Length(min=1, error='Field cannot be blank')
    id = fields.Str(dump_only=True)
    name = fields.String()
    email = fields.Email()
    address = fields.String()
    website = fields.URL()
    creation_date = fields.DateTime()
    is_active = fields.Boolean()
    mobile = fields.Integer()
    Birthday = fields.Date()
    
    #self links
    def get_top_level_links(self, data, many):
        if many:
            self_link = "/users/"
        else:
            self_link = "/users/{}".format(data['id'])
        return {'self': self_link}

    class Meta:
        type_ = 'users'
Exemple #30
0
class UserSchema(UserSchemaPublic):

    # class Meta(UserSchemaPublic.Meta):
    #     pass

    @validates('name')
    def validate_username_uniqueness(self, data):
        if User.query.filter_by(name=data).count():
            raise UnprocessableEntity({'pointer': '/data/attributes/name'},
                                      "Username already taken")

    @validates('email')
    def validate_email_uniqueness(self, data):
        if User.query.filter_by(email=data).count():
            raise UnprocessableEntity({'pointer': '/data/attributes/email'},
                                      "Email already taken")

    class Meta:
        type_ = 'user'
        self_view = 'v1.user_details'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'v1.users_list'
        inflect = dasherize
        ordered = True

    email = fields.Email(required=True)
    password = fields.Str(load_only=True, required=True)
    latitude = fields.Float()
    longitude = fields.Float()
    daily_mails = fields.Boolean()
    observation_radius = fields.Integer()
    hour = fields.Integer(dump_only=True)
    secid = fields.Str()
    statpic_id = fields.Integer()
    last_update_date_time = fields.Date(dump_only=True)
    last_mail_date_time = fields.Date(dump_only=True)
    last_login_date_time = fields.Date(dump_only=True)