Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion oscar_invoices/abstract_models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from oscar.apps.address.abstract_models import AbstractAddress
from oscar.core.loading import get_class
from phonenumber_field.modelfields import PhoneNumberField
from PIL import Image, UnidentifiedImageError

from . import app_settings

DocumentsStorage = get_class("oscar_invoices.storages", "DocumentsStorage")

WEBP = "WEBP"


def validate_no_webp(file):
try:
image = Image.open(file)
image_format = image.format.upper()
if image_format == WEBP:
raise ValidationError(
_(
"WebP images are not supported in a PDF. "
"For that reason please convert it and upload as PNG or JPG."
)
)
except UnidentifiedImageError:
raise ValidationError(_("Uploaded file is not a valid image."))


class AbstractLegalEntity(models.Model):
"""
Expand All @@ -26,7 +45,7 @@ class AbstractLegalEntity(models.Model):
max_length=20, null=True, blank=True)
logo = models.ImageField(
_('Logo'), upload_to=settings.OSCAR_IMAGE_FOLDER, max_length=255,
null=True, blank=True)
null=True, blank=True, validators=[validate_no_webp])
email = models.EmailField(_('Email'), null=True, blank=True)
web_site = models.URLField(_('Website'), null=True, blank=True)
iban = models.CharField(_("IBAN"), max_length=255, null=True, blank=True)
Expand Down
Binary file modified oscar_invoices/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 6 additions & 0 deletions oscar_invoices/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "WebP images are not supported in a PDF. For that reason please convert it and upload as PNG or JPG."
msgstr ""

msgid "Uploaded file is not a valid image."
msgstr ""

#: abstract_models.py:18
msgid "Shop name"
msgstr ""
Expand Down
Binary file modified oscar_invoices/locale/nl/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 6 additions & 0 deletions oscar_invoices/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "WebP images are not supported in a PDF. For that reason please convert it and upload as PNG or JPG."
msgstr "WebP-afbeeldingen worden niet ondersteund in een PDF. Converteer ze daarom en upload ze als PNG of JPG."

msgid "Uploaded file is not a valid image."
msgstr "Geüpload bestand is geen geldige afbeelding."

#: abstract_models.py:18
msgid "Shop name"
msgstr "Naam webshop"
Expand Down
Loading