-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: convert CEUs to decimal #3217
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.2.16 on 2024-11-06 06:35 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("cms", "0072_add_hybrid_courseware_format_option"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="certificatepage", | ||
name="CEUs", | ||
field=models.DecimalField( | ||
blank=True, | ||
decimal_places=2, | ||
help_text="Optional field for CEU (continuing education unit).", | ||
max_digits=5, | ||
null=True, | ||
), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1074,7 +1074,9 @@ def get_context(self, request, *args, **kwargs): | |
"techniques": self.techniques, | ||
"propel_career": self.propel_career, | ||
"news_and_events": self.news_and_events, | ||
"ceus": self.certificate_page.CEUs if self.certificate_page else None, | ||
"ceus": self.certificate_page.normalized_ceus | ||
if self.certificate_page | ||
else None, | ||
} | ||
|
||
def save(self, clean=True, user=None, log_action=False, **kwargs): # noqa: FBT002 | ||
|
@@ -2142,11 +2144,12 @@ class PartnerLogoPlacement(models.IntegerChoices): | |
max_length=255, null=True, blank=True, help_text="Specify the institute text" | ||
) | ||
|
||
CEUs = models.CharField( # noqa: DJ001 | ||
max_length=250, | ||
CEUs = models.DecimalField( | ||
null=True, | ||
blank=True, | ||
help_text="Optional text field for CEU (continuing education unit).", | ||
decimal_places=2, | ||
max_digits=5, | ||
help_text="Optional field for CEU (continuing education unit).", | ||
Comment on lines
+2150
to
+2152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This allows -ve values too. We will need to add validators. |
||
) | ||
|
||
partner_logo = models.ForeignKey( | ||
|
@@ -2242,6 +2245,13 @@ def parent(self): | |
""" | ||
return self.get_parent().specific | ||
|
||
@property | ||
def normalized_ceus(self): | ||
""" | ||
Normalizes the CEUs from decimal to string. Removes the trailing zeros if any. | ||
""" | ||
return f"{self.CEUs.normalize():f}" if self.CEUs else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't a simple |
||
|
||
def get_context(self, request, *args, **kwargs): | ||
preview_context = {} | ||
context = {} | ||
|
@@ -2255,14 +2265,14 @@ def get_context(self, request, *args, **kwargs): | |
"end_date": self.parent.product.first_unexpired_run.end_date | ||
if self.parent.product.first_unexpired_run | ||
else datetime.now() + timedelta(days=45), # noqa: DTZ005 | ||
"CEUs": self.CEUs, | ||
"CEUs": self.normalized_ceus, | ||
} | ||
elif self.certificate: | ||
# Verify that the certificate in fact is for this same course | ||
if self.parent.product.id != self.certificate.get_courseware_object_id(): | ||
raise Http404 | ||
start_date, end_date = self.certificate.start_end_dates | ||
CEUs = self.CEUs | ||
CEUs = self.normalized_ceus | ||
|
||
for override in self.overrides: | ||
if ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import re | ||
import time | ||
from datetime import timedelta | ||
from decimal import Decimal | ||
from enum import Enum | ||
from pathlib import Path | ||
|
||
|
@@ -120,7 +121,7 @@ def __init__(self, emeritus_course_json): | |
self.format = emeritus_course_json.get("format") | ||
self.category = emeritus_course_json.get("Category", None) | ||
self.image_name = emeritus_course_json.get("image_name", None) | ||
self.CEUs = str(emeritus_course_json.get("ceu") or "") | ||
self.CEUs = Decimal(str(emeritus_course_json.get("ceu"))) or None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails on null CEU values |
||
self.learning_outcomes_list = ( | ||
parse_emeritus_data_str(emeritus_course_json.get("learning_outcomes")) | ||
if emeritus_course_json.get("learning_outcomes") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Keeping the same format of how we are using other properties, we might just want to move the if/else inside the normalized_ceus method.