From f2950f4b226b5a7d388c4eb2fb6c383e72ac6d54 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Mon, 8 Jul 2013 12:49:49 +0200 Subject: Make a widget to add multiple attachments --- hyperkitty/views/forms.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'hyperkitty/views/forms.py') diff --git a/hyperkitty/views/forms.py b/hyperkitty/views/forms.py index 034b7d9..99f158f 100644 --- a/hyperkitty/views/forms.py +++ b/hyperkitty/views/forms.py @@ -17,12 +17,14 @@ # HyperKitty. If not, see . # # Author: Aamir Khan +# Author: Aurélien Bompard # from django import forms from django.core import validators from django.contrib.auth.models import User from django.utils.safestring import mark_safe +from django.utils.translation import ugettext, ugettext_lazy from hyperkitty.models import UserProfile @@ -98,14 +100,38 @@ class AddTagForm(forms.Form): +class AttachmentFileInput(forms.FileInput): + attach_first_text = ugettext_lazy('Attach a file') + attach_another_text = ugettext_lazy('Attach another file') + rm_text = ugettext_lazy('Remove this file') + template = """ + + %(input)s (-) + + +%(attach_first_text)s +%(attach_another_text)s +""" + + def render(self, name, value, attrs=None): + substitutions = { + 'attach_first_text': self.attach_first_text, + 'attach_another_text': self.attach_another_text, + 'rm_text': self.rm_text, + } + substitutions['input'] = super(AttachmentFileInput, self).render(name, value, attrs) + return mark_safe(self.template % substitutions) + + class ReplyForm(forms.Form): newthread = forms.BooleanField(label="", required=False) subject = forms.CharField(label="", required=False, widget=forms.TextInput(attrs={ 'placeholder': 'New subject'})) message = forms.CharField(label="", widget=forms.Textarea) - attachment = forms.FileField(required=False) + attachment = forms.FileField(required=False, widget=AttachmentFileInput) class PostForm(forms.Form): subject = forms.CharField() message = forms.CharField(widget=forms.Textarea) - attachment = forms.FileField(required=False) + attachment = forms.FileField(required=False, label="", + widget=AttachmentFileInput) -- cgit