コード例 #1
0
class EditVenueBodyModel(BaseModel):
    name: Optional[str]
    address: Optional[str]
    siret: Optional[str]
    latitude: Optional[Union[float, str]]
    longitude: Optional[Union[float, str]]
    bookingEmail: Optional[str]
    postalCode: Optional[str]
    city: Optional[str]
    publicName: Optional[str]
    comment: Optional[str]
    venueTypeId: Optional[int]
    venueLabelId: Optional[int]
    withdrawalDetails: Optional[str]
    isAccessibilityAppliedOnAllOffers: Optional[bool]
    isWithdrawalAppliedOnAllOffers: Optional[bool]
    isEmailAppliedOnAllOffers: Optional[bool]
    description: Optional[VenueDescription]  # type: ignore
    audioDisabilityCompliant: Optional[bool]
    mentalDisabilityCompliant: Optional[bool]
    motorDisabilityCompliant: Optional[bool]
    visualDisabilityCompliant: Optional[bool]
    contact: Optional[VenueContactModel]

    _dehumanize_venue_label_id = dehumanize_field("venueLabelId")
    _dehumanize_venue_type_id = dehumanize_field("venueTypeId")
コード例 #2
0
class CreateMediationBodyModel(BaseModel):
    thumb_url: Optional[str]
    offerer_id: int
    offer_id: int
    credit: Optional[str]
    cropping_rect_x: Optional[float] = Field(None, alias="croppingRect[x]")
    cropping_rect_y: Optional[float] = Field(None, alias="croppingRect[y]")
    cropping_rect_height: Optional[float] = Field(None,
                                                  alias="croppingRect[height]")

    _dehumanize_offerer_id = dehumanize_field("offerer_id")
    _dehumanize_offer_id = dehumanize_field("offer_id")

    class Config:
        alias_generator = to_camel

    @property
    def crop_params(self):
        if {
                self.cropping_rect_x, self.cropping_rect_y,
                self.cropping_rect_height
        } == {None}:
            return None
        return (self.cropping_rect_x, self.cropping_rect_y,
                self.cropping_rect_height)

    def get_image_as_bytes(self, request):
        """Get the image from the POSTed data (request) or from the form field
        (in which case it's supposed to be an URL that we are going to
        request.
        """
        # FIXME: use pydantic logic to return validation errors
        missing_image_error = ApiErrors(
            {"thumb": ["Vous devez fournir une image d'accroche"]})

        if "thumb" in request.files:
            blob = request.files["thumb"]
            if not blob.filename:
                raise missing_image_error
            if Path(blob.filename).suffix not in ALLOWED_IMAGE_SUFFIXES:
                error = (
                    f"Cette image n'a pas d'extension ({', '.join(ALLOWED_IMAGE_SUFFIXES)}) "
                    f"ou son format n'est pas autorisé")
                raise ApiErrors({"thumb": [error]})

            return blob.read()

        if self.thumb_url:
            try:
                return _fetch_image(self.thumb_url)
            except ValueError as value_error:
                logger.exception(value_error)
                raise ApiErrors(
                    {"thumbUrl": ["L'adresse saisie n'est pas valide"]})

        raise missing_image_error
コード例 #3
0
class PatchAllOffersActiveStatusBodyModel(BaseModel):
    is_active: bool
    offerer_id: Optional[int]
    venue_id: Optional[int]
    name: Optional[str]
    type_id: Optional[str]
    creation_mode: Optional[str]
    status: Optional[str]
    period_beginning_date: Optional[datetime]
    period_ending_date: Optional[datetime]

    _dehumanize_offerer_id = dehumanize_field("offerer_id")
    _dehumanize_venue_id = dehumanize_field("venue_id")

    class Config:
        alias_generator = to_camel
コード例 #4
0
class ListVenueProviderQuery(BaseModel):
    venue_id: int

    _dehumanize_venue_id = dehumanize_field("venue_id")

    class Config:
        alias_generator = to_camel
        extra = "forbid"
コード例 #5
0
class ListOffersQueryModel(BaseModel):
    nameOrIsbn: Optional[str]
    offerer_id: Optional[int]
    status: Optional[str]
    venue_id: Optional[int]
    categoryId: Optional[str]
    creation_mode: Optional[str]
    period_beginning_date: Optional[str]
    period_ending_date: Optional[str]

    _dehumanize_venue_id = dehumanize_field("venue_id")
    _dehumanize_offerer_id = dehumanize_field("offerer_id")

    class Config:
        alias_generator = to_camel
        extra = "forbid"
        arbitrary_types_allowed = True
コード例 #6
0
class StocksUpsertBodyModel(BaseModel):
    offer_id: int
    stocks: List[Union[StockCreationBodyModel, StockEditionBodyModel]]

    _dehumanize_offer_id = dehumanize_field("offer_id")

    class Config:
        alias_generator = to_camel
コード例 #7
0
class ListOffersQueryModel(BaseModel):
    paginate: Optional[int]
    page: Optional[int]
    name: Optional[str]
    offerer_id: Optional[int]
    status: Optional[str]
    venue_id: Optional[int]
    type_id: Optional[str]
    creation_mode: Optional[str]
    period_beginning_date: Optional[str]
    period_ending_date: Optional[str]

    _cast_paginate = cast_optional_field_str_to_int("paginate")
    _cast_page = cast_optional_field_str_to_int("page")
    _dehumanize_venue_id = dehumanize_field("venue_id")
    _dehumanize_offerer_id = dehumanize_field("offerer_id")

    class Config:
        alias_generator = to_camel
        extra = "forbid"
        arbitrary_types_allowed = True
コード例 #8
0
class StockEditionBodyModel(BaseModel):
    beginning_datetime: Optional[datetime]
    booking_limit_datetime: Optional[datetime]
    id: int
    price: float
    quantity: Optional[int]

    _dehumanize_id = dehumanize_field("id")

    class Config:
        alias_generator = to_camel
        extra = "forbid"
コード例 #9
0
class CreateThumbnailBodyModel(BaseModel):
    thumb_url: Optional[str]
    offerer_id: int
    offer_id: int
    credit: Optional[str]
    cropping_rect_x: Optional[float]
    cropping_rect_y: Optional[float]
    cropping_rect_height: Optional[float]

    _dehumanize_offerer_id = dehumanize_field("offerer_id")
    _dehumanize_offer_id = dehumanize_field("offer_id")

    class Config:
        alias_generator = to_camel

    @property
    def crop_params(self):
        if {
                self.cropping_rect_x, self.cropping_rect_y,
                self.cropping_rect_height
        } == {None}:
            return None
        return (self.cropping_rect_x, self.cropping_rect_y,
                self.cropping_rect_height)

    def get_image_as_bytes(self, request) -> bytes:
        """
        Get the image from the POSTed data (request) or from the form field
        (in which case it's supposed to be an URL that we are going to request.
        Only the max size is checked at this stage, and possibly the content type header
        """
        if "thumb" in request.files:
            blob = request.files["thumb"]
            image_as_bytes = blob.read()
            return validation.get_uploaded_image(image_as_bytes)

        if self.thumb_url:
            return validation.get_distant_image(self.thumb_url)

        raise validation.exceptions.MissingImage
コード例 #10
0
class ListBookingsQueryModel(BaseModel):
    page: int = 1
    venue_id: Optional[int]
    event_date: Optional[datetime]
    booking_period_beginning_date: date
    booking_period_ending_date: date

    _dehumanize_venue_id = dehumanize_field("venue_id")

    class Config:
        alias_generator = to_camel

    extra = "forbid"
コード例 #11
0
class VenueListQueryModel(BaseModel):
    validated_for_user: Optional[bool]
    validated: Optional[bool]
    active_offerers_only: Optional[bool]
    offerer_id: Optional[int]

    _dehumanize_offerer_id = dehumanize_field("offerer_id")
    _string_to_boolean_validated_for_user = string_to_boolean_field(
        "validated_for_user")
    _string_to_boolean_validated = string_to_boolean_field("validated")
    _string_to_boolean_active_offerers_only = string_to_boolean_field(
        "active_offerers_only")

    class Config:
        alias_generator = to_camel
        extra = "forbid"
コード例 #12
0
class StockCreationBodyModel(BaseModel):
    beginning_datetime: Optional[datetime.datetime]
    booking_limit_datetime: Optional[datetime.datetime]
    offer_id: int
    price: float
    quantity: Optional[int]

    # FIXME (cgaunet, 2020-11-05): these two fields are actually
    # unused for the stock creation. But the webapp does send them so
    # we must list them here (because of the `extra = "forbid"` below.
    beginning_time: Optional[str]
    offerer_id: Optional[str]

    _dehumanize_offer_id = dehumanize_field("offer_id")

    class Config:
        alias_generator = to_camel
        extra = "forbid"