Exemple #1
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>')
    })
Exemple #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
                )
            ),
        }
    )
Exemple #3
0
class FavoriteSchema(ModelSchema):
    class Meta:
        model = Favorite
        fields = ('id', 'resource_id', 'user_id', '_links')
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.favoriteendpoint', id='<id>'),
    })
Exemple #4
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",)))
Exemple #5
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
                )
            ),
        }
    )
Exemple #6
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)
Exemple #7
0
class EvaluationHistoryDependentQuestionnaireSchema(ModelSchema):
    class Meta(ModelSchema.Meta):
        model = EvaluationHistoryDependentQuestionnaire
        fields = (
            "id",
            "last_updated",
            "participant_id",
            "user_id",
            "time_on_task_ms",
            "self_identifies_autistic",
            "has_autism_diagnosis",
            "years_old_at_first_diagnosis",
            "who_diagnosed",
            "who_diagnosed_other",
            "where_diagnosed",
            "where_diagnosed_other",
            "partner_centers_evaluation",
            "gives_permission_to_link_evaluation_data",
            "has_iq_test",
            "recent_iq_score",
            "_links"
        )
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.questionnaireendpoint', name='evaluation_history_dependent_questionnaire', id='<id>'),
    })
Exemple #8
0
class EventDetailSchema(ma.Schema):
    class Meta:
        fields = ('id', 'game_id', 'num_of_players', 'date', 'start_time',
                  'end_time', '_links')
        ordered = True

    _links = ma.Hyperlinks({"self": ma.URLFor('get_event', id="<id>")})
class SupportsQuestionnaireSchema(ModelSchema):
    @pre_load
    def set_field_session(self, data, **kwargs):
        self.fields['medications'].schema.session = self.session
        self.fields['therapies'].schema.session = self.session
        self.fields['alternative_augmentative'].schema.session = self.session
        self.fields['assistive_devices'].schema.session = self.session
        return data

    class Meta(ModelSchema.Meta):
        model = SupportsQuestionnaire
        fields = ("id", "last_updated", "time_on_task_ms", "participant_id",
                  "user_id", "medications", "therapies", "assistive_devices",
                  "alternative_augmentative", "_links")

    medications = ma.Nested(MedicationSchema, many=True)
    therapies = ma.Nested(TherapySchema, many=True)
    assistive_devices = ma.Nested(AssistiveDeviceSchema, many=True)
    alternative_augmentative = ma.Nested(AlternativeAugmentativeSchema,
                                         many=True)
    _links = ma.Hyperlinks({
        'self':
        ma.URLFor('api.questionnaireendpoint',
                  name='supports_questionnaire',
                  id='<id>'),
    })
Exemple #10
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)
Exemple #11
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')
    })
Exemple #12
0
class ProfessionalProfileQuestionnaireSchema(ModelSchema):
    class Meta:
        model = ProfessionalProfileQuestionnaire
        ordered = True
        include_fk = True
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.questionnaireendpoint', name='professional_profile_questionnaire', id='<id>'),
    })
Exemple #13
0
class OrganizationSchema(ModelSchema):
    class Meta:
        model = Organization
        fields = ('id', 'name', 'last_updated', 'description', 'resources', 'studies',
                  'investigators', '_links')
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.organizationendpoint', id='<id>'),
    })
Exemple #14
0
class InvoiceSchema(WrappedModelSchema):
    many_name = "invoices"
    supplier = fields.Nested(UserSchema(only=("id", "username")))

    class Meta:
        fields = ("id", "paid", "sum", "supplier", "_links")

    _links = ma.Hyperlinks({'self': ma.URLFor('api.invoice', id='<id>')})
Exemple #15
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')
    })
class ClinicalDiagnosesQuestionnaireSchema(ModelSchema):
    class Meta:
        model = ClinicalDiagnosesQuestionnaire
        ordered = True
        include_fk = True
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.questionnaireendpoint', name="clinical_diagnoses_questionnaire", id='<id>')
    })
class IdentificationQuestionnaireSchema(ModelSchema):
    class Meta:
        model = IdentificationQuestionnaire
        ordered = True
        include_fk = True
    _links = ma.Hyperlinks({
        'self': ma.URLFor('api.questionnaireendpoint', name="identification_questionnaire", id='<id>')
    })
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")}
    )
Exemple #19
0
class DepartmentSchema(ma.Schema):
	"""Marshmallow output schema"""
	class Meta:
		fields = ["name", "id", "_links"]

	_links = ma.Hyperlinks({
		"self": ma.AbsoluteURLFor("api.departments", id="<id>"),
		"users": ma.AbsoluteURLFor("api.department_users", id="<id>")
	})
Exemple #20
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')
    })
Exemple #21
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'),
    })
Exemple #22
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>')
    })
Exemple #23
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>')
    })
Exemple #24
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>')
    })
Exemple #25
0
class DataTransferLogSchema(ModelSchema):
    class Meta(ModelSchema.Meta):
        model = DataTransferLog
        fields = ('id', 'type', 'date_started', 'last_updated',
                  'total_records', 'alerts_sent', 'details', '_links')

    details = ma.Nested(DataTransferLogDetailSchema, dump_only=True, many=True)
    _links = ma.Hyperlinks(
        {'self': ma.URLFor('api.datatransferlogendpoint', id='<id>')})
Exemple #26
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>')
    })
Exemple #27
0
class GameDetailSchema(ma.Schema):
    class Meta:
        fields = ('id', 'name', 'description', 'num_of_players', 'puzzles',
                  'events', '_links')
        ordered = True

    puzzles = ma.Nested('PuzzleListSchema', many=True)
    events = ma.Nested('EventListSchema', many=True)

    _links = ma.Hyperlinks({"self": ma.URLFor('get_game', id="<id>")})
Exemple #28
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>')
    })
Exemple #29
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>')
    })
Exemple #30
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>')
    })