]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/forms.py
forgot to remove a test variable.
[osqa.git] / forum / forms.py
index 2196981f6258c31e1c3ca373a7e45a66c0d4e2ce..b6bfc08a515962f01818fcdd1441565918485f17 100644 (file)
@@ -8,7 +8,7 @@ from forum.models import User
 
 from django.utils.safestring import mark_safe
 from forum.utils.forms import NextUrlField, UserNameField, SetPasswordForm
-from django.conf import settings
+from forum import settings
 import logging
 
 class TitleField(forms.CharField):
@@ -58,26 +58,24 @@ 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'))
+            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):
@@ -188,8 +186,6 @@ class EditAnswerForm(forms.Form):
 
 class EditUserForm(forms.Form):
     email = forms.EmailField(label=u'Email', help_text=_('this email does not have to be linked to gravatar'), required=True, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))
-    if settings.EDITABLE_SCREEN_NAME:
-       username = UserNameField(label=_('Screen name'))
     realname = forms.CharField(label=_('Real name'), required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))
     website = forms.URLField(label=_('Website'), required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))
     city = forms.CharField(label=_('Location'), required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))
@@ -198,8 +194,8 @@ class EditUserForm(forms.Form):
 
     def __init__(self, user, *args, **kwargs):
         super(EditUserForm, self).__init__(*args, **kwargs)
-        logging.debug('initializing the form')
         if settings.EDITABLE_SCREEN_NAME:
+            self.fields['username'] = UserNameField(label=_('Screen name'))
             self.fields['username'].initial = user.username
             self.fields['username'].user_instance = user
         self.fields['email'].initial = user.email