Esempio n. 1
0
class EventSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'events'
        url = 'events'
        model = Event

    id = fields.Int()
    status = fields.String()
    type = fields.String()
    title = fields.String()
    description = fields.String()
    image_url = fields.Url(data_key='imageUrl')
    promoted = fields.Boolean()
    event_dates = fields.Nested(EventDateSchema,
                                data_key='eventDates',
                                many=True)
    app = fields.Function(get_id_from_url)
    venues = fields.List(RelatedResourceLinkField(schema=VenueSchema),
                         many=True,
                         missing=None)
    artists = fields.List(fields.Inferred),  # TODO
    useful_info = fields.List(fields.Inferred, data_key='usefulInfo'),  # TODO
    user_actions = fields.List(fields.Inferred,
                               data_key='userActions'),  # TODO
    social_media = fields.List(fields.Inferred,
                               data_key='socialMedia'),  # TODO
    translations = fields.List(fields.Inferred),  # TODO
    updated_at = fields.AwareDateTime(data_key='updatedAt', allow_none=True)
    created_at = fields.AwareDateTime(data_key='createdAt', allow_none=True)
    core_event_category = fields.Nested(CoreEventCategory,
                                        data_key='coreEventCategory',
                                        missing=None)
Esempio n. 2
0
class UserSchema(Schema):
    id = fields.UUID(required=True)
    user_name = fields.Str(
        required=True,
        validate=validate.Regexp(regex='^([A-Za-z0-9]+_*)+')
    )
    password = fields.Str(required=True)
    group = fields.Str(
        required=True,
        validate=validate.OneOf(
            choices=["super_admin", "teacher", "student"]
        )
    )
    created_at = fields.AwareDateTime(
        default_timezone=pytz.utc,
        required=True
    )
    updated_at = fields.AwareDateTime(
        default_timezone=pytz.utc,
        required=True
    )

    @pre_load
    def hash_password(self, in_data: dict, **kwargs):
        in_data["password"] = get_password_hash(in_data["password"])
        return in_data

    class Meta:
        load_only = ["password"]
        dump_only = ["created_at", "id"]
Esempio n. 3
0
class NewsSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'news'
        url = 'news'
        model = News

    class NewsMediaSchema(Schema):
        class Meta:
            unknown = EXCLUDE

        type = fields.String(required=True, allow_none=False)
        url = fields.String(required=True, allow_none=False)
        thumbnail_url = fields.String(required=False,
                                      allow_none=False,
                                      missing=None,
                                      data_key='thumbnailUrl')

    id = fields.Int()
    external_id = fields.String(data_key='externalId')
    headline = fields.String(data_key='headline', missing=None)
    image_url = fields.String(data_key='imageUrl', missing=None)
    title = fields.String(data_key='title')
    media = fields.Nested(NewsMediaSchema, missing=None, allow_none=False)
    url = fields.String(allow_none=True)
    updated_at = fields.AwareDateTime(data_key='updatedAt',
                                      allow_none=False,
                                      load_only=True)
    published_at = fields.AwareDateTime(data_key='publishedAt',
                                        allow_none=False)
    author = fields.String(required=False, missing=None)
Esempio n. 4
0
class RealityTypeSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'reality_type'
        url = 'user_management/reality_types'
        model = RealityType

    id = fields.Int()
    name = fields.String(missing=None)
    config_json_schema = fields.Raw(missing={},
                                    data_key='configJsonSchema',
                                    allow_none=True)
    config_ui_schema = fields.Raw(missing={},
                                  data_key='configUiSchema',
                                  allow_none=True)
    evaluator = fields.Raw(missing={})
    watch = fields.Raw()
    value_type = fields.String(data_key='valueType')
    updated_at = fields.AwareDateTime(data_key='updatedAt',
                                      allow_none=True,
                                      missing=None)
    created_at = fields.AwareDateTime(data_key='createdAt',
                                      allow_none=True,
                                      missing=None)
    combination_key = fields.String(data_key='combinationKey',
                                    allow_none=True,
                                    missing=None)
Esempio n. 5
0
class User(Schema):
    username = fields.String()
    email = fields.Email()
    first_name = fields.String()
    last_name = fields.String()
    created_at = fields.AwareDateTime()
    updated_at = fields.AwareDateTime()
Esempio n. 6
0
class RegistrationSchema(BaseSchema):
    username = custom_fields.Username(required=True)
    email = fields.Email(required=True)
    password = custom_fields.Password(write_only=True, required=True)
    first_name = fields.String()
    last_name = fields.String()
    created_at = fields.AwareDateTime(read_only=True)
    updated_at = fields.AwareDateTime(read_only=True)
Esempio n. 7
0
class ProjectCreateSchema(Schema):
    name = fields.Str(required=True)
    description = fields.Str(missing=None)
    course_id = fields.Int(required=True)
    start_date = fields.AwareDateTime(required=True)
    due_date = fields.AwareDateTime(required=True)
    type = fields.Str(required=True,
                      validate=validate.OneOf([e.value for e in ProjectTypes]))
    groups = fields.List(fields.List(fields.Raw))
Esempio n. 8
0
class EventDateSchema(Schema):
    class Meta:
        unknown = EXCLUDE

    id = fields.Int()
    start_at = fields.AwareDateTime(data_key='startAt')
    end_at = fields.AwareDateTime(data_key='endAt')
    general_ticket_url = fields.String(data_key='generalTicketUrl',
                                       required=False)
Esempio n. 9
0
class BOASchema(PostLoadObjMixin):

    __model__ = BOA

    id = fields.Integer(required=True)
    start = fields.AwareDateTime(required=True)
    end = fields.AwareDateTime(required=True)
    mw = fields.Float(required=True)
    offer = fields.Function(
        deserialize=lambda data, context: context['offers'][data])
Esempio n. 10
0
class OfferSchema(PostLoadObjMixin):

    __model__ = Offer

    id = fields.Integer(required=True)
    bmu = fields.Function(
        deserialize=lambda data, context: context['bmus'][data])
    start = fields.AwareDateTime(nullable=True, missing=None)
    end = fields.AwareDateTime(nullable=True, missing=None)
    price_mw_hr = fields.Float(missing=0)
Esempio n. 11
0
class AssetStateSchema(PostLoadObjMixin):

    __model__ = AssetState

    id = fields.Integer(required=True)
    asset = fields.Function(
        deserialize=lambda data, context: context['assets'][data])
    start = fields.AwareDateTime(required=True)
    end = fields.AwareDateTime(required=True)
    charge = fields.Float(missing=0)
    available = fields.Boolean(missing=False)
Esempio n. 12
0
class InstructionSchema(PostLoadObjMixin):

    __model__ = Instruction

    id = fields.Integer(required=True)
    asset = fields.Function(
        deserialize=lambda data, context: context['assets'][data])
    mw = fields.Float(required=True)
    start = fields.AwareDateTime(required=True)
    end = fields.AwareDateTime(required=True)
    boa = fields.Function(
        deserialize=lambda data, context: context['boa'][data])
Esempio n. 13
0
class DeviceConsentSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        model = DeviceConsent

    id = fields.Int()
    location_capture = fields.Boolean(data_key='locationCapture', allow_none=True, missing=None)
    location_granular = fields.String(data_key='locationGranular', allow_none=True, missing=None)
    camera = fields.Boolean(data_key='camera', allow_none=True, missing=None)
    calendar = fields.Boolean(allow_none=True)
    photo_sharing = fields.Boolean(data_key='photoSharing', allow_none=True)
    push_notification = fields.Boolean(data_key='pushNotification', allow_none=True)
    updated_at = fields.AwareDateTime(data_key='updatedAt', allow_none=True, missing=None)
    created_at = fields.AwareDateTime(data_key='createdAt', allow_none=True, missing=None)
Esempio n. 14
0
class DeviceFormDataSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        model = DeviceFormData
        api_type = 'form_data'
        url = 'engage/form_data'
        default_ordering = 'id'

    id = fields.Int()
    expires_at = fields.AwareDateTime(data_key='expiresAt', load_only=True, allow_none=True)
    created_at = fields.AwareDateTime(data_key='createdAt', load_only=True, allow_none=True)
    updated_at = fields.AwareDateTime(data_key='updatedAt', load_only=True, allow_none=True)
    data = fields.List(fields.Inferred, data_key='data')
    device_id = RelatedResourceLinkField(schema=DeviceSchema, data_key='device', microservice_aware=True)
    form_id = RelatedResourceLinkField(schema=FormSchema, data_key='form', microservice_aware=True)
Esempio n. 15
0
class Task(BaseSchema):
    task_id = fields.Int(strict=True, dump_only=True)
    project_id = fields.Int(strict=True)
    team_id = fields.Int(strict=True)
    name = fields.Str(required=True, validate=validate.Length(min=3, max=255))
    description = fields.Str()
    estimation = fields.TimeDelta()
    status = Status(required=True)
    created_at = fields.AwareDateTime(dump_only=True)
    created_by = fields.Int(dump_only=True)
    assignee_id = fields.Int(strict=True)
    due_date = fields.AwareDateTime()
    creator = fields.Nested(User, dump_only=True)
    assignee = fields.Nested(User, dump_only=True)
    time_entries = fields.Nested(TimeEntry, many=True, dump_only=True)
Esempio n. 16
0
class PushConsentSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'push_consents'
        url = 'push_consents'
        model = PushConsent

    id = fields.Int()
    type = fields.String()
    label = fields.String()
    title = fields.String()
    sort_id = fields.Int(data_key='sortId')
    updated_at = fields.AwareDateTime(data_key='updatedAt', allow_none=True)
    created_at = fields.AwareDateTime(data_key='createdAt', allow_none=True)
    translations = fields.Raw()
Esempio n. 17
0
class TimeEntry(BaseSchema):
    time_entry_id = fields.Int(dump_only=True)
    task_id = fields.Int(required=True)
    assignee_id = fields.Int(required=True)
    start_datetime = fields.AwareDateTime(required=True)
    end_datetime = fields.AwareDateTime()

    @validates_schema
    def validate_datetime(self, data, **kwargs):
        if 'start_datetime' in data and 'end_datetime' in data:
            if data['start_datetime'] > data['end_datetime']:
                raise ValidationError({
                    'startDatetime':
                    ['startDatetime is greater than endDatetime']
                })
Esempio n. 18
0
class BookingSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        model = Booking
        api_type = 'bookings'
        url = 'bookings'

    id = fields.Int()
    title = fields.String()
    device_id = RelatedResourceLinkField(schema=DeviceSchema, data_key='device')
    user_id = RelatedResourceLinkField(schema=UserSchema, data_key='user')
    event_id = RelatedResourceLinkField(schema=EventSchema, data_key='event')
    updated_at = fields.AwareDateTime(data_key='updatedAt', allow_none=True)
    created_at = fields.AwareDateTime(data_key='createdAt', allow_none=True)
    action = fields.String()
    type = fields.String()
Esempio n. 19
0
class _ByReferenceFileSchema(Schema):
    url = fields.Url(data_key="@id", required=True)
    content_disposition = fields.String(data_key="contentDisposition",
                                        required=True)
    content_length = fields.Integer(data_key="contentLength", strict=True)
    content_type = fields.String(data_key="contentType", required=True)
    dereference = fields.Boolean(required=True)
    packaging = fields.String(missing=PackagingFormat.Binary)
    ttl = fields.AwareDateTime()

    @validates_schema
    def validate_url(self, data, **kwargs):
        parsed_url = urlparse(data["url"])
        if parsed_url.hostname == self.context["url_adapter"].server_name:
            try:
                rule, rv = self.context["url_adapter"].match(parsed_url.path)
            except HTTPException:
                return None
            if rule == "invenio_sword.temporary_url":
                data["temporary_id"] = rv["temporary_id"]
                del data["url"]

    @post_load
    def make_object(self, data, **kwargs):
        return ByReferenceFileDefinition(**data)
Esempio n. 20
0
class LectureDumpSchema(IdSchema):
    name = fields.Str()
    aliases = fields.List(fields.Str())
    comment = fields.Str()
    validated = fields.Boolean()
    early_document_until = fields.AwareDateTime(default_timezone=reference.LocalTimezone())
    early_document_eligible = fields.Boolean()
Esempio n. 21
0
class TicketAuthSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'ticket_auths'
        url = 'ticket_auths'
        model = TicketAuth

    id = fields.Int()
    client_email = fields.String(required=False,
                                 missing=None,
                                 data_key='clientEmail')
    client_id = fields.String(required=False,
                              missing=None,
                              data_key='clientId')
    access_token = fields.String(required=False,
                                 missing=None,
                                 data_key='accessToken')
    expire_at = fields.AwareDateTime(data_key='expireAt',
                                     allow_none=False,
                                     missing=None)
    refresh_token = fields.String(required=False,
                                  missing=None,
                                  data_key='refreshToken')
    user_email = RelatedResourceField(schema=UserEmailSchema,
                                      required=False,
                                      missing=None,
                                      data_key='userEmail')
    ticket_integration = RelatedResourceLinkField(
        schema=TicketIntegrationSchema,
        required=False,
        missing=None,
        data_key='ticketIntegration')
Esempio n. 22
0
class WellBaseSchema(BaseSchema):
    class Meta:
        ordered = True

    api14 = fields.Str(required=True, validate=length_is_14)
    api10 = fields.Str(validate=length_is_10)
    status = fields.Str()
    provider = fields.Str(default="IHS", required=True)
    last_update_at = fields.AwareDateTime(default_timezone=timezone.utc)
    well_name = fields.Str()
    # well_number = fields.Str()
    hole_direction = fields.Str()

    @pre_dump
    def transform(self, data, **kwargs) -> Dict:

        output: Dict = {}
        # header: Dict = {}
        # if hasattr(data, "header"):
        #     header = data["header"]

        get = functools.partial(query_dict, data=data.__dict__)

        output["api14"] = data["api14"]
        output["api10"] = data["api10"]
        output["last_update_at"] = data["last_update_at"]
        output["status"] = data["status"]
        output["well_name"] = get("well_name")
        output["hole_direction"] = get("hole_direction")
        # output["well_name"] = get("well_name")
        # output["well_number"] = get("number")
        # output["hole_direction"] = get("drilling.hole_direction.designation.code")

        return output
Esempio n. 23
0
class EventStageSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'event_stages'
        url = 'event_stages'
        model = EventStage

    id = fields.Int()
    status = fields.String()
    venue = fields.Function(get_id_from_url)
    name = fields.String()
    description = fields.String()
    color = fields.String()
    sort_id = fields.Int(data_key='sortId')
    updated_at = fields.AwareDateTime(data_key='updatedAt', allow_none=True)
    created_at = fields.AwareDateTime(data_key='createdAt', allow_none=True)
    app = fields.Function(get_id_from_url)
Esempio n. 24
0
class EventCategorySchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'event_categories'
        url = 'event_categories'
        model = EventCategory

    id = fields.Int()
    title = fields.String()
    resource = fields.String()
    force_show = fields.Boolean(data_key='forceShow')
    updated_at = fields.AwareDateTime(data_key='updatedAt', allow_none=True)
    created_at = fields.AwareDateTime(data_key='createdAt', allow_none=True)
    app = fields.Function(get_id_from_url)
    venue = fields.Function(get_id_from_url)
    sort_id = fields.Boolean(data_key='sortId')
    translations = fields.List(fields.Inferred, allow_none=True)
Esempio n. 25
0
class WorkshopSchema(CustomSchema):
    id = fields.Str(dump_only=True)
    name = fields.Str(required=True, validate=validate.Length(min=1, max=128))
    startAt = fields.AwareDateTime(required=True)
    creatorId = fields.Str(dump_only=True)
    coachId = fields.Str(required=True, validate=validate.Length(min=1))
    city = fields.Str(required=True, validate=validate.Length(max=128))
    address = fields.Str(validate=validate.Length(max=512))
    eventUrl = fields.Str(validate=validate.Length(max=1024))
Esempio n. 26
0
class AudienceSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'audiences'
        url = 'user_management/audiences'
        model = Audience

    id = fields.Int()
    name = fields.String(missing=None)
    reality_values = fields.Nested(AudienceRealityValuesSchema,
                                   many=True,
                                   data_key='realityValues')
    updated_at = fields.AwareDateTime(data_key='updatedAt',
                                      allow_none=True,
                                      missing=None)
    created_at = fields.AwareDateTime(data_key='createdAt',
                                      allow_none=True,
                                      missing=None)
Esempio n. 27
0
class EventIntegrationSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'event_integration'
        url = 'event_integration'
        model = Event

    id = fields.Int()
    status = fields.String()
    endpoint_url = fields.Url(data_key='endpointUrl')
    timezone = fields.String()
    adapter = fields.String()
    config_payload = fields.String(data_key='configPayload')
    updated_at = fields.AwareDateTime(data_key='updatedAt', allow_none=True)
    created_at = fields.AwareDateTime(data_key='createdAt', allow_none=True)
    app = fields.Function(get_id_from_url)
    remove_old = fields.Boolean(data_key='removeOld')
    override_social_media = fields.Boolean(data_key='overrideSocialMedia')
Esempio n. 28
0
class PushBroadcastSchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'push_broadcasts'
        url = 'push_broadcasts'
        publish_url = 'push_broadcasts/publish'
        model = PushBroadcast

    id = fields.Int(required=False, allow_none=False)
    title = fields.String(data_key='title')
    message = fields.String(data_key='message')
    deep_link = fields.String(data_key='deepLink')
    ttl = fields.Int()
    message_id = fields.String(data_key='messageId')
    delivered = fields.Int()
    updated_at = fields.AwareDateTime(data_key='updatedAt', allow_none=True)
    created_at = fields.AwareDateTime(data_key='createdAt', allow_none=True)
    push_consent_id = RelatedResourceLinkField(schema=PushConsentSchema,
                                               data_key='pushConsent')
Esempio n. 29
0
class X(Schema):
    string = fields.String(missing=lambda: "default")
    integer = fields.Integer(missing=lambda: 10)
    boolean = fields.Boolean(missing=lambda: True)
    datetime = fields.AwareDateTime(missing=lambda: datetime.datetime(
        2000, 1, 1, 1, 1, 1, tzinfo=datetime.timezone.utc))
    object = fields.Nested(lambda: XObject(),
                           missing=lambda: OrderedDict([("name", "foo"),
                                                        ("age", 20)]))
    array = fields.List(fields.Integer(), missing=lambda: [1, 2, 3])
Esempio n. 30
0
class DeviceRealitySchema(Schema):
    class Meta:
        unknown = EXCLUDE
        api_type = 'device_realities'
        url = 'user_management/device_realities'
        model = DeviceReality

    id = fields.Int()
    reality = RelatedResourceLinkField(schema=RealitySchema,
                                       allow_none=False,
                                       microservice_aware=True)
    device = RelatedResourceLinkField(schema=DeviceSchema,
                                      allow_none=False,
                                      microservice_aware=True)
    value = fields.String(missing=None)
    updated_at = fields.AwareDateTime(data_key='updatedAt',
                                      allow_none=True,
                                      missing=None)
    created_at = fields.AwareDateTime(data_key='createdAt',
                                      allow_none=True,
                                      missing=None)