-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from 4sfc/increase-phone-size
Increase phone size
- Loading branch information
Showing
4 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""ProfileForm class""" | ||
|
||
from django import forms | ||
from django.core.exceptions import ValidationError | ||
from django.utils.translation import gettext as _ | ||
|
||
from member_manager.models.profile import Profile | ||
|
||
|
||
class ProfileForm(forms.ModelForm): | ||
"""ProfileForm class inherits custom save""" | ||
|
||
def clean_phone(self): | ||
"""Clean phone field""" | ||
data = self.cleaned_data['phone'] | ||
if len(data) != 10: | ||
raise ValidationError(_('Enter a valid 10-digit phone number.')) | ||
if not data.isdigit(): | ||
raise ValidationError(_('Enter only numbers--e.g., 1234567890.')) | ||
return data | ||
|
||
class Meta: | ||
model = Profile | ||
fields = ['first_name', 'last_name', 'pronouns', 'email', 'phone', | ||
'join_reason', 'how_heard', 'how_heard_other'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""ProfileFormTest class""" | ||
|
||
from django.test import TestCase | ||
|
||
from member_manager.forms.profile import ProfileForm | ||
|
||
|
||
class ProfileFormTest(TestCase): | ||
"""ProfileFormTest tests ProfileForm""" | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
cls.data = {'first_name': 'foo', 'last_name': 'bar', | ||
'email': '[email protected]'} | ||
|
||
def test_long_phone(self): | ||
"""Test invalid long phone""" | ||
data = self.data.update({'phone': '12345678900'}) | ||
form = ProfileForm(data=data) | ||
self.assertFalse(form.is_valid()) | ||
|
||
def test_nondigit_phone(self): | ||
"""Test invalid nondigit phone""" | ||
data = self.data.update({'phone': '123abc7890'}) | ||
form = ProfileForm(data=data) | ||
self.assertFalse(form.is_valid()) | ||
|
||
def test_valid_phone(self): | ||
"""Test valid nondigit phone""" | ||
data = self.data | ||
for number in ['9999999999', '0000000000']: | ||
data['phone'] = number | ||
form = ProfileForm(data=data) | ||
self.assertTrue(form.is_valid()) |