forked from CGM_Public/pretix_original
Fix favicon loading
This commit is contained in:
@@ -267,9 +267,10 @@ CACHE_LARGE_VALUES_ALIAS = 'default'
|
||||
FILE_UPLOAD_EXTENSIONS_IMAGE = (".png", ".jpg", ".gif", ".jpeg")
|
||||
PILLOW_FORMATS_IMAGE = ('PNG', 'GIF', 'JPEG')
|
||||
|
||||
FILE_UPLOAD_EXTENSIONS_FAVICON = (".ico", ".png", "jpg", ".gif", ".jpeg")
|
||||
FILE_UPLOAD_EXTENSIONS_FAVICON = (".ico", ".png", ".jpg", ".gif", ".jpeg")
|
||||
PILLOW_FORMATS_QUESTIONS_FAVICON = ('PNG', 'GIF', 'JPEG', 'ICO')
|
||||
|
||||
FILE_UPLOAD_EXTENSIONS_QUESTION_IMAGE = (".png", "jpg", ".gif", ".jpeg", ".bmp", ".tif", ".tiff", ".jfif")
|
||||
FILE_UPLOAD_EXTENSIONS_QUESTION_IMAGE = (".png", ".jpg", ".gif", ".jpeg", ".bmp", ".tif", ".tiff", ".jfif")
|
||||
PILLOW_FORMATS_QUESTIONS_IMAGE = ('PNG', 'GIF', 'JPEG', 'BMP', 'TIFF')
|
||||
|
||||
FILE_UPLOAD_EXTENSIONS_EMAIL_ATTACHMENT = (
|
||||
|
||||
@@ -2910,6 +2910,25 @@ Your {organizer} team""")) # noqa: W291
|
||||
label=_('Use header image also for events without an individually uploaded logo'),
|
||||
)
|
||||
},
|
||||
'favicon': {
|
||||
'default': None,
|
||||
'type': File,
|
||||
'form_class': ExtFileField,
|
||||
'form_kwargs': dict(
|
||||
label=_('Favicon'),
|
||||
ext_whitelist=settings.FILE_UPLOAD_EXTENSIONS_FAVICON,
|
||||
max_size=settings.FILE_UPLOAD_MAX_SIZE_FAVICON,
|
||||
help_text=_('If you provide a favicon, we will show it instead of the default pretix icon. '
|
||||
'We recommend a size of at least 200x200px to accommodate most devices.')
|
||||
),
|
||||
'serializer_class': UploadedFileField,
|
||||
'serializer_kwargs': dict(
|
||||
allowed_types=[
|
||||
'image/png', 'image/jpeg', 'image/gif', 'image/x-icon', 'image/vnd.microsoft.icon',
|
||||
],
|
||||
max_size=settings.FILE_UPLOAD_MAX_SIZE_FAVICON,
|
||||
)
|
||||
},
|
||||
'og_image': {
|
||||
'default': None,
|
||||
'type': File,
|
||||
|
||||
@@ -423,6 +423,7 @@ class OrganizerSettingsForm(SettingsForm):
|
||||
'organizer_link_back',
|
||||
'organizer_logo_image_large',
|
||||
'organizer_logo_image_inherit',
|
||||
'favicon',
|
||||
'giftcard_length',
|
||||
'giftcard_expiry_years',
|
||||
'locales',
|
||||
@@ -464,14 +465,6 @@ class OrganizerSettingsForm(SettingsForm):
|
||||
'can increase the size with the setting below. We recommend not using small details on the picture '
|
||||
'as it will be resized on smaller screens.')
|
||||
)
|
||||
favicon = ExtFileField(
|
||||
label=_('Favicon'),
|
||||
ext_whitelist=settings.FILE_UPLOAD_EXTENSIONS_FAVICON,
|
||||
required=False,
|
||||
max_size=settings.FILE_UPLOAD_MAX_SIZE_FAVICON,
|
||||
help_text=_('If you provide a favicon, we will show it instead of the default pretix icon. '
|
||||
'We recommend a size of at least 200x200px to accommodate most devices.')
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
is_admin = kwargs.pop('is_admin', False)
|
||||
|
||||
@@ -164,9 +164,9 @@ def resize_image(image, size):
|
||||
return image
|
||||
|
||||
|
||||
def create_thumbnail(sourcename, size):
|
||||
def create_thumbnail(sourcename, size, formats=None):
|
||||
source = default_storage.open(sourcename)
|
||||
image = Image.open(BytesIO(source.read()), formats=settings.PILLOW_FORMATS_QUESTIONS_IMAGE)
|
||||
image = Image.open(BytesIO(source.read()), formats=formats or settings.PILLOW_FORMATS_QUESTIONS_IMAGE)
|
||||
try:
|
||||
image.load()
|
||||
except:
|
||||
@@ -208,9 +208,9 @@ def create_thumbnail(sourcename, size):
|
||||
return t
|
||||
|
||||
|
||||
def get_thumbnail(source, size):
|
||||
def get_thumbnail(source, size, formats=None):
|
||||
# Assumes files are immutable
|
||||
try:
|
||||
return Thumbnail.objects.get(source=source, size=size)
|
||||
except Thumbnail.DoesNotExist:
|
||||
return create_thumbnail(source, size)
|
||||
return create_thumbnail(source, size, formats=formats)
|
||||
|
||||
@@ -1229,7 +1229,8 @@ class OrganizerIcalDownload(OrganizerViewMixin, View):
|
||||
|
||||
class OrganizerFavicon(View):
|
||||
def get(self, *args, **kwargs):
|
||||
if self.request.organizer.settings.favicon:
|
||||
return redirect_to_url(get_thumbnail(self.request.organizer.settings.favicon, '32x32^').thumb.url)
|
||||
icon_file = self.request.organizer.settings.get('favicon', as_type=str, default='')[7:]
|
||||
if icon_file:
|
||||
return redirect_to_url(get_thumbnail(icon_file, '32x32^', formats=settings.PILLOW_FORMATS_QUESTIONS_FAVICON).thumb.url)
|
||||
else:
|
||||
return redirect_to_url(static("pretixbase/img/favicon.ico"))
|
||||
|
||||
Reference in New Issue
Block a user