mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-18 17:20:15 -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):
|
||||
|
||||
dependencies = [
|
||||
('authentication', '0012_user_preferred_name'),
|
||||
("authentication", "0012_user_preferred_name"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='GPA',
|
||||
field=models.DecimalField(blank=True, decimal_places=3, help_text='Weighted GPA', max_digits=4, null=True),
|
||||
model_name="user",
|
||||
name="GPA",
|
||||
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)
|
||||
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_student = models.BooleanField(default=False)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from decimal import Decimal
|
||||
from typing import Any, Dict
|
||||
|
||||
from crispy_forms.helper import FormHelper
|
||||
|
@ -28,7 +29,7 @@ class ProfilePublishForm(forms.ModelForm):
|
|||
# Check the GPA: 0.0 <= GPA <= 5.0
|
||||
if cleaned_data.get("GPA"):
|
||||
gpa = cleaned_data.get("GPA")
|
||||
assert isinstance(gpa, float)
|
||||
assert isinstance(gpa, Decimal)
|
||||
if not 0.0 <= gpa <= 5.0:
|
||||
self.add_error("GPA", "This is not a valid GPA")
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from decimal import Decimal
|
||||
|
||||
from django.urls import reverse
|
||||
|
||||
from tjdests.apps.authentication.models import User
|
||||
|
@ -44,7 +46,7 @@ class ProfileTest(TJDestsTestCase):
|
|||
self.assertEqual(
|
||||
1,
|
||||
User.objects.filter(
|
||||
GPA=4.000,
|
||||
GPA=Decimal(4.000),
|
||||
id=user.id,
|
||||
biography="hello",
|
||||
attending_decision=None,
|
||||
|
@ -92,7 +94,7 @@ class ProfileTest(TJDestsTestCase):
|
|||
1,
|
||||
User.objects.filter(
|
||||
id=user.id,
|
||||
GPA=3.141,
|
||||
GPA=Decimal(3.141),
|
||||
biography="hello2",
|
||||
attending_decision=decision,
|
||||
publish_data=True,
|
||||
|
@ -123,7 +125,7 @@ class ProfileTest(TJDestsTestCase):
|
|||
1,
|
||||
User.objects.filter(
|
||||
id=user.id,
|
||||
GPA=3.141,
|
||||
GPA=Decimal(3.141),
|
||||
biography="hello2",
|
||||
attending_decision=decision,
|
||||
publish_data=True,
|
||||
|
|
Loading…
Reference in New Issue
Block a user