]> git.openstreetmap.org Git - osqa.git/commitdiff
Closing http://jira.osqa.net/browse/OSQA-24 with a bonus, it's also possible to speci...
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 7 May 2010 23:18:14 +0000 (23:18 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 7 May 2010 23:18:14 +0000 (23:18 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@167 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/forms.py
forum/settings/form.py

index 70466b57c2478f2d6771bbb6172bc806855f028b..bf14d54aed5e7aac2493d497b981f0810540ee78 100644 (file)
@@ -4,12 +4,12 @@ from django import forms
 from models import *
 from const import *
 from django.utils.translation import ugettext as _
+from django.contrib.humanize.templatetags.humanize import apnumber
 from forum.models import User
-from django.contrib.contenttypes.models import ContentType
+
 from django.utils.safestring import mark_safe
 from forum.utils.forms import NextUrlField, UserNameField, SetPasswordForm
 from django.conf import settings
-from django.contrib.contenttypes.models import ContentType
 import logging
 
 class TitleField(forms.CharField):
@@ -38,7 +38,7 @@ class EditorField(forms.CharField):
         self.initial = ''
 
     def clean(self, value):
-        if len(value) < settings.FORM_MIN_QUESTION_BODY and not settings.FORM_EMPTEY_QUESTION_BODY:
+        if len(value) < settings.FORM_MIN_QUESTION_BODY and not settings.FORM_EMPTY_QUESTION_BODY:
             raise forms.ValidationError(_('question content must be must be at least %s characters' % settings.FORM_MIN_QUESTION_BODY))
 
         return value
@@ -51,7 +51,9 @@ class TagNamesField(forms.CharField):
         self.max_length = 255
         self.label  = _('tags')
         #self.help_text = _('please use space to separate tags (this enables autocomplete feature)')
-        self.help_text = _('Tags are short keywords, with no spaces within. Up to five tags can be used.')
+        self.help_text = _('Tags are short keywords, with no spaces within. At least one %(min)s and up to %(max)s tags can be used.') % {
+            'min': apnumber(settings.FORM_MIN_NUMBER_OF_TAGS), 'max': apnumber(settings.FORM_MAX_NUMBER_OF_TAGS)    
+        }
         self.initial = ''
 
     def clean(self, value):
@@ -63,8 +65,10 @@ class TagNamesField(forms.CharField):
         split_re = re.compile(r'[ ,]+')
         list = split_re.split(data)
         list_temp = []
-        if len(list) > 5:
-            raise forms.ValidationError(_('please use 5 tags or less'))
+        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)
+        })
 
         tagname_re = re.compile(r'[a-z0-9]+')
         for tag in list:
index 7329d5f9a0f8a69cfa316930d0a27fb778b82ae6..ba1b5b595eb38df271bbfc8d77a5bf4311a4f01c 100644 (file)
@@ -23,12 +23,23 @@ help_text = _("The minimum number of characters a user must enter into the conte
 # label = _("Maximum number of characters for a question."),
 # help_text = _("The maximum number of characters a user can enter into the description field to submit a question.")))
 
-FORM_EMPTEY_QUESTION_BODY = Setting('FORM_EMPTY_QUESTION_BODY', False, FORUM_SET, dict(
+FORM_EMPTY_QUESTION_BODY = Setting('FORM_EMPTY_QUESTION_BODY', False, FORUM_SET, dict(
 label = _("Empty question content"),
 help_text = _("If a question's content can be empty."),
 required=False))
 
 
+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."),
+))
+
+FORM_MAX_NUMBER_OF_TAGS = Setting('FORM_MAX_NUMBER_OF_TAGS', 5, FORUM_SET, dict(
+label = _("Maximum number of tags per question"),
+help_text = _("How many tags are allowed in questions."),
+))
+
+
 
 """ settings for comments """
 FORM_MIN_COMMENT_BODY = Setting('FORM_MIN_COMMENT_BODY', 10, FORUM_SET, dict(