From 3b9f21a55fed735652716e63fedabad87899be81 Mon Sep 17 00:00:00 2001 From: SVN-Git Migration Date: Thu, 8 Oct 2015 11:51:45 -0700 Subject: Imported Upstream version 0.2.1 --- tagging/forms.py | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) (limited to 'tagging/forms.py') diff --git a/tagging/forms.py b/tagging/forms.py index 875c598..6844039 100644 --- a/tagging/forms.py +++ b/tagging/forms.py @@ -1,22 +1,23 @@ -from django import newforms as forms - -from tagging.utils import get_tag_name_list -from tagging.validators import tag_list_re - -class TagField(forms.CharField): - def clean(self, value): - """ - Validates that the input is a valid list of tag names, - separated by a single comma, a single space or a comma - followed by a space. - """ - value = super(TagField, self).clean(value) - if value == u'': - return value - if not tag_list_re.search(value): - raise forms.ValidationError(u'Tag names must contain only unicode alphanumeric characters, numbers, underscores or hyphens, with a comma, space or comma followed by space used to separate each tag name.') - tag_names = get_tag_name_list(value) - for tag_name in tag_names: - if len(tag_name) > 50: - raise forms.ValidationError(u'Tag names must be no longer than 50 characters.') - return value +""" +Tagging components for Django's ``newforms`` form library. +""" +from django import newforms as forms +from django.utils.translation import ugettext as _ + +from tagging import settings +from tagging.utils import parse_tag_input + +class TagField(forms.CharField): + """ + A ``CharField`` which validates that its input is a valid list of + tag names. + """ + def clean(self, value): + value = super(TagField, self).clean(value) + if value == u'': + return value + for tag_name in parse_tag_input(value): + if len(tag_name) > settings.MAX_TAG_LENGTH: + raise forms.ValidationError( + _('Each tag may be no more than %s characters long.') % settings.MAX_TAG_LENGTH) + return value -- cgit v1.2.3