Ejemplo n.º 1
0
class ProfileSchema(Schema):
    class Meta:
        type_ = 'profiles'
        self_view = 'profiles_api.profile_detail'
        self_view_kwargs = {'profile_id': '<id>'}
        self_view_many = 'profiles_api.profiles_list'

    id = fields.Int(dump_only=True)
    data = fields.String()

    description = fields.Str()
    display_name = fields.Str()
    expiration_date = fields.DateTime()
    identifier = fields.Str()
    organization = fields.Str()
    uuid = fields.UUID()
    removal_disallowed = fields.Boolean()
    version = fields.Int()
    scope = fields.Str()
    removal_date = fields.DateTime()
    duration_until_removal = fields.Int()
    consent_en = fields.Str()

    tags = Relationship(related_view='api_app.tag_detail',
                        related_view_kwargs={'tag_id': '<id>'},
                        many=True,
                        schema='TagSchema',
                        type_='tags')
Ejemplo n.º 2
0
class ReportSchema(Schema):
    id = fields.Int()
    height = fields.Int()
    spotName = fields.Str()
    regionName = fields.Str()
    windDirection = fields.List(fields.Int())
    windSpeed = fields.List(fields.Float())
    tide = fields.Float()
    waterTempMin = fields.Float()
    waterTempMax = fields.Float()

    class Meta:
        type_ = 'reports'

    @pre_load()
    def before_load(self, data):
        # TODO: remove the land mines. eg accessing a list
        # when it might be an object.
        result = {}
        result['height'] = data.get('Sort', {}).get('height_max')
        result['id'] = data.get('Quickspot', {}).get('spotid')
        result['spotName'] = data.get('Quickspot', {}).get('spotname')
        result['regionName'] = data.get('Quickspot', {}).get('regionname')
        result['windDirection'] = data.get('Wind', {}).get('wind_direction')[0]
        result['windSpeed'] = data.get('Wind', {}).get('wind_speed')[0]
        result['tide'] = data.get('Tide', {}).get('dataPoints')[0]['height']
        result['waterTempMin'] = data.get('WaterTemp', {}).get('watertemp_min')
        result['waterTempMax'] = data.get('WaterTemp', {}).get('watertemp_max')
        return result
class OutletTypeSchema(Schema):
    id = fields.Integer(dump_only=True)
    name = fields.String(allow_none=True)
    voltage = fields.Int()
    amperage = fields.Int()
    last_modified_dt = fields.DateTime()

    class Meta:
        type_ = 'outlet-type',
        strict = 'true'
Ejemplo n.º 4
0
class AdminReportSchema(Schema):
    class Meta:
        type_ = 'admin-reports'

    id = fields.Date(required=True, dump_only=True)
    mailSentCount = fields.Int(as_string=True)
    badgeCount = fields.Int(as_string=True)
    badgeDeletionCount = fields.Int(as_string=True)
    userCreationCount = fields.Int(as_string=True)
    userDeletionCount = fields.Int(as_string=True)
Ejemplo n.º 5
0
class PlacementPeriod(Schema):
    id = fields.String(dump_only=True, attribute='placement_id')
    start = fields.String()
    end = fields.DateTime()
    cmp = fields.Int()
    delivery = fields.List(fields.Nested(Delivery))
    budget = fields.Int()

    class Meta:
        type_ = 'placement_period'
class RackUnitSchema(Schema):
    id = fields.Integer(dump_only=True)
    ru_start = fields.Int()
    ru_end = fields.Int()
    last_modified_dt = fields.DateTime()

    rack = Relationship(
        schema=RackSchema,
        include_resource_linkage=True,
        type_='rack'
    )

    class Meta:
        type_ = 'rack-unit'
        strict = True
class ErrorSchema(Schema):
    code = fields.Int(required=True)
    detail = fields.Str(required=True, attribute='description')

    class Meta:
        type_ = 'error'
        strict = True
Ejemplo n.º 8
0
class Delivery(Schema):
    id = fields.String(dump_only=True, attribute='placement_id')
    date = fields.DateTime()
    impressions = fields.Int()

    class Meta:
        type_ = 'delivery'
class CircuitSchema(Schema):
    id = fields.Int(dump_only=True)
    voltage = fields.Int(allow_none=True)
    amperage = fields.Int(allow_none=True)
    power_rating = fields.Int(allow_none=True)
    last_modified_dt = fields.DateTime()

    rack = Relationship(
        schema=RackSchema,
        include_resource_linkage=True,
        type_='rack'
    )

    class Meta:
        type_ = 'circuit'
        strict = True
Ejemplo n.º 10
0
class AvailableOSUpdateSchema(Schema):
    class Meta:
        type_ = 'available_os_updates'
        self_view = 'api_app.available_os_update_detail'
        self_view_kwargs = {'available_os_update_id': '<id>'}
        self_view_many = 'api_app.available_os_updates_list'

    id = fields.Int(dump_only=True)
    allows_install_later = fields.Boolean()
    #  app_identifiers_to_close = fields.List(fields.String())
    human_readable_name = fields.Str()
    human_readable_name_locale = fields.Str()
    is_config_data_update = fields.Boolean()
    is_critical = fields.Boolean()
    is_firmware_update = fields.Boolean()
    metadata_url = fields.URL()
    product_key = fields.String()
    restart_required = fields.Boolean()
    version = fields.String()

    device = Relationship(
        related_view='api_app.device_detail',
        related_view_kwargs={'device_id': '<device_id>'},
        type_='devices',
    )
Ejemplo n.º 11
0
class ItemSchema(BaseSchema):
    """
    Schema describing the Item resources.

    Attributes:
        id (``UUID``): Item's ID
        name (str): Item's name
        price (float): Single item price
        description (str): Item's description
        availability (int): Quantity of items of this type available in the store

        pictures (``Relationship``):list of :any:`Picture` related to the
            Currently parsed `Item`. If included it will attach all the
            pictures information within the `included` attribute of the generated json.
    """
    class Meta:
        type_ = 'item'
        self_url = '/items/{id}'
        self_url_kwargs = {'id': '<id>'}
        self_url_many = '/items/'

    id = fields.Str(dump_only=True, attribute='uuid')
    name = fields.Str(required=True, validate=NOT_BLANK)
    price = fields.Float(required=True, validate=MORE_THAN_ZERO)
    description = fields.Str(required=True, validate=NOT_BLANK)
    availability = fields.Int(required=True, validate=MORE_THAN_ZERO)
    category = fields.Str(required=True, validate=NOT_BLANK)

    pictures = fields.Relationship(
        include_resource_linkage=True,
        type_='picture',
        schema='PictureSchema',
        id_field='uuid',
        many=True,
    )
Ejemplo n.º 12
0
        class InvalidFlaskMetaSchema(Schema):
            id = fields.Int()

            class Meta:
                type_ = "posts"
                self_view = "wrong_view"
                self_view_kwargs = {"post_id": "<id>"}
Ejemplo n.º 13
0
        class InvalidFlaskMetaSchema(Schema):
            id = fields.Int()

            class Meta:
                type_ = 'posts'
                self_view = 'wrong_view'
                self_view_kwargs = {'post_id': '<id>'}
Ejemplo n.º 14
0
            class InvalidFlaskMetaSchema(Schema):
                id = fields.Int()

                class Meta:
                    type_ = 'posts'
                    self_url = '/posts/{id}'
                    self_url_kwargs = {'post_id': '<id>'}
Ejemplo n.º 15
0
class UserSchema(Schema):
    class Meta:
        sqla_session = db.session
        model = user_models.User
        type_ = "users"
        self_view = "rest_api.user"
        self_view_kwargs = {"id": "<id>"}

    id = f.Int(attribute="user_id",
               required=False,
               allow_none=True,
               as_string=True)
    username = f.String()
    email = f.String()
    salt = f.String()
    password = f.String()
    created_at = f.DateTime()
    first_name = f.String()
    last_name = f.String()
    active = f.Boolean()
    admin = f.Boolean(attribute="is_admin")
    api_token = f.String()

    reports = Relationship(
        related_view="rest_api.user_reportlist",
        related_view_kwargs={"id": "<user_id>"},
        many=True,
        type_="reports",
        required=False,
        schema="ReportSchema",
    )
Ejemplo n.º 16
0
        class RefSchema(Schema):
            id = fields.Int()
            data = fields.Str()
            parent = fields.Relationship(schema='self', many=False)

            class Meta:
                type_ = 'refs'
Ejemplo n.º 17
0
class OrderItemSchema(BaseSchema):
    """
    Schema for representing OrderItem instances but pointing to the related ``Item``
    resources.

    The output generated by the schema takes values from :any:`models.OrderItem`
    - `quantity` and `subtotal` as well as from the related :any:`models.Item`
    to generate a consistent and complete data structure.

    Links generated from the Schema Meta class point to the Item resource, since
    that the :any:`models.OrderItem` does not have a direct resource.

    Attributes:
        id (``UUID``): ID of the related **Item**
        name (str): Item's name
        description (str): Item's description
        price (float): Item's price
        quantity (int): Quantity of item's of this type included in the order
        subtotal (float): Subtotal for all the items of this type in the order
    """
    class Meta:
        type_ = 'order_item'
        self_url = '/items/{uuid}'
        self_url_kwargs = {'uuid': '<id>'}
        self_url_many = '/items/'
        json_module = simplejson

    id = fields.Str(dump_only=True, attribute='item.uuid')
    name = fields.Str(attribute='item.name')
    description = fields.Str(attribute='item.description')
    price = fields.Float(attribute='item.price')
    quantity = fields.Int()
    subtotal = fields.Float()
Ejemplo n.º 18
0
class PostSchema(Schema):
    id = fields.Int()
    post_title = fields.Str(attribute='title', dump_to='title')

    author = fields.Relationship('http://test.test/posts/{id}/author/',
                                 related_url_kwargs={'id': '<id>'},
                                 schema=AuthorSchema,
                                 many=False,
                                 type_='people')

    post_comments = fields.Relationship(
        'http://test.test/posts/{id}/comments/',
        related_url_kwargs={'id': '<id>'},
        attribute='comments',
        load_from='post-comments',
        dump_to='post-comments',
        schema='CommentSchema',
        many=True,
        type_='comments')

    post_keywords = fields.Relationship(
        'http://test.test/posts/{id}/keywords/',
        related_url_kwargs={'id': '<id>'},
        attribute='keywords',
        dump_to='post-keywords',
        schema='KeywordSchema',
        many=True,
        type_='keywords')

    class Meta:
        type_ = 'posts'
Ejemplo n.º 19
0
            class InvalidFlaskMetaSchema(Schema):
                id = fields.Int()

                class Meta:
                    type_ = "posts"
                    self_url = "/posts/{id}"
                    self_url_kwargs = {"post_id": "<id>"}
Ejemplo n.º 20
0
class CommandResult(Schema):
    id = fields.Str(dump_only=True)
    exitCode = fields.Int()
    stdout = fields.Str()

    class Meta:
        type_ = 'pppoe_command_status'
        strict = True
Ejemplo n.º 21
0
    class AuthorSchemaWithInflection(Schema):
        id = fields.Int(dump_only=True)
        first_name = fields.Str(required=True, validate=validate.Length(min=2))
        last_name = fields.Str(required=True)

        class Meta:
            type_ = 'people'
            inflect = dasherize
Ejemplo n.º 22
0
class PhysicalReqSchema(Schema):
    id = fields.Int(dump_only=True)
    name = fields.String()
    model = fields.String()
    vendor = fields.String()
    part_number = fields.String()
    procs = fields.Int(allow_none=True)
    description = fields.String(allow_none=True)
    sfp_type = fields.String()
    power_draw = fields.String()
    network_ports = fields.Int()
    mgmt_ports = fields.Int()
    group = fields.String(allow_none=True)  # Todo: replace with a team relationship
    ram = fields.Int(allow_none=True)
    storage = fields.Int(allow_none=True)
    vm_count = fields.Int(allow_none=True)
    hypervisor = fields.String(allow_none=True)
    env = fields.String(allow_none=True)

    team = Relationship(
        schema=TeamSchema,
        type_='team',
        include_resource_linkage=True
    )

    location = Relationship(
        schema=LocationSchema,
        type_='location',
        include_resource_linkage=True
    )

    class Meta:
        strict = True
        type_ = 'bm-req'
        inflect = dasherize
Ejemplo n.º 23
0
class PrivateKeySchema(Schema):
    class Meta:
        type_ = 'private_keys'
        self_view = 'api_app.private_key_detail'
        self_view_kwargs = {'private_key_id': '<id>'}
        strict = True

    id = fields.Int(dump_only=True)
    pem_key = fields.Str()
Ejemplo n.º 24
0
    class PostFlaskSchema(Schema):
        id = fields.Int()
        title = fields.Str()

        class Meta:
            type_ = "posts"
            self_view = "post_detail"
            self_view_kwargs = {"post_id": "<id>"}
            self_view_many = "posts"
Ejemplo n.º 25
0
class VMSchema(Schema):
    id = fields.Int()
    hostname = fields.String()
    vcpu = fields.Int()
    ram = fields.Int()
    storage = fields.Int()
    role = fields.String()
    environment = fields.String()
    cluster = fields.String()

    location = Relationship(schema=LocationSchema,
                            include_resource_linkage=True,
                            type_='location')

    class Meta:
        type_ = 'vm'
        strict = True
        inflect = dasherize
Ejemplo n.º 26
0
    class PostFlaskSchema(Schema):
        id = fields.Int()
        title = fields.Str()

        class Meta:
            type_ = 'posts'
            self_view = 'post_detail'
            self_view_kwargs = {'post_id': '<id>'}
            self_view_many = 'posts'
Ejemplo n.º 27
0
class LicenseSchema(Schema):
    id = fields.Int()
    vendor = fields.String()
    model = fields.Int()
    name = fields.Int()
    type = fields.Int()
    quantity = fields.String()
    in_use = fields.String()
    expiration_dt = fields.String()
    last_modified_dt = fields.String()

    location = Relationship(schema=LocationSchema,
                            include_resource_linkage=True,
                            type_='location')

    class Meta:
        type_ = 'license'
        strict = True
Ejemplo n.º 28
0
class DataSchema(Schema):
    class Meta:
        '''I include these because I like being able to see where stuff comes
        in case we end up having multiple tables in the same API.
        Plus, metadata can be easily filtered out in the output dict.'''
        type_ = 'usda_5yr_crop_table'
        self_view_kwargs = {'id': '<id>'}
        self_view = 'data_detail'
        self_view_many = 'data_list'

    id = fields.Int(dump_only=True)
    CROP = fields.Str(required=True)
    FIPS_CODE = fields.Int(required=True)
    COUNTY_NAME = fields.Str(required=True)
    STATE_CODE = fields.Str(required=True)
    YEAR = fields.Int(required=True)
    TOTAL_HARVESTED_ACRES = fields.Int(required=True)
    TOTAL_YIELD = fields.Number(required=True)
Ejemplo n.º 29
0
class ApplicationSchema(Schema):
    class Meta:
        type_ = 'applications'
        self_view = 'applications_api.application_detail'
        self_view_kwargs = {'application_id': '<id>'}
        self_view_many = 'applications_api.application_list'
        strict = True

    id = fields.Int(dump_only=True)
    manifest_url = fields.Url()
Ejemplo n.º 30
0
class UserSchema(Schema):
    id = fields.Int(required=True)
    email = fields.Str(required=True)

    class Meta:
        type_ = 'users'
        self_view = 'users.get_user'
        self_view_many = 'users.get_users'
        self_view_kwargs = {'user_id': '<id>'}
        strict = True