diff options
Diffstat (limited to 'lib/taggit/forms.py')
-rw-r--r-- | lib/taggit/forms.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/taggit/forms.py b/lib/taggit/forms.py new file mode 100644 index 0000000..e0198bd --- /dev/null +++ b/lib/taggit/forms.py @@ -0,0 +1,21 @@ +from django import forms +from django.utils.translation import ugettext as _ + +from taggit.utils import parse_tags, edit_string_for_tags + + +class TagWidget(forms.TextInput): + def render(self, name, value, attrs=None): + if value is not None and not isinstance(value, basestring): + value = edit_string_for_tags([o.tag for o in value.select_related("tag")]) + return super(TagWidget, self).render(name, value, attrs) + +class TagField(forms.CharField): + widget = TagWidget + + def clean(self, value): + value = super(TagField, self).clean(value) + try: + return parse_tags(value) + except ValueError: + raise forms.ValidationError(_("Please provide a comma-separated list of tags.")) |