Пример #1
0
def remove_thumb(
    model_with_thumb: Model,
    image_index: int,
) -> None:
    object_storage.delete_public_object(
        bucket="thumbs",
        object_id=model_with_thumb.get_thumb_storage_id(image_index),
    )
Пример #2
0
def validate(model: Model, api_errors: ApiErrors) -> ApiErrors:
    if model.isDigital and model.is_offline_only():
        api_errors.add_error(
            "url",
            f"Une offre de type {model.get_label_from_type_string()} ne peut pas être numérique"
        )

    return api_errors
Пример #3
0
def _save_same_thumb_from_thumb_count_to_index(pc_object: Model, thumb_index: int, image_as_bytes: bytes):
    if pc_object.thumbCount is None:  # handle unsaved object
        pc_object.thumbCount = 0
    if thumb_index <= pc_object.thumbCount:
        # replace existing thumb
        create_thumb(pc_object, image_as_bytes, thumb_index)
    else:
        # add new thumb
        for index in range(pc_object.thumbCount, thumb_index):
            create_thumb(pc_object, image_as_bytes, index)
            pc_object.thumbCount += 1
def create_thumb(
    model_with_thumb: Model,
    image_as_bytes: bytes,
    image_index: int,
    crop_params: tuple = None,
) -> None:
    image_as_bytes = standardize_image(image_as_bytes, crop_params)

    object_storage.store_public_object(
        bucket=settings.BASE_BUCKET_NAME,
        object_id=model_with_thumb.get_thumb_storage_id(image_index),
        blob=image_as_bytes,
        content_type="image/jpeg",
    )
Пример #5
0
def create_thumb(
    model_with_thumb: Model,
    image_as_bytes: bytes,
    image_index: int,
    crop_params: tuple = None,
    symlink_path: str = None,
    use_v2: bool = False,
) -> None:
    if use_v2:
        image_as_bytes = standardize_image_v2(image_as_bytes, crop_params)
    else:
        image_as_bytes = standardize_image(image_as_bytes, crop_params)

    object_storage.store_public_object(
        bucket="thumbs",
        object_id=model_with_thumb.get_thumb_storage_id(image_index),
        blob=image_as_bytes,
        content_type="image/jpeg",
        symlink_path=symlink_path,
    )
Пример #6
0
 def fill_object_attributes(self, pc_object: Model):
     pc_object.name = "New Product"
     pc_object.type = str(ThingType.LIVRE_EDITION)
Пример #7
0
 def fill_object_attributes(self, pc_object: Model):
     pc_object.name = "New Product"
     pc_object.subcategoryId = subcategories.LIVRE_PAPIER.id