Exemple #1
0
    def __init__(self, data=None, *args, **kwargs):
        user = getattr(kwargs.get('request'), 'user', None)
        if user and not user.is_superuser:
            if data is None:
                data = QueryDict()
            data = data.copy()
            data['author'] = user.get_full_name()

        super(OrderFilter, self).__init__(data, *args, **kwargs)
Exemple #2
0
    def create_from_request(cls,
                            data: QueryDict,
                            files: {},
                            donation_page,
                            image_key="DImage") -> [dict]:
        """Takes a request.data and builds a MediaImage instance from the json blob data found in the files dict.

        Expected Schemas:
            data = [{"uuid": str, "type": "DImage", "content": {}, n...]
            files = {"str(<UUID>)": Blob}
        :param data: A copy of the request POST data.
        :param files: A list of dicts. Key=UUID in the request.data for the image element
        :param donation_page: the page that these images are referenced on.
        :param image_key: The key that identifies an Image element.
        :return: The data["sidebar_elements"] updated with the storage locations for the image and the thumbnail.
        """

        ## TODO: Duplicate detection

        mutable = data.copy()
        if sbe := mutable.get("sidebar_elements"):
            elements = json.loads(sbe)
            for index, element in enumerate(elements):
                if element.get("type") == image_key:
                    if f := files.get(element.get("uuid"), None):
                        img = ImageFile(f)
                        thumb = get_thumbnail(img)
                        media_image = cls(
                            spa_key=element.get("uuid"),
                            image=img,
                            thumbnail=thumb,
                            page_id=DonationPage.objects.get(pk=donation_page),
                            image_attrs={},
                        )
                        media_image.save()
                        elements[index] = media_image.get_as_dict()