forked from Beta-Persei/vaccination-slot-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,9 @@ class Meta: | |
] | ||
widgets = { | ||
"email": forms.TextInput(attrs={"placeholder": "[email protected]"}), | ||
"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,55 +40,81 @@ 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") | ||
phone_number = cleaned_data.get("phone_number") | ||
|
||
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") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,10 @@ def setUp(self): | |
phone_number="9999999999", district_id=1 | ||
) | ||
self.subscriber3 = Subscriber.objects.create( | ||
email="[email protected]", phone_number="9999999999", pincode=222222, district_id=2 | ||
email="[email protected]", | ||
phone_number="9999999999", | ||
pincode=222222, | ||
district_id=2, | ||
) | ||
|
||
self.test_centers = [ | ||
|
22 changes: 0 additions & 22 deletions
22
subscribers/tests/test_tasks.py.103b43e9630af265634bea6b5700d287.tmp
This file was deleted.
Oops, something went wrong.