コード例 #1
0
class TodoSchema(Schema):
    class Meta:
        type_ = 'todo'
        self_view = 'todo_detail'
        self_view_kwargs = {'id': '<id>'}

    id = fields.Integer(dump_only=True)
    name = fields.Str()
    done = fields.Bool()
コード例 #2
0
class ProductAreaSchema(Schema):
    class Meta:
        type_ = 'product_area'
        self_view = 'product_area_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'product_area_list'

    id = fields.Integer(as_string=True, dump_only=True)
    name = fields.Str(requried=True)
コード例 #3
0
class ClientSchema(Schema):
    class Meta:
        type_ = 'client'
        self_view = 'client_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'client_list'

    id = fields.Integer(as_string=True, dump_only=True)
    name = fields.Str(requried=True)
コード例 #4
0
ファイル: tax.py プロジェクト: shawnjots/eventcity
class TaxSchemaPublic(SoftDeletionSchema):
    class Meta:
        type_ = 'tax'
        self_view = 'v1.tax_detail'
        self_view_kwargs = {'id': '<id>'}
        inflect = dasherize

    id = fields.Str(dump_only=True)
    name = fields.Str(required=True)
    rate = fields.Float(validate=lambda n: 0 <= n <= 100, required=True)
    is_tax_included_in_price = fields.Boolean(default=False)
    event = Relationship(attribute='event',
                         self_view='v1.tax_event',
                         self_view_kwargs={'id': '<id>'},
                         related_view='v1.event_detail',
                         related_view_kwargs={'tax_id': '<id>'},
                         schema='EventSchemaPublic',
                         type_='event')
コード例 #5
0
class BadSchema(Schema):
    other_id = fields.Str(required=True)

    class Meta:
        type_ = 'bad'
        self_view_many = 'bad_list'
        self_view = 'bad_detail'
        self_view_kwargs = {'bad_id': '<id>'}
        strict = True
コード例 #6
0
        class ContextTestSchema(Schema):
            id = fields.Str()
            from_context = fields.Method('get_from_context')

            def get_from_context(self, obj):
                return self.context['some_value']

            class Meta:
                type_ = 'people'
コード例 #7
0
class VideoChannelSchema(VideoChannelSchemaPublic):
    class Meta:
        type_ = 'video-channel'
        self_view = 'v1.video_channel_detail'
        self_view_kwargs = {'id': '<id>'}
        inflect = dasherize

    api_key = fields.Str(allow_none=True)
    extra = CustomFormValueField(allow_none=True)
コード例 #8
0
class AbilitySchema(Schema):
    class Meta:
        type_ = 'abilities'
        self_view = 'ability_detail'
        self_view_kwargs = {'id': '<id>'}
        self_view_many = 'ability_list'

    id = fields.Integer(dump_only=True)
    owner_id = fields.Str()
    short_summary = fields.Str()

    contributions = Relationship(self_view='ability_contribution',
                                 self_view_kwargs={'id': '<id>'},
                                 related_view='contribution_list',
                                 related_view_kwargs={'id': '<id>'},
                                 many=True,
                                 schema='ContributionSchema',
                                 type_='contributions')
コード例 #9
0
class AuthorSchema(Schema):
    id = fields.Str(dump_only=True)
    first_name = fields.Str(required=True)
    last_name = fields.Str(required=True)
    password = fields.Str(load_only=True, validate=validate.Length(6))
    twitter = fields.Str()

    def get_top_level_links(self, data, many):
        if many:
            self_link = url_for('authors_list', _external=True)
        else:
            self_link = url_for('author_detail',
                                author_id=data['id'],
                                _external=True)
        return {'self': self_link}

    class Meta:
        type_ = 'people'
コード例 #10
0
class TagSchema(Schema):
    class Meta:
        type_ = 'tags'
        self_view = 'api_app.tag_detail'
        self_view_kwargs = {'tag_id': '<id>'}
        self_view_many = 'api_app.tags_list'

    id = fields.Int(dump_only=True)
    name = fields.Str()
    color = fields.Str()

    devices = Relationship(self_view='api_app.tag_devices',
                           self_view_kwargs={'tag_id': '<id>'},
                           related_view='api_app.device_detail',
                           related_view_kwargs={'device_id': '<id>'},
                           schema='DeviceSchema',
                           many=True,
                           type_='devices')
コード例 #11
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"
コード例 #12
0
ファイル: users.py プロジェクト: khornberg/starlette-jsonapi
class UserSchema(JSONAPISchema):
    id = fields.Str(dump_only=True)
    username = fields.Str(required=True)

    organization = JSONAPIRelationship(
        type_='organizations',
        schema='OrganizationSchema',
        include_resource_linkage=True,
        id_attribute='organization_id',
        required=True,
    )

    class Meta:
        type_ = 'users'
        strict = True
        self_route = 'users:get'
        self_route_kwargs = {'id': '<id>'}
        self_route_many = 'users:get_all'
コード例 #13
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()
コード例 #14
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'
コード例 #15
0
ファイル: models.py プロジェクト: yuseferi/portia
class SchemaSchema(SlydSchema):
    id = fields.Str(dump_only=True)
    name = fields.Str()
    project = fields.Relationship(
        related_url='/api/projects/{project_id}',
        related_url_kwargs={'project_id': '<project_id>'},
        type_='projects',
        include_resource_linkage=True
    )
    fields = fields.Relationship(
        related_url='/api/projects/{project_id}/schemas/{schema_id}/fields',
        related_url_kwargs={'project_id': '<project_id>',
                            'schema_id': '<id>'},
        many=True, include_resource_linkage=True, type_='fields'
    )

    class Meta:
        type_ = 'schemas'
コード例 #16
0
class ParentSchema(Schema):
    id = fields.Str(required=True)

    class Meta:
        type_ = 'parent'
        self_view_many = 'parent_list'
        self_view = 'parent_detail'
        self_view_kwargs = {'parent_id': '<id>'}
        strict = True
コード例 #17
0
class ExchangeSchema(Schema):
    id = fields.Str(dump_only=True)
    currency_from = fields.String()
    currency_to = fields.String()
    date = fields.Date()
    value = fields.String()

    class Meta:
        type_ = 'currency_exchange'
コード例 #18
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)
コード例 #19
0
    class TestSchema(JSONAPISchema):
        class Meta:
            type_ = 'foo'

        id = fields.Str()
        rel = JSONAPIRelationship(id_attribute='rel_id',
                                  schema=OtherSchema,
                                  include_resource_linkage=True,
                                  type_='bar')
コード例 #20
0
class FeedbackSchema(SoftDeletionSchema):
    """
    Api schema for Feedback Model
    """
    class Meta:
        """
        Meta class for Feedback Api Schema
        """

        type_ = 'feedback'
        self_view = 'v1.feedback_detail'
        self_view_kwargs = {'id': '<id>'}
        inflect = dasherize

    id = fields.Str(dump_only=True)
    rating = fields.Float(required=True, validate=Range(min=1, max=5))
    comment = fields.Str(required=False)
    event = Relationship(
        attribute='event',
        self_view='v1.feedback_event',
        self_view_kwargs={'id': '<id>'},
        related_view='v1.event_detail',
        related_view_kwargs={'feedback_id': '<id>'},
        schema='EventSchemaPublic',
        type_='event',
    )
    session = Relationship(
        attribute='session',
        self_view='v1.feedback_session',
        self_view_kwargs={'id': '<id>'},
        related_view='v1.session_detail',
        related_view_kwargs={'feedback_id': '<id>'},
        schema='SessionSchema',
        type_='session',
    )
    user = Relationship(
        attribute='user',
        self_view='v1.feedback_user',
        self_view_kwargs={'id': '<id>'},
        related_view='v1.user_detail',
        related_view_kwargs={'feedback_id': '<id>'},
        schema='UserSchema',
        type_='user',
    )
コード例 #21
0
class SpeakersCallSchema(Schema):
    """
    Api Schema for Speakers Call model
    """
    class Meta:
        """
        Meta class for Speakers Call Api Schema
        """
        type_ = 'speakers-call'
        self_view = 'v1.speakers_call_detail'
        self_view_kwargs = {'id': '<id>'}
        inflect = dasherize

    @validates_schema(pass_original=True)
    def validate_date(self, data, original_data):
        if 'id' in original_data['data']:
            speakers_calls = SpeakersCall.query.filter_by(
                id=original_data['data']['id']).one()

            if 'starts_at' not in data:
                data['starts_at'] = speakers_calls.starts_at

            if 'ends_at' not in data:
                data['ends_at'] = speakers_calls.ends_at

        if data['starts_at'] >= data['ends_at']:
            raise UnprocessableEntity({'pointer': '/data/attributes/ends-at'},
                                      "ends-at should be after starts-at")

    id = fields.Str(dump_only=True)
    announcement = fields.Str(required=True)
    starts_at = fields.DateTime(required=True)
    ends_at = fields.DateTime(required=True)
    hash = fields.Str(allow_none=True)
    privacy = fields.String(
        validate=validate.OneOf(choices=["private", "public"]),
        allow_none=True)
    event = Relationship(attribute='event',
                         self_view='v1.speakers_call_event',
                         self_view_kwargs={'id': '<id>'},
                         related_view='v1.event_detail',
                         related_view_kwargs={'speakers_call_id': '<id>'},
                         schema='EventSchemaPublic',
                         type_='event')