summaryrefslogtreecommitdiffstats
path: root/hyperkitty/views/forms.py
diff options
context:
space:
mode:
Diffstat (limited to 'hyperkitty/views/forms.py')
-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)