Skip to content

Commit

Permalink
Merge pull request #28 from 4sfc/increase-phone-size
Browse files Browse the repository at this point in the history
Increase phone size
  • Loading branch information
jwokaty authored Oct 8, 2020
2 parents 44e76fc + e57a30e commit 670fe91
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
25 changes: 25 additions & 0 deletions member_manager/forms/profile.py
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']
4 changes: 2 additions & 2 deletions member_manager/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Profile(Timestamp):
last_name = models.CharField(db_index=True, max_length=191)
pronouns = models.CharField(max_length=191, blank=True, null=True)
email = models.EmailField(db_index=True, max_length=191, unique=True)
phone = models.PositiveIntegerField(help_text='Enter only numbers.',
unique=True)
phone = models.CharField(max_length=10, unique=True,
help_text='Enter only numbers--e.g., 1234567890')
active = models.BooleanField(default=True, null=False)
user = models.OneToOneField(User, blank=True, null=True,
on_delete=models.SET_NULL)
Expand Down
1 change: 1 addition & 0 deletions member_manager/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
from member_manager.tests.page import PageTest
from member_manager.tests.profile import ProfileTest
from member_manager.tests.profile_form import ProfileFormTest
from member_manager.tests.profile_skill import ProfileSkillTest
from member_manager.tests.published import PublishedListFilterTest
from member_manager.tests.skill import SkillTest
Expand Down
34 changes: 34 additions & 0 deletions member_manager/tests/profile_form.py
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())

0 comments on commit 670fe91

Please sign in to comment.