-
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?
Conversation
638451b
to
85b997f
Compare
85b997f
to
ef3d652
Compare
@asadali145 could you rebase this PR? |
ef3d652
to
5eabdca
Compare
@arslanashraf7 Done! |
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.
Left a couple of changes.
cms/models.py
Outdated
"ceus": self.certificate_page.normalized_ceus | ||
if self.certificate_page | ||
else None, | ||
} |
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.
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.
normalized_ceus is a property of CertificatePage and this usage is in ProductPage. We cannot check this in normalized_ceus.
cms/models.py
Outdated
""" | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't a simple str()
conversion be better?
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.
str
does not remove trailing zeros, This property is mostly used for display purposes, so, we don't need trailing zeros. That is why I used normalize.
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.
I noted this because there are many courses in production that have .0
format at least. You can find them in /api/courses
and search for credits
. I don't know if the consumers of the APIs can break if they don't find .0s that's why I wanted to make sure that we keep the exact same format for the APIs to keep the external consumers from breaking.
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.
Confirmed with Matt that this is OKay with MIT Learn. I will confirm with Bon today.
cms/models.py
Outdated
decimal_places=2, | ||
max_digits=5, | ||
help_text="Optional field for CEU (continuing education unit).", |
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.
This allows -ve values too. We will need to add validators.
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.
Fixed in 85b1c00
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
This fails on null CEU values
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.
Good Catch!
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.
Fixed in 85b1c00
4f7601c
to
85b1c00
Compare
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.
👍 Just some thoughts and one small change.
cms/models.py
Outdated
help_text="Optional text field for CEU (continuing education unit).", | ||
decimal_places=2, | ||
max_digits=5, | ||
validators=[MinValueValidator(Decimal("0.01"))], |
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.
I think this should be zero otherwise it will never allow them to make CEUs Zero if needed in future revisions.
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.
Fixed in f005f49
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.
👍
f005f49
to
80d44eb
Compare
review changes revert unintended change recreate migration
80d44eb
to
88ce0dd
Compare
@arslanashraf7 This should be good to review. |
What are the relevant tickets?
Closes https://github.com/mitodl/hq/issues/5834
Description (What does it do?)
Converts CEUs from string to decimal to avoid issues.
How can this be tested?
api/courses
, should be null or decimalapi/programs
, should be null or decimal for each course and null or decimal for the program itselfbuild_course_run_credential
andbuild_program_credential
, But we should verify that CEUs are returned in the data. I verified it through shell