summaryrefslogtreecommitdiffstats
path: root/hyperkitty/views
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-10-11 12:42:06 +0200
committerAurélien Bompard <aurelien@bompard.org>2012-10-11 12:42:06 +0200
commit270ac090732ee3a42e595d9d04d75b944fc2181c (patch)
tree27c8fadbd336c1f6d2571fbdc19725790fd7a998 /hyperkitty/views
parent37ff508a20036e29775e9784cecf9d6ee9a360c5 (diff)
Improve the 'add tag' form
Diffstat (limited to 'hyperkitty/views')
-rw-r--r--hyperkitty/views/forms.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/hyperkitty/views/forms.py b/hyperkitty/views/forms.py
index fc885c8..8e458d0 100644
--- a/hyperkitty/views/forms.py
+++ b/hyperkitty/views/forms.py
@@ -1,6 +1,8 @@
from django import forms
from django.core import validators
from django.contrib.auth.models import User
+from django.utils.safestring import mark_safe
+
def isValidUsername(username):
try:
@@ -9,6 +11,7 @@ def isValidUsername(username):
return
raise validators.ValidationError('The username "%s" is already taken.' % username)
+
class RegistrationForm(forms.Form):
username = forms.CharField(label='username', help_text=None,
@@ -32,10 +35,30 @@ class RegistrationForm(forms.Form):
return u
+class TextInputWithButton(forms.TextInput):
+ """
+ Render a text field and a button following the Twitter Bootstrap
+ directives: http://twitter.github.com/bootstrap/base-css.html#buttons
+
+ Use the 'button_text' class attribute to set the button's text.
+ """
+
+ def render(self, name, value, attrs=None):
+ button_text = self.attrs.pop("button_text", u"")
+ initial_rendering = forms.TextInput.render(
+ self, name, value, attrs)
+ button = mark_safe(u'<button type="submit" class="btn">%s</button>'
+ % button_text)
+ return "".join([u'<span class="input-append">',
+ initial_rendering, button, u'</span>'])
+
+
class AddTagForm(forms.Form):
tag = forms.CharField(label='', help_text=None,
- widget=forms.TextInput(
- attrs={'placeholder': 'Add a tag...'}
+ widget=TextInputWithButton(
+ attrs={'placeholder': 'Add a tag...',
+ 'class': 'span2',
+ 'button_text': 'Add'}
)
)
from_url = forms.CharField(widget=forms.HiddenInput, required=False)