From 81a31208b16607de5207af646d91883843686ed3 Mon Sep 17 00:00:00 2001 From: Alisamar Husain Date: Wed, 19 May 2021 23:58:28 +0530 Subject: [PATCH] Fix formatting issues --- subscribers/forms.py | 94 ++++++++++++------- subscribers/models.py | 17 +++- subscribers/tests/test_models.py | 5 +- ...ks.py.103b43e9630af265634bea6b5700d287.tmp | 22 ----- 4 files changed, 77 insertions(+), 61 deletions(-) delete mode 100644 subscribers/tests/test_tasks.py.103b43e9630af265634bea6b5700d287.tmp diff --git a/subscribers/forms.py b/subscribers/forms.py index 4aba31c..7b31e5a 100644 --- a/subscribers/forms.py +++ b/subscribers/forms.py @@ -28,7 +28,9 @@ class Meta: ] widgets = { "email": forms.TextInput(attrs={"placeholder": "you@example.com"}), - "phone_number": forms.TextInput(attrs={"placeholder": "10-digit number (Optional)"}), + "phone_number": forms.TextInput( + attrs={"placeholder": "10-digit number (Optional)"} + ), "pincode": forms.TextInput(attrs={"placeholder": "110006"}), "district_id": forms.Select, } @@ -38,25 +40,35 @@ def clean(self): error = {} if not cleaned_data.get("email") and not cleaned_data.get("phone_number"): - error.update({ - "email": "Please enter either email or phone number.", - "phone_number": "Please enter either email or phone number.", - }) + error.update( + { + "email": "Please enter either email or phone number.", + "phone_number": "Please enter either email or phone number.", + } + ) - if cleaned_data.get("search_type") == SEARCH_TYPE_CHOICES[0][0] and not cleaned_data.get("pincode"): - error.update({ - "pincode": "Please enter your pincode", - }) + if cleaned_data.get("search_type") == SEARCH_TYPE_CHOICES[0][ + 0 + ] and not cleaned_data.get("pincode"): + error.update( + { + "pincode": "Please enter your pincode", + } + ) if cleaned_data.get("search_type") == SEARCH_TYPE_CHOICES[1][0]: if not cleaned_data.get("state"): - error.update({ - "state": "Please select your State", - }) + error.update( + { + "state": "Please select your State", + } + ) if not cleaned_data.get("district_id"): - error.update({ - "district_id": "Please select your district", - }) + error.update( + { + "district_id": "Please select your district", + } + ) if cleaned_data.get("email") or cleaned_data.get("phone_number"): email = cleaned_data.get("email") @@ -64,29 +76,45 @@ def clean(self): if cleaned_data.get("pincode"): if email: - if Subscriber.objects.filter(email=email, pincode=cleaned_data.get("pincode")).exists(): - error.update({ - "pincode": "You have already subscribed at this pincode.", - }) + if Subscriber.objects.filter( + email=email, pincode=cleaned_data.get("pincode") + ).exists(): + error.update( + { + "pincode": "You have already subscribed at this pincode.", + } + ) elif phone_number: - if Subscriber.objects.filter(phone_number=phone_number, pincode=cleaned_data.get("pincode")).exists(): - error.update({ - "pincode": "You have already subscribed at this pincode.", - }) + if Subscriber.objects.filter( + phone_number=phone_number, pincode=cleaned_data.get("pincode") + ).exists(): + error.update( + { + "pincode": "You have already subscribed at this pincode.", + } + ) if cleaned_data.get("district_id"): if email: - if Subscriber.objects.filter(email=email, district_id=cleaned_data.get("district_id")).exists(): - error.update({ - "district_id": "You have already subscribed at this district.", - }) + if Subscriber.objects.filter( + email=email, district_id=cleaned_data.get("district_id") + ).exists(): + error.update( + { + "district_id": "You have already subscribed at this district.", + } + ) elif phone_number: - if Subscriber.objects.filter(phone_number=phone_number, district_id=cleaned_data.get("district_id")).exists(): - error.update({ - "pincode": "You have already subscribed at this district.", - }) - - + if Subscriber.objects.filter( + phone_number=phone_number, + district_id=cleaned_data.get("district_id"), + ).exists(): + error.update( + { + "district_id": "You have already subscribed at this district.", + } + ) + if cleaned_data.get("pincode") and cleaned_data.get("district_id"): cleaned_data.pop("district_id") diff --git a/subscribers/models.py b/subscribers/models.py index 1152031..e89886e 100644 --- a/subscribers/models.py +++ b/subscribers/models.py @@ -28,12 +28,17 @@ class Subscriber(models.Model): validators=[MinValueValidator(100000), MaxValueValidator(999999)], blank=True, null=True, - help_text = "Don't know your pincode? Use 'By District'" + help_text="Don't know your pincode? Use 'By District'", + ) + district_id = models.IntegerField( + "district", + blank=True, + null=True, + help_text="Districts are based on voting districts", ) - district_id = models.IntegerField("district", blank=True, null=True, help_text = "Districts are based on voting districts") age_limit = models.IntegerField( "age limit", - help_text = "Select your age category", + help_text="Select your age category", choices=AGE_CATEGORY, default=AGE_CATEGORY[0][0], null=False, @@ -55,8 +60,10 @@ class Subscriber(models.Model): def __str__(self): s = [] - if self.email: s.append(str(self.email)) - if self.phone_number: s.append(str(self.phone_number)) + if self.email: + s.append(str(self.email)) + if self.phone_number: + s.append(str(self.phone_number)) return " ".join(s) diff --git a/subscribers/tests/test_models.py b/subscribers/tests/test_models.py index c964029..17f4bca 100644 --- a/subscribers/tests/test_models.py +++ b/subscribers/tests/test_models.py @@ -21,7 +21,10 @@ def setUp(self): phone_number="9999999999", district_id=1 ) self.subscriber3 = Subscriber.objects.create( - email="foo@bar.com", phone_number="9999999999", pincode=222222, district_id=2 + email="foo@bar.com", + phone_number="9999999999", + pincode=222222, + district_id=2, ) self.test_centers = [ diff --git a/subscribers/tests/test_tasks.py.103b43e9630af265634bea6b5700d287.tmp b/subscribers/tests/test_tasks.py.103b43e9630af265634bea6b5700d287.tmp deleted file mode 100644 index 9d5c753..0000000 --- a/subscribers/tests/test_tasks.py.103b43e9630af265634bea6b5700d287.tmp +++ /dev/null @@ -1,22 +0,0 @@ -from django.test import TestCase - -from subscribers.models import Subscriber -from subscribers.tasks import refresh_sms_count - - - -class TestSubscriberUtils(TestCase): - - def setUp(self): - self.subscribers = [Subscriber.objects.create( - email="foo@bar.com", pincode=111111, daily_sms_count=10 - ), - Subscriber.objects.create( - phone_number="9999999999", district_id=1, daily_sms_count=12 - )] - - return super().setUp() - - - def test_refresh_sms_count(self): -