Exemple #1
0
    def store_attachments(cls, xform, attachments):
        xform_attachments = []
        for attachment in attachments:
            xform_attachment = XFormAttachmentSQL(
                name=attachment.name,
                attachment_id=uuid.uuid4(),
                content_type=attachment.content_type,
            )
            xform_attachment.write_content(attachment.content)
            if xform_attachment.is_image:
                try:
                    img_size = Image.open(attachment.content_as_file()).size
                    xform_attachment.properties = dict(width=img_size[0], height=img_size[1])
                except IOError:
                    xform_attachment.content_type = 'application/octet-stream'
            xform_attachments.append(xform_attachment)

        xform.unsaved_attachments = xform_attachments