Commit 9ea23b852dbefbce275777b5cd149e7fecae4464
1 parent
4bfc0010
Exists in
master
and in
33 other branches
Fixed code style
Showing
2 changed files
with
17 additions
and
16 deletions
Show diff stats
colab/accounts/forms.py
... | ... | @@ -12,8 +12,6 @@ from django.utils.encoding import force_bytes |
12 | 12 | from django.utils.http import urlsafe_base64_encode |
13 | 13 | from django.utils.text import capfirst |
14 | 14 | from django.utils.translation import ugettext_lazy as _ |
15 | -from django.core.validators import validate_email | |
16 | -from django.core.exceptions import ValidationError | |
17 | 15 | from django.utils.safestring import mark_safe |
18 | 16 | |
19 | 17 | from conversejs.models import XMPPAccount |
... | ... | @@ -66,10 +64,12 @@ class UserForm(forms.ModelForm): |
66 | 64 | email = self.cleaned_data.get('email') |
67 | 65 | username = self.cleaned_data.get('username') |
68 | 66 | |
69 | - if email and User.objects.filter(email=email).exclude( | |
70 | - username=username).count(): | |
71 | - raise forms.ValidationError( | |
72 | - mark_safe("Try login in: <a href='login'>sign in<a/>")) | |
67 | + user_qs = User.objects.filter(email=email).exclude(username=username) | |
68 | + | |
69 | + if email and user_qs.exists(): | |
70 | + msg = mark_safe("Try login in: <a href='login'>sign in<a/>") | |
71 | + raise forms.ValidationError(msg) | |
72 | + | |
73 | 73 | return email |
74 | 74 | |
75 | 75 | def clean_username(self): | ... | ... |
colab/accounts/tests/test_forms.py
... | ... | @@ -2,12 +2,13 @@ |
2 | 2 | Test Form class. |
3 | 3 | Objective: Test parameters, and behavior. |
4 | 4 | """ |
5 | +from re import search | |
6 | + | |
7 | +from django.test import TestCase | |
8 | + | |
5 | 9 | from colab.accounts.forms import UserForm |
6 | 10 | from colab.accounts.models import User |
7 | -from django.test import TestCase, Client | |
8 | -from django import forms | |
9 | -from django.core.exceptions import ValidationError | |
10 | -from re import search | |
11 | + | |
11 | 12 | |
12 | 13 | class FormTest(TestCase): |
13 | 14 | |
... | ... | @@ -24,12 +25,12 @@ class FormTest(TestCase): |
24 | 25 | user.save() |
25 | 26 | |
26 | 27 | def create_form_data(self): |
27 | - form_data = {'email': 'usertest@colab.com.br', | |
28 | - 'first_name': 'colabName', | |
29 | - 'last_name': 'secondName', | |
30 | - 'username': 'colab', | |
31 | - 'password1': '123colab4', | |
32 | - 'password2': '123colab4'} | |
28 | + form_data = {'email': 'usertest@colab.com.br', | |
29 | + 'first_name': 'colabName', | |
30 | + 'last_name': 'secondName', | |
31 | + 'username': 'colab', | |
32 | + 'password1': '123colab4', | |
33 | + 'password2': '123colab4'} | |
33 | 34 | form = UserForm(data=form_data) |
34 | 35 | return form |
35 | 36 | ... | ... |