diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-07-08 12:49:49 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-07-08 12:49:49 +0200 |
commit | f2950f4b226b5a7d388c4eb2fb6c383e72ac6d54 (patch) | |
tree | 7380a1fc573bf77bdbc915a1d45ae291fabc605e /hyperkitty/views/forms.py | |
parent | 8301b45160da213d1f52fddc3527b81959dd3a08 (diff) | |
download | hyperkitty-f2950f4b226b5a7d388c4eb2fb6c383e72ac6d54.tar.gz hyperkitty-f2950f4b226b5a7d388c4eb2fb6c383e72ac6d54.tar.xz hyperkitty-f2950f4b226b5a7d388c4eb2fb6c383e72ac6d54.zip |
Make a widget to add multiple attachments
Diffstat (limited to 'hyperkitty/views/forms.py')
-rw-r--r-- | hyperkitty/views/forms.py | 30 |
1 files changed, 28 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>. # # Author: Aamir Khan <syst3m.w0rm@gmail.com> +# Author: Aurélien Bompard <abompard@fedoraproject.org> # 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 = """ +<span class="attach-files-template"> + %(input)s <a href="#" title="%(rm_text)s">(-)</a> +</span> +<span class="attach-files"></span> +<a class="attach-files-first">%(attach_first_text)s</a> +<a class="attach-files-add">%(attach_another_text)s</a> +""" + + 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) |