Esempio n. 1
0
class ThrivResourceSchema(ModelSchema):
    class Meta:
        model = ThrivResource
        fields = ('id', 'name', 'description', 'last_updated', 'owner',
                  'website', 'cost', 'institution_id', 'type_id', 'type',
                  'segment_id', 'segment', 'institution', 'availabilities',
                  'approved', 'files', 'contact_email', 'contact_phone',
                  'contact_notes', 'private', '_links', 'favorites',
                  'favorite_count', 'resource_categories', 'owners',
                  'user_may_view', 'user_may_edit', 'location', 'starts',
                  'ends')

    id = fields.Integer(required=False, allow_none=True)
    last_updated = fields.Date(required=False, allow_none=True)
    owner = fields.String(required=False, allow_none=True)
    contact_email = fields.String(required=False, allow_none=True)
    contact_phone = fields.String(required=False, allow_none=True)
    contact_notes = fields.String(required=False, allow_none=True)
    website = fields.String(required=False, allow_none=True)
    institution_id = fields.Integer(required=False, allow_none=True)
    type_id = fields.Integer(required=False, allow_none=True)
    segment_id = fields.Integer(required=False, allow_none=True)
    approved = fields.String(required=False, allow_none=True)
    favorite_count = fields.Integer(required=False, allow_none=True)
    private = fields.Boolean(required=False, allow_none=True)
    location = fields.String(required=False, allow_none=True)
    starts = fields.DateTime(required=False, allow_none=True)
    ends = fields.DateTime(required=False, allow_none=True)

    type = fields.Nested(ThrivTypeSchema(), dump_only=True)
    segment = fields.Nested(ThrivSegmentSchema(), dump_only=True)
    institution = fields.Nested(ThrivInstitutionSchema(),
                                dump_only=True,
                                allow_none=True)
    availabilities = fields.Nested(AvailabilitySchema(),
                                   many=True,
                                   dump_only=True)
    favorites = fields.Nested(FavoriteSchema(), many=True, dump_only=True)
    resource_categories = fields.Nested(CategoriesOnResourceSchema(),
                                        many=True,
                                        dump_only=True)
    files = fields.Nested(FileSchema(), many=True, dump_only=True)
    user_may_view = fields.Boolean(allow_none=True)
    user_may_edit = fields.Boolean(allow_none=True)
    _links = ma.Hyperlinks(
        {
            'self':
            ma.URLFor('api.resourceendpoint', id='<id>'),
            'collection':
            ma.URLFor('api.resourcelistendpoint'),
            'institution':
            ma.UrlFor('api.institutionendpoint', id='<institution_id>'),
            'type':
            ma.UrlFor('api.typeendpoint', id='<type_id>'),
            'categories':
            ma.UrlFor('api.categorybyresourceendpoint', resource_id='<id>'),
            'availability':
            ma.UrlFor('api.resourceavailabilityendpoint', resource_id='<id>')
        },
        dump_only=True)
Esempio n. 2
0
class ModulesTypesSchema(ModelSchema):
    """Models types serialization schema."""

    class Meta:
        """Metadata."""

        model = ModulesTypes

    modules = ma.Nested(ModulesBaseSchema, many=True)

    links = ma.Hyperlinks(
        {
            "self": ma.URLFor(
                "APIv1_0_0.get_modules_types_item",
                values=dict(
                    id="<id>", _external=True
                )
            ),
            "collection": ma.URLFor(
                "APIv1_0_0.get_modules_types",
                values=dict(
                    _external=True
                )
            ),
        }
    )
Esempio n. 3
0
class OrganizationalStructureSchema(ModelSchema):
    """Departments positions serialization schema."""

    class Meta:
        """Metadata."""

        model = OrganizationalStructure
        exclude = ("children",)

    parent = ma.Nested(
        lambda: OrganizationalStructureSchema(exclude=("parent",))
    )
    children = ma.Nested(
        lambda: OrganizationalStructureSchema(exclude=("parent", "children",)),
        many=True
    )

    links = ma.Hyperlinks(
        {
            "self": ma.URLFor(
                "APIv1_0_0.get_organizational_structure_element",
                values=dict(
                    id="<id>", _external=True
                )
            ),
            "collection": ma.URLFor(
                "APIv1_0_0.get_organizational_structure",
                values=dict(
                    _external=True
                )
            ),
        }
    )
Esempio n. 4
0
class ParentCategorySchema(ModelSchema):
    """Provides a view of the parent category, all the way to the top, but ignores children"""
    class Meta:
        model = Category
        fields = ('id', 'name', 'parent', 'level', 'color', 'icon_id', 'icon',
                  'image', '_links', 'brief_description', 'description',
                  'display_order')

    parent = fields.Nested('self', dump_only=True)
    level = fields.Function(lambda obj: obj.calculate_level())
    color = fields.Function(lambda obj: obj.calculate_color())
    icon_id = fields.Integer(required=False, allow_none=True)
    icon = fields.Nested(IconSchema, allow_none=True, dump_only=True)
    image = fields.String(required=False, allow_none=True)
    display_order = fields.Integer(required=True,
                                   allow_none=False,
                                   default=999)
    _links = ma.Hyperlinks({
        'self':
        ma.URLFor('api.categoryendpoint', id='<id>'),
        'collection':
        ma.URLFor('api.categorylistendpoint'),
        'resources':
        ma.URLFor('api.resourcebycategoryendpoint', category_id='<id>')
    })
Esempio n. 5
0
class ClientSchema(ma.ModelSchema):
    class Meta:
        model = Client
        # fields = ("id", "recipe_id", "instructions")

    recipes = ma.Nested(RecipeSchema, many=True)

    # pass Schema as string to avoid infinite circular relation between Clients & Recipes
    menus = ma.Nested('MenuSchema', many=True, exclude=('client,'), dump_only=True, )

    allergens = ma.Nested(IngredientSchema, many=True, only=("_links",
                                                             "alternatives",
                                                             "description",
                                                             "id",
                                                             "is_allergen",
                                                             "name",
                                                             "nutrition",
                                                             "timestamp",
                                                             "type"))

    # Smart hyperlinking
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api._create_client', client_id='<id>'),
        'collection': ma.URLFor('api._create_client')
    })

    @post_load
    def make_client(self, data):
        return Client(**data)
Esempio n. 6
0
class RecipeSchema(ma.ModelSchema):
    class Meta:
        model = Recipe
        # fields = ("id", "name", "description", "style", "type", "_links")
        exclude = ('step', 'clients', 'step_sub_recipe')

    steps = ma.Nested(StepSchema, many=True)

    # sub_recipes = ma.Nested(StepSubRecipeSchema, many=True)
    # ingredients = ma.Nested(StepIngredientSchema, many=True)
    # ingredients = ma.Method("get_days_since_created", dump_only=True)
    #
    # def get_days_since_created(self, obj):
    #     # return dt.datetime.now().day - obj.created_at.day
    #     ingredients_schmea = IngredientSchema(many=True)
    #     ingredients = db.session.query(Ingredient).all()
    #     # return jsonify(ingredients_schmea.dump(ingredients))
    #     return ingredients_schmea.jsonify(ingredients)
    #     # print(db.session.query(User).all())
    #     # print(db.session.query(Ingredient).all())
    #     # return db.session.query(Ingredient).all()

    # balance = fields.Method('get_balance', deserialize='load_balance', dump_only=True)
    #
    # def get_balance(self, obj):
    #     return obj.name
    #
    # def load_balance(self, value):
    #     return float(value)

    # Smart hyperlinking
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api._get_recipe', recipe_id='<id>'),
        'collection': ma.URLFor('api._get_recipes')
    })
Esempio n. 7
0
class PasswordsSchema(ModelSchema):
    """Passwords serialization schema."""

    class Meta:
        """Metadata."""

        model = Passwords

    links = ma.Hyperlinks(
        {
            "self": ma.URLFor(
                "APIv1_0_0.get_passwords_item",
                values=dict(
                    id="<id>", _external=True
                )
            ),
            "collection": ma.URLFor(
                "APIv1_0_0.get_passwords",
                values=dict(
                    _external=True
                )
            ),
        }
    )
    users = ma.Nested(UsersBaseSchema(exclude=("passwords",)))
Esempio n. 8
0
class UserSchema(ma.Schema):
    class Meta:
        fields = ('id', 'username', 'email', '_links')

    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.user_detail', id='<id>'),
        'collection': ma.URLFor('api.users')
    })
Esempio n. 9
0
class EventCategorySchema(ModelSchema):
    class Meta(ModelSchema.Meta):
        model = ResourceCategory
        fields = ('id', '_links', 'resource_id', 'category_id')
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.eventcategoryendpoint', id='<id>'),
        'category': ma.URLFor('api.categoryendpoint', id='<category_id>'),
        'event': ma.URLFor('api.eventendpoint', id='<resource_id>')
    })
Esempio n. 10
0
class ImageSchema(ma.Schema):
    class Meta:
        # Fields to expose
        fields = ["picname",'id']

    # Smart hyperlinking
    _links = ma.Hyperlinks(
        {"self": ma.URLFor("item_detail", id="<id>"), "collection": ma.URLFor("image")}
    )
Esempio n. 11
0
class InvestigatorSchema(ModelSchema):
    class Meta:
        model = Investigator
        fields = ('id', 'last_updated', 'name', 'title', 'organization_name', 'bio_link',
                  '_links')
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.investigatorendpoint', id='<id>'),
        'collection': ma.URLFor('api.investigatorlistendpoint'),
    })
Esempio n. 12
0
class StudyCategorySchema(ModelSchema):
    class Meta:
        model = StudyCategory
        fields = ('id', '_links', 'study_id', 'category_id')
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.studycategoryendpoint', id='<id>'),
        'category': ma.URLFor('api.categoryendpoint', id='<category_id>'),
        'study': ma.URLFor('api.studyendpoint', id='<study_id>')
    })
Esempio n. 13
0
class StudyInvestigatorSchema(ModelSchema):
    class Meta:
        model = StudyInvestigator
        fields = ('id', '_links', 'study_id', 'investigator_id')
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.studyinvestigatorendpoint', id='<id>'),
        'investigator': ma.URLFor('api.investigatorendpoint', id='<investigator_id>'),
        'study': ma.URLFor('api.studyendpoint', id='<study_id>')
    })
Esempio n. 14
0
class ChildCategoryInSearchSchema(ModelSchema):
    """Children within a category have hit counts when returned as a part of a search."""
    class Meta:
        model = Category
        fields = ('id', 'name', '_links', 'hit_count')
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.categoryendpoint', id='<id>'),
        'collection': ma.URLFor('api.categorylistendpoint')
    })
Esempio n. 15
0
class LocationCategorySchema(ModelSchema):
    class Meta:
        model = ResourceCategory
        fields = ('id', '_links', 'resource_id', 'category_id')
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.locationcategoryendpoint', id='<id>'),
        'category': ma.URLFor('api.categoryendpoint', id='<category_id>'),
        'location': ma.URLFor('api.locationendpoint', id='<resource_id>')
    })
Esempio n. 16
0
class CategoryStudiesSchema(ModelSchema):
    class Meta:
        model = StudyCategory
        fields = ('id', '_links', 'study_id', 'category_id', 'study')
    study = fields.Nested(StudySchema, dump_only=True)
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.studycategoryendpoint', id='<id>'),
        'category': ma.URLFor('api.categoryendpoint', id='<category_id>'),
        'study': ma.URLFor('api.studyendpoint', id='<study_id>')
    })
Esempio n. 17
0
class StudyUserSchema(ModelSchema):
    class Meta:
        model = StudyUser
        fields = ('id', '_links', 'status', 'study_id', 'user_id')
    status = EnumField(StudyUserStatus, allow_none=True)
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.studyuserendpoint', id='<id>'),
        'user': ma.URLFor('api.userendpoint', id='<user_id>'),
        'study': ma.URLFor('api.studyendpoint', id='<study_id>')
    })
Esempio n. 18
0
class CategoryLocationsSchema(ModelSchema):
    class Meta:
        model = ResourceCategory
        fields = ('id', '_links', 'resource_id', 'category_id', 'resource')
    resource = fields.Nested(LocationSchema, dump_only=True)
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.locationcategoryendpoint', id='<id>'),
        'category': ma.URLFor('api.categoryendpoint', id='<category_id>'),
        'location': ma.URLFor('api.locationendpoint', id='<resource_id>')
    })
Esempio n. 19
0
class CategoryEventsSchema(ModelSchema):
    class Meta:
        model = ResourceCategory
        fields = ('id', '_links', 'resource_id', 'category_id', 'resource')
    resource = fields.Nested(EventSchema, dump_only=True)
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.eventcategoryendpoint', id='<id>'),
        'category': ma.URLFor('api.categoryendpoint', id='<category_id>'),
        'event': ma.URLFor('api.eventendpoint', id='<resource_id>')
    })
Esempio n. 20
0
class ResourceCategoriesSchema(ModelSchema):
    class Meta:
        model = ResourceCategory
        fields = ('id', '_links', 'resource_id', 'category_id', 'category')
    category = fields.Nested(CategorySchema, dump_only=True)
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.resourcecategoryendpoint', id='<id>'),
        'category': ma.URLFor('api.categoryendpoint', id='<category_id>'),
        'resource': ma.URLFor('api.resourceendpoint', id='<resource_id>')
    })
Esempio n. 21
0
class ItemSchema(ma.Schema):
    class Meta:
        # Fields to expose
        fields = ("id","name", "category", "price", 'imgs')
    # imgs = ma.Nested(ImageSchema)
    imgs = ma.Nested(ImageSchema, many = True)
    # Smart hyperlinking
    _links = ma.Hyperlinks(
        {"self": ma.URLFor("item_detail", id="<id>"), "collection": ma.URLFor("item")}
    )
Esempio n. 22
0
class UserFavoritesSchema(ModelSchema):
    class Meta:
        model = Favorite
        fields = ('id', 'user_id', 'resource_id', 'resource', '_links')
    resource = fields.Nested(ThrivResourceSchema, dump_only=True)
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.favoriteendpoint', id='<id>'),
        'user': ma.URLFor('api.userendpoint', id='<user_id>'),
        'resource': ma.URLFor('api.resourceendpoint', id='<resource_id>')
    })
Esempio n. 23
0
class InvestigatorStudiesSchema(ModelSchema):
    class Meta:
        model = StudyInvestigator
        fields = ('id', '_links', 'study_id', 'investigator_id', 'study')
    study = fields.Nested(StudySchema, dump_only=True)
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.studyinvestigatorendpoint', id='<id>'),
        'investigator': ma.URLFor('api.investigatorendpoint', id='<investigator_id>'),
        'study': ma.URLFor('api.studyendpoint', id='<study_id>')
    })
Esempio n. 24
0
class SimplePlayerSchema(ma.ModelSchema):
    class Meta:
        fields = ('id', 'name', 'image', 'self', 'delete_player',
                  'update_player')
        model = Player

    image = ma.URLFor("get_player_image", id="<id>")
    self = ma.URLFor("get_player", id="<id>")
    update_player = ma.URLFor("update_player", id="<id>")
    delete_player = ma.URLFor("delete_player", id="<id>")
Esempio n. 25
0
class PuzzleListSecondarySchema(ma.Schema):
    class Meta:
        fields = ('id', 'name', '_links')
        ordered = True

    _links = ma.Hyperlinks({
        "self":
        ma.URLFor('get_puzzle_by_game', game_id="<game_id>", puzzle_id="<id>"),
        "detail":
        ma.URLFor('get_puzzle', id="<id>")
    })
Esempio n. 26
0
class ClueDetailSecondarySchema(ma.Schema):
    class Meta:
        fields = ('id', 'name', 'needer', 'holder', '_links')
        ordered = True

    _links = ma.Hyperlinks({
        "self":
        ma.URLFor('get_clues_by_puzzle', puzzle_id="<holder>", clue_id="<id>"),
        "detail":
        ma.URLFor('get_clue', id="<id>")
    })
Esempio n. 27
0
class ProgramaSchema(ma.Schema):
    """Classe para receber o programa como JSON."""
    class Meta:
        """Metaclasse com configurações."""

        fields = ('id', 'nome', 'valor', '_links')

    _links = ma.Hyperlinks({
        'self': ma.URLFor('programs.detail', id='<id>'),
        'collection': ma.URLFor('programs.list')
    })
Esempio n. 28
0
class ParentCategorySchema(ModelSchema):
    """Provides a view of the parent category, all the way to the top, but ignores children"""
    class Meta:
        model = Category
        fields = ('id', 'name', 'parent', 'level', '_links')
    parent = fields.Nested('self', dump_only=True)
    level = fields.Function(lambda obj: obj.calculate_level())
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.categoryendpoint', id='<id>'),
        'collection': ma.URLFor('api.categorylistendpoint')
    })
Esempio n. 29
0
class ProductSchema(WrappedModelSchema):
    many_name = "products"

    class Meta:
        fields = ("id", "description", "active", "_links")

    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.product', id='<id>'),
        'collection': ma.URLFor('api.products'),
        'offers': ma.URLFor('api.offers', product='<id>')
    })
Esempio n. 30
0
class ResourceSchema(ModelSchema):
    class Meta:
        model = Resource
        fields = ('id', 'type', 'title', 'last_updated', 'description', 'organization_name', 'phone', 'website',
                  'contact_email', 'video_code', 'is_uva_education_content', 'resource_categories',
                  'is_draft', 'ages', 'insurance', 'phone_extension', 'languages', 'covid19_categories', '_links')
    resource_categories = fields.Nested(CategoriesOnResourceSchema(), many=True, dump_only=True)
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.resourceendpoint', id='<id>'),
        'collection': ma.URLFor('api.resourcelistendpoint'),
        'categories': ma.UrlFor('api.categorybyresourceendpoint', resource_id='<id>')
    })