From b41d891b467b1fed5a0cb8a6d2a42388a0f12fd5 Mon Sep 17 00:00:00 2001 From: qw3rty Date: Fri, 14 May 2010 15:24:20 +0000 Subject: [PATCH] add the ability for admins to edit the min and max length of tags. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@272 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/forms.py | 15 +++++++-------- forum/settings/form.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/forum/forms.py b/forum/forms.py index c644b04..143be75 100644 --- a/forum/forms.py +++ b/forum/forms.py @@ -58,26 +58,25 @@ class TagNamesField(forms.CharField): def clean(self, value): value = super(TagNamesField, self).clean(value) data = value.strip() - if len(data) < 1: - raise forms.ValidationError(_('tags are required')) split_re = re.compile(r'[ ,]+') list = split_re.split(data) - list_temp = [] + if len(list) > settings.FORM_MAX_NUMBER_OF_TAGS or len(list) < settings.FORM_MIN_NUMBER_OF_TAGS: - raise forms.ValidationError(_('please use betwen %(min)s and %(max)s tags') % { - 'min': apnumber(settings.FORM_MIN_NUMBER_OF_TAGS), 'max': apnumber(settings.FORM_MAX_NUMBER_OF_TAGS) - }) + raise forms.ValidationError(_('please use between %(min)s and %(max)s tags') % { 'min': apnumber(settings.FORM_MIN_NUMBER_OF_TAGS), 'max': apnumber(settings.FORM_MAX_NUMBER_OF_TAGS)}) + list_temp = [] tagname_re = re.compile(r'[a-z0-9]+') for tag in list: - if len(tag) > 20: - raise forms.ValidationError(_('tags must be shorter than 20 characters')) + test = len(tag) + if len(tag) > settings.FORM_MAX_LENGTH_OF_TAG or len(tag) < settings.FORM_MIN_LENGTH_OF_TAG: + raise forms.ValidationError(_('please use between %(min)s and %(max)s characters in you tags') % { 'min': apnumber(settings.FORM_MIN_LENGTH_OF_TAG), 'max': apnumber(settings.FORM_MAX_LENGTH_OF_TAG)}) if not tagname_re.match(tag): raise forms.ValidationError(_('please use following characters in tags: letters \'a-z\', numbers, and characters \'.-_#\'')) # only keep one same tag if tag not in list_temp and len(tag.strip()) > 0: list_temp.append(tag) + return u' '.join(list_temp) class WikiField(forms.BooleanField): diff --git a/forum/settings/form.py b/forum/settings/form.py index 45df66f..0637c13 100644 --- a/forum/settings/form.py +++ b/forum/settings/form.py @@ -33,6 +33,9 @@ help_text = _("If a question's content can be empty."), required=False)) + + +""" settings for tags """ FORM_MIN_NUMBER_OF_TAGS = Setting('FORM_MIN_NUMBER_OF_TAGS', 1, FORUM_SET, dict( label = _("Required number of tags per question"), help_text = _("How many tags are required in questions."), @@ -43,6 +46,17 @@ label = _("Maximum number of tags per question"), help_text = _("How many tags are allowed in questions."), )) +FORM_MIN_LENGTH_OF_TAG = Setting('FORM_MIN_LENGTH_OF_TAG', 1, FORUM_SET, dict( +label = _("Minimum length of a tag"), +help_text = _("How short a tag can be."), +)) + +FORM_MAX_LENGTH_OF_TAG = Setting('FORM_MAX_LENGTH_OF_TAG', 20, FORUM_SET, dict( +label = _("Maximum length of a tag"), +help_text = _("How long a tag can be."), +)) + + """ settings for comments """ -- 2.39.5