1. offline
  2. django-openauth

Commits

offline  committed 6bad669

form fields now placed in seperate file

  • Participants
  • Parent commits 4a1cca6
  • Branches default

Comments (0)

Files changed (2)

File openauth/fields.py

View file
  • Ignore whitespace
+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

File openauth/forms.py

View file
  • Ignore whitespace
 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: