]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/forms.py
Remove unused import.
[osqa.git] / forum / forms.py
index 70466b57c2478f2d6771bbb6172bc806855f028b..c644b04253a0487289972dd7c656a348fc9aad78 100644 (file)
@@ -2,14 +2,13 @@ import re
 from datetime import date
 from django import forms
 from models import *
 from datetime import date
 from django import forms
 from models import *
-from const import *
 from django.utils.translation import ugettext as _
 from django.utils.translation import ugettext as _
+from django.contrib.humanize.templatetags.humanize import apnumber
 from forum.models import User
 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.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
+from forum import settings
 import logging
 
 class TitleField(forms.CharField):
 import logging
 
 class TitleField(forms.CharField):
@@ -38,7 +37,7 @@ class EditorField(forms.CharField):
         self.initial = ''
 
     def clean(self, value):
         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
             raise forms.ValidationError(_('question content must be must be at least %s characters' % settings.FORM_MIN_QUESTION_BODY))
 
         return value
@@ -51,7 +50,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.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):
         self.initial = ''
 
     def clean(self, value):
@@ -63,8 +64,10 @@ class TagNamesField(forms.CharField):
         split_re = re.compile(r'[ ,]+')
         list = split_re.split(data)
         list_temp = []
         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:
 
         tagname_re = re.compile(r'[a-z0-9]+')
         for tag in list:
@@ -126,9 +129,6 @@ class AnswerForm(forms.Form):
             self.fields['wiki'].initial = True
 
 
             self.fields['wiki'].initial = True
 
 
-class CloseForm(forms.Form):
-    reason = forms.ChoiceField(choices=CLOSE_REASONS)
-
 class RetagQuestionForm(forms.Form):
     tags   = TagNamesField()
     # initialize the default values
 class RetagQuestionForm(forms.Form):
     tags   = TagNamesField()
     # initialize the default values
@@ -188,8 +188,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}))
 
 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}))
     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 +196,8 @@ class EditUserForm(forms.Form):
 
     def __init__(self, user, *args, **kwargs):
         super(EditUserForm, self).__init__(*args, **kwargs)
 
     def __init__(self, user, *args, **kwargs):
         super(EditUserForm, self).__init__(*args, **kwargs)
-        logging.debug('initializing the form')
         if settings.EDITABLE_SCREEN_NAME:
         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
             self.fields['username'].initial = user.username
             self.fields['username'].user_instance = user
         self.fields['email'].initial = user.email
@@ -229,6 +227,12 @@ class EditUserForm(forms.Form):
                     raise forms.ValidationError(_('this email has already been registered, please use another one'))
         return self.cleaned_data['email']
 
                     raise forms.ValidationError(_('this email has already been registered, please use another one'))
         return self.cleaned_data['email']
 
+NOTIFICATION_CHOICES = (
+    ('i', _('Instantly')),
+    ('d', _('Daily')),
+    ('w', _('Weekly')),
+    ('n', _('No notifications')),
+)
 
 class SubscriptionSettingsForm(forms.Form):
     member_joins = forms.ChoiceField(widget=forms.RadioSelect, choices=NOTIFICATION_CHOICES)
 
 class SubscriptionSettingsForm(forms.Form):
     member_joins = forms.ChoiceField(widget=forms.RadioSelect, choices=NOTIFICATION_CHOICES)