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

Added support for international phone numbers in volunteer model #846

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions floodrelief/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def get_list(text):
# Application definition

INSTALLED_APPS = [
'phonenumber_field',
'mainapp.apps.MainappConfig',
'django.contrib.admin',
'django.contrib.auth',
Expand All @@ -73,6 +74,8 @@ def get_list(text):
'rest_auth',
]

PHONENUMBER_DEFAULT_REGION = 'IN'

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
Expand Down
19 changes: 19 additions & 0 deletions mainapp/migrations/0069_auto_20180821_2231.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.1 on 2018-08-21 17:01

from django.db import migrations
import phonenumber_field.modelfields


class Migration(migrations.Migration):

dependencies = [
('mainapp', '0068_auto_20180821_1710'),
]

operations = [
migrations.AlterField(
model_name='volunteer',
name='phone',
field=phonenumber_field.modelfields.PhoneNumberField(max_length=128, verbose_name='Phone - ഫോണ്\u200d നമ്പര്\u200d'),
),
]
19 changes: 19 additions & 0 deletions mainapp/migrations/0070_auto_20180821_2302.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.1 on 2018-08-21 17:32

from django.db import migrations
import phonenumber_field.modelfields


class Migration(migrations.Migration):

dependencies = [
('mainapp', '0069_auto_20180821_2231'),
]

operations = [
migrations.AlterField(
model_name='volunteer',
name='phone',
field=phonenumber_field.modelfields.PhoneNumberField(error_messages={'invalid': 'Add + for International Phone Number'}, max_length=128, verbose_name='Phone - ഫോണ്\u200d നമ്പര്\u200d'),
),
]
19 changes: 19 additions & 0 deletions mainapp/migrations/0071_auto_20180821_2308.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.1 on 2018-08-21 17:38

from django.db import migrations
import phonenumber_field.modelfields


class Migration(migrations.Migration):

dependencies = [
('mainapp', '0070_auto_20180821_2302'),
]

operations = [
migrations.AlterField(
model_name='volunteer',
name='phone',
field=phonenumber_field.modelfields.PhoneNumberField(error_messages={'invalid': 'Please enter a valid phone number. Add + in the beginning for International Phone Number'}, max_length=128, verbose_name='Phone - ഫോണ്\u200d നമ്പര്\u200d'),
),
]
14 changes: 14 additions & 0 deletions mainapp/migrations/0072_merge_20180821_2326.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.1 on 2018-08-21 17:56

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('mainapp', '0071_auto_20180821_2308'),
('mainapp', '0069_auto_20180821_1929'),
]

operations = [
]
7 changes: 2 additions & 5 deletions mainapp/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import uuid
from enum import Enum

from phonenumber_field.modelfields import PhoneNumberField
from django.db import models
from django.core.validators import RegexValidator
from django.contrib.auth.models import User
Expand Down Expand Up @@ -179,10 +179,7 @@ class Volunteer(models.Model):
verbose_name="District - ജില്ല"
)
name = models.CharField(max_length=100, verbose_name="Name - പേര്")

phone_number_regex = RegexValidator(regex='^((\+91|91|0)[\- ]{0,1})?[456789]\d{9}$', message='Please Enter 10 digit mobile number or landline as 0<std code><phone number>', code='invalid_mobile')
phone = models.CharField(max_length=14, verbose_name="Phone - ഫോണ്‍ നമ്പര്‍", validators=[phone_number_regex])

phone = PhoneNumberField(verbose_name="Phone - ഫോണ്‍ നമ്പര്‍", error_messages={"invalid":"Please enter a valid phone number. Add + in the beginning for International Phone Number"})
organisation = models.CharField(max_length=250, verbose_name="Organization (സംഘടന) / Institution")
address = models.TextField(verbose_name="Address - വിലാസം")
area = models.CharField(
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ pillow==5.2.0
boto3==1.7.80
botocore==1.10.80
django-storages==1.6.6
beautifulsoup4==4.6.3

django-phonenumber-field
beautifulsoup4==4.6.3