class PrivateChatSchema(ma.Schema):
    """Class to serialize PrivateChat models."""

    RESOURCE_NAME = "private_chat"
    COLLECTION_NAME = "private_chats"

    _id = ma.UUID(required=True, data_key="id")
    _primary_user = ma.Nested(UserSchema(),
                              dump_only=True,
                              data_key="primary_user")
    _secondary_user = ma.Nested(UserSchema(),
                                dump_only=True,
                                data_key="secondary_user")
    resource_type = ma.Str(dump_only=True, default="PrivateChat")

    # Links
    messages_url = ma.URLFor("api.get_private_chat_messages",
                             private_chat_id="<_id>")

    @post_load
    def convert_uuid_to_hex(self, data, **kwargs):
        """Convert all UUID fields to their 32-character hexadecimal equivalent."""
        for key in data:
            value = data[key]
            if isinstance(value, uuid.UUID):
                data[key] = data[key].hex
        return data
Esempio n. 2
0
class CheckSchema(ma.ModelSchema):
    class Meta:
        model = Check

    method = ma.Nested(MethodSchema)
    store = ma.Nested(StoreSchema)
    status = ma.Nested(StatusSchema)
Esempio n. 3
0
class CardFeedsSchema(ma.ModelSchema):
    class Meta:
        model = Card
        fields = ('id', 'date_created', 'date_modified', 'title', 'note',
                  'parent_card_id', 'owner_id', 'child_cards', 'todos')

    child_cards = ma.Nested('self', many=True)
    todos = ma.Nested(TodoSchema, many=True)
Esempio n. 4
0
class UserSchema(ma.Schema):
    """Class to serialize and deserialize User models."""

    COLLECTION_NAME = "users"
    RESOURCE_NAME = "user"

    class Meta:
        unknown = EXCLUDE

    _id = ma.UUID(data_key="id", dump_only=True)
    username = ma.Str(required=True, validate=validate.Length(min=1, max=32))
    name = ma.Str(required=True, validate=validate.Length(min=1, max=32))
    email = ma.Email(required=True, validate=validate.Length(min=1, max=32))
    _created_at = ma.DateTime(data_key="joined_on",
                              dump_only=True)  # defaults to ISO 8601
    last_seen_at = ma.DateTime(dump_only=True)  # defaults to ISO 8601
    password = ma.Str(required=True, load_only=True)
    bio = ma.Str(validate=validate.Length(max=280))
    resource_type = ma.Str(default="User", dump_only=True)
    location = ma.Nested(LocationSchema, required=True)
    avatar = ma.Nested(ImageSchema, dump_only=True)
    cover_photo = ma.Nested(ImageSchema, dump_only=True)

    # links
    self_url = ma.URLFor("api.get_user", user_id="<_id>")
    communities_url = ma.URLFor("api.get_user_communities", user_id="<_id>")
    notifications_url = ma.URLFor("api.get_user_notifications",
                                  user_id="<_id>")
    private_chats_url = ma.URLFor("api.get_user_private_chats",
                                  user_id="<_id>")
    group_chats_url = ma.URLFor("api.get_user_group_chats", user_id="<_id>")

    @pre_load
    def strip_unwanted_fields(self, data, many, **kwargs):
        """Remove unwanted fields from the input data before deserialization."""
        unwanted_fields = ["resource_type"]
        for field in unwanted_fields:
            if field in data:
                data.pop(field)
        return data

    @post_dump(pass_original=True)
    def inject_extra_fields(self, data, original_model, **kwargs):
        """Post processing method to inject extra fields into the
        serialized data.
        """
        if hasattr(original_model, "role"):
            data["is_admin"] = original_model.is_admin()
        return data
Esempio n. 5
0
 class Meta:
     fields = (
         "username",
         "first_name",
         "last_name",
         "password",
         "email",
         "tenant_id",
         "roles",
     )
     model = TenantUser
     roles = ma.List(ma.Nested(authorization_schemas.RoleSchema))
Esempio n. 6
0
class GradeSchema(ma.Schema):
    class Meta:
        fields = (
            "id",
            "course_id",
            "grade",
            "record_id",
            "user",
            "threshold",
            "min_score",
        )

    user = ma.Nested(UserSchema)
Esempio n. 7
0
class CommunitySchema(ma.Schema):
    """Class to serialize and deserialize Community models."""

    COLLECTION_NAME = "communities"
    RESOURCE_NAME = "community"

    class Meta:
        unknown = EXCLUDE

    _id = ma.UUID(data_key="id", dump_only=True)
    name = ma.Str(required=True, validate=validate.Length(min=1, max=64))
    description = ma.Str(required=True,
                         validate=validate.Length(min=1, max=280))
    topic = EnumField(CommunityTopic)
    avatar = ma.Nested(ImageSchema, dump_only=True)
    cover_photo = ma.Nested(ImageSchema, dump_only=True)
    location = ma.Nested(LocationSchema, required=True)
    _founder_id = ma.UUID(dump_only=True, data_key="founder_id")
    _created_at = ma.DateTime(data_key="founded_on",
                              dump_only=True)  # defaults to ISO 8601
    resource_type = ma.Str(default="Community", dump_only=True)

    # Links
    self_url = ma.URLFor("api.get_community", community_id="<_id>")
    founder_url = ma.URLFor("api.get_user", user_id="<_founder_id>")
    members_url = ma.URLFor("api.get_community_members", community_id="<_id>")
    group_chats_url = ma.URLFor("api.get_community_group_chats",
                                community_id="<_id>")

    @pre_load
    def strip_unwanted_fields(self, data, many, **kwargs):
        """Remove unwanted fields from the input data before deserialization."""
        unwanted_fields = ["resource_type"]
        for field in unwanted_fields:
            if field in data:
                data.pop(field)
        return data
Esempio n. 8
0
class ClientSchema(ma.ModelSchema):
    class Meta:
        model = Client
        include_fk = True

    results = ma.Nested(ResultSchema, many=True)
Esempio n. 9
0
class OrderSchema(ma.ModelSchema):
    class Meta:
        model = Order

    order_details = ma.Nested(OrderDetailSchema, many=True)
    checks = ma.Nested(CheckSchema, many=True)
Esempio n. 10
0
class DiseaseSchema(ma.ModelSchema):
    refs = ma.Nested(RefSchema, many=True)

    class Meta:
        model = Disease
Esempio n. 11
0
class SourceSchema(ma.ModelSchema):
    clients = ma.Nested(ClientSchema, many=True)

    class Meta:
        model = Source
Esempio n. 12
0
class OutcomeResultSchema(ma.ModelSchema):
    class Meta:
        model = OutcomeResult

    outcome = ma.Nested(OutcomeSchema)
    alignment = ma.Nested(AlignmentSchema)