Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase phone size #28

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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)
1 change: 1 addition & 0 deletions member_manager/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
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())