-
Notifications
You must be signed in to change notification settings - Fork 48
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: adds attribute to hide course prices when zero #1788
Closed
tecoholic
wants to merge
10
commits into
openedx:master
from
open-craft:tecoholic/BB-7541-hide-price-in-enrollment-page
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7740dcd
feat: adds attribute to hide course prices when zero
tecoholic 4f37ab1
fix: removed unused variable from template context
tecoholic 5f2f7fb
fix: quality issue and add the new attribute to test
tecoholic f8caa06
fix: update the help text in the db migration
tecoholic 9a650e2
feat: adds final price to logging
tecoholic 8413dfe
fix: change the attribute in the utils test causing test failure
tecoholic d4b04a3
refactor: renamed the migration file
tecoholic f4a10ca
chore: rebase on master and update db migration
tecoholic d4ac14d
fix: remove empty lines causing linting failure
tecoholic 219e3f1
fix: remove the empty line in tests file
tecoholic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 3.2.23 on 2023-12-08 05:36 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('enterprise', '0197_auto_20231130_2239'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='enterprisecustomer', | ||
name='hide_course_price_when_zero', | ||
field=models.BooleanField(default=False, help_text='Specify whether course cost should be hidden in the landing page when the final price is zero.'), | ||
), | ||
migrations.AddField( | ||
model_name='historicalenterprisecustomer', | ||
name='hide_course_price_when_zero', | ||
field=models.BooleanField(default=False, help_text='Specify whether course cost should be hidden in the landing page when the final price is zero.'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2382,3 +2382,28 @@ def truncate_string(string, max_length=MAX_ALLOWED_TEXT_LENGTH): | |
was_truncated = True | ||
return (truncated_string, was_truncated) | ||
return (string, was_truncated) | ||
|
||
|
||
def hide_price_when_zero(enterprise_customer, course_modes): | ||
""" | ||
Adds a "hide_price" flag to the course modes if price is zero and "Hide course price when zero" flag is set. | ||
|
||
Arguments: | ||
enterprise_customer: The EnterpriseCustomer that the enrollemnt is being done. | ||
course_modes: iterable with dictionaries containing a required 'final_price' key | ||
""" | ||
if not enterprise_customer.hide_course_price_when_zero: | ||
return course_modes | ||
|
||
for mode in course_modes: | ||
mode['hide_price'] = False | ||
try: | ||
numbers = re.findall(r'\d+', mode['final_price']) | ||
mode['hide_price'] = int(''.join(numbers)) == 0 | ||
except ValueError: | ||
LOGGER.warning( | ||
'hide_price_when_zero: Could not convert price "%s" of course mode "%s" to int.', | ||
mode['final_price'], | ||
mode['title'] | ||
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. We could also log the |
||
) | ||
return course_modes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 can happen only when
mode['original_price']
does not contain digits (mode['final_price']
is generated inget_course_final_price
).Technically, it could also happen when the
mode['min_price']
does not contain digits, but this should raise an exception in theformat_price
function.Is it even possible? If yes, what does it mean? Is the course free? We can keep this exception handling; I'm just curious.
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.
@Agrendalath To be fair, I didn't quite find an edge case while testing for this. The final
final_price
is a formatted string fromformat_price
which is bound to either provide a properly formatted string, or throw an exception.But for some reason, I wasn't comfortable with parsing string using regex with no safeguards, so added the try block.