Diverse Code Cleanups

*Code wurde PEP-8 gerecht formatiert
* Kleine Fehler die der PyCharm Inspector beanstandet wurden korrigiert
This commit is contained in:
Christian Berg
2014-11-26 16:04:52 +01:00
committed by Christian Berg
parent f34281089d
commit 86a0db050d
76 changed files with 619 additions and 528 deletions

View File

@@ -1,11 +1,11 @@
'''
"""
Created on 03.10.2011
@author: Christian
'''
"""
from . import models
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib import auth
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from utils.html5 import forms
@@ -26,29 +26,25 @@ class MembershipForm(forms.ModelForm):
)
def clean_birthday(self):
if self.cleaned_data['membership'] \
and not self.cleaned_data['birthday']:
if self.cleaned_data['membership'] and not self.cleaned_data['birthday']:
raise forms.ValidationError(_('For your membership, we need this. \
Please fill out this field yet.'))
return self.cleaned_data['birthday']
def clean_telephone(self):
if self.cleaned_data['membership'] \
and not self.cleaned_data['telephone']:
if self.cleaned_data['membership'] and not self.cleaned_data['telephone']:
raise forms.ValidationError(_('For your membership, we need this. \
Please fill out this field yet.'))
return self.cleaned_data['telephone']
def clean_street_name(self):
if self.cleaned_data['membership'] \
and not self.cleaned_data['street_name']:
if self.cleaned_data['membership'] and not self.cleaned_data['street_name']:
raise forms.ValidationError(_('For your membership, we need this. \
Please fill out this field yet.'))
return self.cleaned_data['street_name']
def clean_post_code(self):
if self.cleaned_data['membership'] \
and not self.cleaned_data['post_code']:
if self.cleaned_data['membership'] and not self.cleaned_data['post_code']:
raise forms.ValidationError(_('For your membership, we need this. \
Please fill out this field yet.'))
return self.cleaned_data['post_code']
@@ -71,41 +67,43 @@ class RegistrationForm(forms.ModelForm):
required_css_class = 'required'
first_name = forms.CharField(max_length=30, required=True,
label=_('Given Name'))
label=_('Given Name'))
last_name = forms.CharField(max_length=30, required=True,
label=_('Last Name'))
label=_('Last Name'))
username = forms.SlugField(required=True, max_length=30,
label=_('Username'),
help_text=_("The Username can only contain the letters from A to Z, \
label=_('Username'),
help_text=_("The Username can only contain the letters from A to Z, \
Numbers, and the underscore. It must be at least 2 characters long, \
and cannot be longer the 30. The first character must be a letter."))
email = forms.EmailField(required=True)
password1 = forms.CharField(widget=forms.PasswordInput(),
label=_('password'))
label=_('password'))
password2 = forms.CharField(widget=forms.PasswordInput(),
label=_('password (again)'))
label=_('password (again)'))
recaptcha = forms.ReCaptchaField()
class Meta:
model = User
model = auth.get_user_model()
fields = ('first_name', 'last_name', 'username', 'email',)
def clean_username(self):
'''
"""
Validate that the username is not already in use.
'''
"""
try:
User.objects.get(username__iexact=self.cleaned_data['username'])
except User.DoesNotExist:
auth.get_user_model().objects.get(
username__iexact=self.cleaned_data['username']
)
except auth.get_user_model().DoesNotExist:
return self.cleaned_data['username']
raise forms.ValidationError(_(u'This username is already taken. \
Please choose another.'))
def clean_email(self):
'''
"""
Validate that the supplied email address is unique for the site.
'''
if User.objects.filter(email__iexact=self.cleaned_data['email']):
"""
if auth.get_user_model().objects.filter(email__iexact=self.cleaned_data['email']):
raise forms.ValidationError(_(u'This email address is already in \
use. Please supply a different email address.'))
return self.cleaned_data['email']