Fix #1153 -- Show preview of uploaded pictures in the backend

This commit is contained in:
Raphael Michel
2019-05-01 13:16:25 +02:00
parent 30b8c0f4b9
commit 6841a30d8f
4 changed files with 20 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ import os
from django import forms
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.files import File
from django.forms.utils import from_current_timezone
from django.utils.translation import ugettext_lazy as _
@@ -66,11 +67,20 @@ def selector(values, prop):
class ClearableBasenameFileInput(forms.ClearableFileInput):
template_name = 'pretixbase/forms/widgets/thumbnailed_file_input.html'
class FakeFile:
class FakeFile(File):
def __init__(self, file):
self.file = file
@property
def name(self):
return self.file.name
@property
def is_img(self):
return any(self.file.name.endswith(e) for e in ('.jpg', '.jpeg', '.png', '.gif'))
def __str__(self):
return os.path.basename(self.file.name).split('.', 1)[-1]