summaryrefslogtreecommitdiff
path: root/postgresqleu/util/widgets.py
diff options
context:
space:
mode:
authorMagnus Hagander2019-07-11 12:59:58 +0000
committerMagnus Hagander2019-07-11 13:36:34 +0000
commit38fa4c3ece442653d92d2fbaa499820f5e8737c9 (patch)
treeef643038e2030875252146b98d0225657f6a597d /postgresqleu/util/widgets.py
parent3774ce5ac83a8f3fd2573058e5bcceb17572a6a6 (diff)
Make the speaker photo use a proper widget and validator
Instead of a bunch of things hardcoded in the template and in the view, make the photo upload widget reusable, and move the validation of the field into a proper validator. This makes it a lot easier to re-use the field elsewhere.
Diffstat (limited to 'postgresqleu/util/widgets.py')
-rw-r--r--postgresqleu/util/widgets.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/postgresqleu/util/widgets.py b/postgresqleu/util/widgets.py
index e3d886ed..0488bc78 100644
--- a/postgresqleu/util/widgets.py
+++ b/postgresqleu/util/widgets.py
@@ -1,6 +1,7 @@
from django import forms
from django.forms.widgets import TextInput
from django.utils.safestring import mark_safe
+from django.template import loader
import datetime
import json
@@ -66,6 +67,14 @@ class EmailTextWidget(forms.Textarea):
return mark_safe('<div class="textarea-mail-prefix">This text area is sized to the correct width of an email! Automatic line wrappings are preserved.</div>') + t
+class PhotoUploadWidget(forms.ClearableFileInput):
+ clear_checkbox_label = "Remove photo"
+
+ def render(self, name, value, attrs=None, renderer=None):
+ context = self.get_context(name, value, attrs)
+ return mark_safe(loader.render_to_string('confreg/widgets/photo_upload_widget.html', context))
+
+
class AdminJsonWidget(PrettyPrintJsonWidget):
def render(self, name, value, attrs=None, renderer=None):
attrs['cols'] = 100