mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-20 17:50:16 -04:00
feat(profile): limit GPA to reasonable values
GPA must be 0 <= GPA <= 5
This commit is contained in:
parent
f7a2dd1768
commit
23cda5d64d
|
@ -22,6 +22,18 @@ class ProfilePublishForm(forms.ModelForm):
|
|||
user=self.instance, admission_status__contains="ADMIT"
|
||||
)
|
||||
|
||||
def clean(self) -> Dict[str, Any]:
|
||||
cleaned_data = super().clean()
|
||||
|
||||
# Check the GPA: 0.0 <= GPA <= 5.0
|
||||
if cleaned_data.get("GPA"):
|
||||
gpa = cleaned_data.get("GPA")
|
||||
assert type(gpa) is float
|
||||
if not 0.0 <= gpa <= 5.0:
|
||||
self.add_error("GPA", "This is not a valid GPA")
|
||||
|
||||
return cleaned_data
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ["publish_data", "GPA", "biography", "attending_decision"]
|
||||
|
|
|
@ -52,6 +52,26 @@ class ProfileTest(TJDestsTestCase):
|
|||
).count(),
|
||||
)
|
||||
|
||||
response = self.client.post(
|
||||
reverse("profile:index"),
|
||||
data={
|
||||
"biography": "sdf",
|
||||
"attending_decision": "",
|
||||
"publish_data": False,
|
||||
},
|
||||
)
|
||||
self.assertEqual(200, response.status_code)
|
||||
self.assertEqual(
|
||||
1,
|
||||
User.objects.filter(
|
||||
GPA=None,
|
||||
id=user.id,
|
||||
biography="sdf",
|
||||
attending_decision=None,
|
||||
publish_data=False,
|
||||
).count(),
|
||||
)
|
||||
|
||||
# Test creating an admitted decision, then setting that as our destination.
|
||||
college = College.objects.get_or_create(name="test college")[0]
|
||||
decision = Decision.objects.get_or_create(
|
||||
|
|
Loading…
Reference in New Issue
Block a user