mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-20 17:50:16 -04:00
fix(profile): use Decimal in GPA tests
This commit is contained in:
parent
1c70273a1c
commit
1ddad17a1e
|
@ -6,13 +6,19 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('authentication', '0012_user_preferred_name'),
|
("authentication", "0012_user_preferred_name"),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='user',
|
model_name="user",
|
||||||
name='GPA',
|
name="GPA",
|
||||||
field=models.DecimalField(blank=True, decimal_places=3, help_text='Weighted GPA', max_digits=4, null=True),
|
field=models.DecimalField(
|
||||||
|
blank=True,
|
||||||
|
decimal_places=3,
|
||||||
|
help_text="Weighted GPA",
|
||||||
|
max_digits=4,
|
||||||
|
null=True,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,7 +8,14 @@ class User(AbstractUser):
|
||||||
accepted_terms = models.BooleanField(default=False)
|
accepted_terms = models.BooleanField(default=False)
|
||||||
graduation_year = models.PositiveSmallIntegerField(null=True)
|
graduation_year = models.PositiveSmallIntegerField(null=True)
|
||||||
|
|
||||||
GPA = models.DecimalField(null=True, blank=True, name="GPA", help_text="Weighted GPA", max_digits=4, decimal_places=3)
|
GPA = models.DecimalField(
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
name="GPA",
|
||||||
|
help_text="Weighted GPA",
|
||||||
|
max_digits=4,
|
||||||
|
decimal_places=3,
|
||||||
|
)
|
||||||
|
|
||||||
is_senior = models.BooleanField(default=False)
|
is_senior = models.BooleanField(default=False)
|
||||||
is_student = models.BooleanField(default=False)
|
is_student = models.BooleanField(default=False)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
from decimal import Decimal
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
from crispy_forms.helper import FormHelper
|
from crispy_forms.helper import FormHelper
|
||||||
|
@ -28,7 +29,7 @@ class ProfilePublishForm(forms.ModelForm):
|
||||||
# Check the GPA: 0.0 <= GPA <= 5.0
|
# Check the GPA: 0.0 <= GPA <= 5.0
|
||||||
if cleaned_data.get("GPA"):
|
if cleaned_data.get("GPA"):
|
||||||
gpa = cleaned_data.get("GPA")
|
gpa = cleaned_data.get("GPA")
|
||||||
assert isinstance(gpa, float)
|
assert isinstance(gpa, Decimal)
|
||||||
if not 0.0 <= gpa <= 5.0:
|
if not 0.0 <= gpa <= 5.0:
|
||||||
self.add_error("GPA", "This is not a valid GPA")
|
self.add_error("GPA", "This is not a valid GPA")
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from tjdests.apps.authentication.models import User
|
from tjdests.apps.authentication.models import User
|
||||||
|
@ -44,7 +46,7 @@ class ProfileTest(TJDestsTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
1,
|
1,
|
||||||
User.objects.filter(
|
User.objects.filter(
|
||||||
GPA=4.000,
|
GPA=Decimal(4.000),
|
||||||
id=user.id,
|
id=user.id,
|
||||||
biography="hello",
|
biography="hello",
|
||||||
attending_decision=None,
|
attending_decision=None,
|
||||||
|
@ -92,7 +94,7 @@ class ProfileTest(TJDestsTestCase):
|
||||||
1,
|
1,
|
||||||
User.objects.filter(
|
User.objects.filter(
|
||||||
id=user.id,
|
id=user.id,
|
||||||
GPA=3.141,
|
GPA=Decimal(3.141),
|
||||||
biography="hello2",
|
biography="hello2",
|
||||||
attending_decision=decision,
|
attending_decision=decision,
|
||||||
publish_data=True,
|
publish_data=True,
|
||||||
|
@ -123,7 +125,7 @@ class ProfileTest(TJDestsTestCase):
|
||||||
1,
|
1,
|
||||||
User.objects.filter(
|
User.objects.filter(
|
||||||
id=user.id,
|
id=user.id,
|
||||||
GPA=3.141,
|
GPA=Decimal(3.141),
|
||||||
biography="hello2",
|
biography="hello2",
|
||||||
attending_decision=decision,
|
attending_decision=decision,
|
||||||
publish_data=True,
|
publish_data=True,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user