]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/forms/general.py
OSQA-766, smart_encode the item titles for the question RSS feeds
[osqa.git] / forum / forms / general.py
index 1becdf0edd52c648520c32394380bb3ff50dfd47..aa4282e9efa4714333a09d2eab4f2ad4d7d0d9fc 100644 (file)
@@ -5,9 +5,11 @@ from django.utils.safestring import mark_safe
 from forum import settings
 from django.http import str_to_unicode
 from forum.models import User
+from forum.modules import call_all_handlers
 import urllib
+import logging
 
-DEFAULT_NEXT = '/' + getattr(settings, 'FORUM_SCRIPT_ALIAS')
+DEFAULT_NEXT = getattr(settings, 'APP_BASE_URL')
 def clean_next(next):
     if next is None:
         return DEFAULT_NEXT
@@ -34,7 +36,7 @@ class NextUrlField(forms.CharField):
         return clean_next(value)
 
 login_form_widget_attrs = { 'class': 'required login' }
-username_re = re.compile(r'^[\w\s ]+$', re.UNICODE)
+username_re = re.compile(r'^[\-\w\s ]+$', re.UNICODE)
 
 class UserNameField(StrippedNonEmptyCharField):
     def __init__(self,db_model=User, db_field='username', must_exist=False,skip_clean=False,label=_('choose a username'),**kw):
@@ -47,7 +49,7 @@ class UserNameField(StrippedNonEmptyCharField):
                         'forbidden':_('sorry, this name is not allowed, please choose another'),
                         'missing':_('sorry, there is no user with this name'),
                         'multiple-taken':_('sorry, we have a serious error - user name is taken by several users'),
-                        'invalid':_('user name can only consist of letters, empty space and underscore'),
+                        'invalid':_('user name can only consist of letters, empty space, hyphens and underscore'),
                         'toshort':_('user name is to short, please use at least %d characters') % settings.MIN_USERNAME_LENGTH
                     }
         if 'error_messages' in kw:
@@ -154,3 +156,18 @@ class SetPasswordForm(forms.Form):
         else:
             return self.cleaned_data['password2']
 
+class SimpleCaptchaForm(forms.Form):
+    fields = {}
+
+    def __init__(self, *args, **kwargs):
+        super(SimpleCaptchaForm, self).__init__(*args, **kwargs)
+
+        spam_fields = call_all_handlers('create_anti_spam_field')
+        if spam_fields:
+            spam_fields = dict(spam_fields)
+            for name, field in spam_fields.items():
+                self.fields[name] = field
+
+            self._anti_spam_fields = spam_fields.keys()
+        else:
+            self._anti_spam_fields = []