From 7601e5f51000875deafa2a222e82560c168bd745 Mon Sep 17 00:00:00 2001 From: Abhinav Gautam Date: Tue, 21 Aug 2018 23:16:43 +0530 Subject: [PATCH 1/2] Added support for international phone numbers in volunteer model --- floodrelief/settings.py | 3 +++ mainapp/migrations/0069_auto_20180821_2231.py | 19 +++++++++++++++++++ mainapp/migrations/0070_auto_20180821_2302.py | 19 +++++++++++++++++++ mainapp/migrations/0071_auto_20180821_2308.py | 19 +++++++++++++++++++ mainapp/models.py | 7 ++----- requirements.txt | 1 + 6 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 mainapp/migrations/0069_auto_20180821_2231.py create mode 100644 mainapp/migrations/0070_auto_20180821_2302.py create mode 100644 mainapp/migrations/0071_auto_20180821_2308.py diff --git a/floodrelief/settings.py b/floodrelief/settings.py index 714a83568..c7bea13d1 100644 --- a/floodrelief/settings.py +++ b/floodrelief/settings.py @@ -57,6 +57,7 @@ def get_list(text): # Application definition INSTALLED_APPS = [ + 'phonenumber_field', 'mainapp.apps.MainappConfig', 'django.contrib.admin', 'django.contrib.auth', @@ -73,6 +74,8 @@ def get_list(text): 'rest_auth', ] +PHONENUMBER_DEFAULT_REGION = 'IN' + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'whitenoise.middleware.WhiteNoiseMiddleware', diff --git a/mainapp/migrations/0069_auto_20180821_2231.py b/mainapp/migrations/0069_auto_20180821_2231.py new file mode 100644 index 000000000..80ac444dc --- /dev/null +++ b/mainapp/migrations/0069_auto_20180821_2231.py @@ -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'), + ), + ] diff --git a/mainapp/migrations/0070_auto_20180821_2302.py b/mainapp/migrations/0070_auto_20180821_2302.py new file mode 100644 index 000000000..4b3507ddb --- /dev/null +++ b/mainapp/migrations/0070_auto_20180821_2302.py @@ -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'), + ), + ] diff --git a/mainapp/migrations/0071_auto_20180821_2308.py b/mainapp/migrations/0071_auto_20180821_2308.py new file mode 100644 index 000000000..363cb221d --- /dev/null +++ b/mainapp/migrations/0071_auto_20180821_2308.py @@ -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'), + ), + ] diff --git a/mainapp/models.py b/mainapp/models.py index b98302dcc..21195d8b8 100644 --- a/mainapp/models.py +++ b/mainapp/models.py @@ -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 @@ -169,10 +169,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', 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( diff --git a/requirements.txt b/requirements.txt index 8c9e4a91c..45c3a1ec3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,3 +20,4 @@ pillow==5.2.0 boto3==1.7.80 botocore==1.10.80 django-storages==1.6.6 +django-phonenumber-field \ No newline at end of file From 617ac033a8eea4cb6dfb52b871e0ab3084065cdd Mon Sep 17 00:00:00 2001 From: Abhinav Gautam Date: Tue, 21 Aug 2018 23:27:39 +0530 Subject: [PATCH 2/2] added migrations --- mainapp/migrations/0072_merge_20180821_2326.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 mainapp/migrations/0072_merge_20180821_2326.py diff --git a/mainapp/migrations/0072_merge_20180821_2326.py b/mainapp/migrations/0072_merge_20180821_2326.py new file mode 100644 index 000000000..4f6898eab --- /dev/null +++ b/mainapp/migrations/0072_merge_20180821_2326.py @@ -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 = [ + ]