Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Code style amends
Krzysiek Szularz431de22dcb96
diff --git a/registration/forms.py b/registration/forms.pyindex ec2fc6b1cc..ef8a6ed75c 100644--- a/registration/forms.py+++ b/registration/forms.py@@ -11,19 +11,16 @@ class LoginForm(AuthenticationForm):username = forms.EmailField(label=_("Email"), max_length=75)-class RegisterForm(forms.Form):+class EmailForm(forms.Form):email = forms.EmailField()- def clean(self):- email = self.cleaned_data.get('email')+class RegisterForm(EmailForm):++ def clean_email(self):+ email = self.cleaned_data.get('email')if email:if User.objects.filter(email=email).exists():- raise forms.ValidationError('Email already registered')- return self.cleaned_data---class EmailForm(forms.Form):-- email = forms.EmailField()+ raise forms.ValidationError('Email already registered.')+ return emaildiff --git a/registration/models.py b/registration/models.pyindex b469437e77..15bc6a7beb 100644--- a/registration/models.py+++ b/registration/models.py@@ -10,16 +10,18 @@ now = datetime.nowclass ExternalUserData(models.Model):+user = models.ForeignKey(User, related_name='external_ids', null=True, blank=True)provider = models.TextField(db_index=True)username = models.TextField(db_index=True)class Meta:- unique_together = (('provider', 'username'),)+ unique_together = [['provider', 'username']]class EmailConfirmation(models.Model):+email = models.EmailField()external_user = models.ForeignKey(ExternalUserData, null=True, blank=True,diff --git a/registration/utils.py b/registration/utils.pyindex b1dc603de8..66e06f20c4 100644--- a/registration/utils.py+++ b/registration/utils.py@@ -1,12 +1,12 @@-from django.template.loader import render_to_stringfrom django.contrib.sites.models import get_current_sitefrom django.core.urlresolvers import reversefrom django.conf import settings+from django.template.loader import render_to_string-from oauth2client.client import OAuth2WebServerFlow, FlowExchangeErrorimport facebookimport httplib2import json+from oauth2client.client import OAuth2WebServerFlow, FlowExchangeErrordef get_callback_url(service):diff --git a/registration/views.py b/registration/views.pyindex 45846d29db..8bce9aabb6 100644--- a/registration/views.py+++ b/registration/views.py@@ -1,17 +1,21 @@from datetime import datetimefrom django.contrib.auth.views import (- login as django_login_view, logout as django_logout,+ login as django_login_view,+ logout as django_logout,)-from django.http import HttpResponseNotFound, HttpResponseBadRequest-from django.contrib.auth import get_user_model-from django.contrib.auth.forms import SetPasswordForm-from django.template.response import TemplateResponsefrom django.contrib import messages-from django.shortcuts import redirect-from django.contrib.auth import login as auth_login, authenticate+from django.contrib.auth import (+ login as auth_login,+ authenticate,+ get_user_model,+)+from django.contrib.auth.forms import SetPasswordFormfrom django.core.urlresolvers import reversefrom django.core.mail.message import EmailMessage+from django.http import HttpResponseNotFound, HttpResponseBadRequest+from django.shortcuts import redirect+from django.template.response import TemplateResponsefrom .forms import LoginForm, EmailFormfrom .models import ExternalUserData, EmailConfirmation@@ -28,10 +32,8 @@ now = datetime.nowdef login(request):- ctx = {- 'facebook_login_url': get_facebook_login_url(),- 'google_login_url': get_google_login_url()- }+ ctx = {'facebook_login_url': get_facebook_login_url(),+ 'google_login_url': get_google_login_url()}return django_login_view(request, authentication_form=LoginForm,extra_context=ctx)@@ -51,8 +53,8 @@ def oauth_callback(request, service):if not external_username:messages.warning(request,- "Failed to retrieve user information from external service."- " Please try again.")+ 'Failed to retrieve user information from external service. '+ 'Please try again.')return redirect(reverse('registration:login'))user = authenticate(external_service=service,@@ -62,7 +64,7 @@ def oauth_callback(request, service):auth_login(request, user)messages.success(request,- "You have been successfully logged in.")+ 'You have been successfully logged in.')return redirect('home')else:request.session['confirmed_email'] = email@@ -84,8 +86,7 @@ def register(request):confirmed_email = request.session.pop('confirmed_email', '')try:external_user_data = {- 'username': request.session.pop(- 'external_username'),+ 'username': request.session.pop('external_username'),'provider': request.session.pop('external_service')}except KeyError:@@ -106,18 +107,18 @@ def register(request):auth_login(request, user)messages.success(request,- "You have been successfully logged in.")+ 'You have been successfully logged in.')else:email_confirmation = EmailConfirmation.objects.create(email=submitted_email, external_user=external_user)message = get_email_confirmation_message(request, email_confirmation)- subject = "[Saleor] Email confirmation"+ subject = '[Saleor] Email confirmation'EmailMessage(subject, message, to=[submitted_email]).send()messages.warning(request,- "We have sent you a confirmation email. "- "Please check your email.")+ 'We have sent you a confirmation email. '+ 'Please check your email.')return redirect('home')return TemplateResponse(request, 'registration/register.html',@@ -157,8 +158,8 @@ def confirm_email(request, pk, token):auth_login(request, user)messages.success(request,- "You have been successfully logged in, %s" % user.email)+ 'You have been successfully logged in, %s' % (user.email,))return redirect('home')else:return TemplateResponse(- request, "registration/set_password.html", {"form": form})+ request, 'registration/set_password.html', {'form': form})