offline avatar offline committed 6bad669

form fields now placed in seperate file

Comments (0)

Files changed (2)

openauth/fields.py

+from django import forms
+from django.contrib.auth.models import User
+from django.contrib.auth import login
+
+from annoying.functions import get_object_or_None
+
+import openauth
+
+
+
+class UsernameField(forms.CharField):
+    """
+    Form field for username handling.
+    """
+
+    def __init__(self, login=True, *args, **kwargs):
+        super(UsernameField, self).__init__(*args, **kwargs)
+        self.label = openauth.settings.USERNAME_LABEL
+
+
+    def clean(self, value):
+        super(UsernameField, self).clean(value)
+
+        if len(value) < openauth.settings.USERNAME_MIN_LENGTH:
+            raise forms.ValidationError(_(u'Login length is less than %(min)d') % {'min': openauth.settings.USERNAME_MIN_LENGTH})
+        if len(value) > openauth.settings.USERNAME_MAX_LENGTH:
+            raise forms.ValidationError(_(u'Login length is more than %(max)d') % {'max': openauth.settings.USERNAME_MAX_LENGTH})
+        if not openauth.settings.USERNAME_REGEX.match(value):
+            raise forms.ValidationError(_(u'Login contains restricted symbols'))
+
+        if openauth.settings.UNIQUE_USERNAME and not login and get_object_or_None(User, username=value):
+            raise forms.ValidationError(_(u'This login already registered'))
+        return value
+
+
+class PasswordField(forms.CharField):
+    """
+    Form field for password handling.
+    """
+
+    def __init__(self, *args, **kwargs):
+        super(PasswordField, self).__init__(*args, **kwargs)
+        self.widget = forms.PasswordInput()
+        self.help_text = ''
+
+
+    def clean(self, value):
+        super(PasswordField, self).clean(value)
+        if len(value) < openauth.settings.PASSWORD_MIN_LENGTH:
+            raise forms.ValidationError(_(u'Password length is less than %(min)d') % {'min': openauth.settings.PASSWORD_MIN_LENGTH})
+        if len(value) > openauth.settings.PASSWORD_MAX_LENGTH:
+            raise forms.ValidationError(_(u'Password length is more than %(max)d') % {'max': openauth.settings.PASSWORD_MAX_LENGTH})
+        return value

openauth/forms.py

 import openauth
 from openauth.utils import uri_to_username
 from openauth.models import OpenID
+from openauth.fields import UsernameField, PasswordField
 
 
 
 
-class UsernameField(forms.CharField):
-    """
-    Form field for username handling.
-    """
-
-    def __init__(self, login=True, *args, **kwargs):
-        super(UsernameField, self).__init__(*args, **kwargs)
-        self.label = openauth.settings.USERNAME_LABEL
-
-
-    def clean(self, value):
-        super(UsernameField, self).clean(value)
-
-        if len(value) < openauth.settings.USERNAME_MIN_LENGTH:
-            raise forms.ValidationError(_(u'Login length is less than %(min)d') % {'min': openauth.settings.USERNAME_MIN_LENGTH})
-        if len(value) > openauth.settings.USERNAME_MAX_LENGTH:
-            raise forms.ValidationError(_(u'Login length is more than %(max)d') % {'max': openauth.settings.USERNAME_MAX_LENGTH})
-        if not openauth.settings.USERNAME_REGEX.match(value):
-            raise forms.ValidationError(_(u'Login contains restricted symbols'))
-
-        if openauth.settings.UNIQUE_USERNAME and not login and get_object_or_None(User, username=value):
-            raise forms.ValidationError(_(u'This login already registered'))
-        return value
-
-
-class PasswordField(forms.CharField):
-    """
-    Form field for password handling.
-    """
-
-    def __init__(self, *args, **kwargs):
-        super(PasswordField, self).__init__(*args, **kwargs)
-        self.widget = forms.PasswordInput()
-        self.help_text = ''
-
-
-    def clean(self, value):
-        super(PasswordField, self).clean(value)
-        if len(value) < openauth.settings.PASSWORD_MIN_LENGTH:
-            raise forms.ValidationError(_(u'Password length is less than %(min)d') % {'min': openauth.settings.PASSWORD_MIN_LENGTH})
-        if len(value) > openauth.settings.PASSWORD_MAX_LENGTH:
-            raise forms.ValidationError(_(u'Password length is more than %(max)d') % {'max': openauth.settings.PASSWORD_MAX_LENGTH})
-        return value
-
-
 class RegistrationForm(forms.Form):
 
     if openauth.settings.DISPLAYNAME_REQUIRED:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.