Skip to content
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: return override fields from properties when they are populated #4434

Merged
merged 4 commits into from
Sep 16, 2024

Conversation

AfaqShuaib09
Copy link
Contributor

@AfaqShuaib09 AfaqShuaib09 commented Sep 9, 2024

PROD-4176

Design methods for subjects and languages, giving preference to overrides rather than using the simple method values.

@hamza-56 hamza-56 marked this pull request as ready for review September 12, 2024 17:28
@hamza-56 hamza-56 force-pushed the afaq/prod-4167-3 branch 3 times, most recently from 96c3510 to 0f7245f Compare September 12, 2024 19:34
extracted from the course runs.
"""
if self.language_override:
return {self.language_override}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's with dict operator?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, it should be a list instead of a set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 @property
    def languages(self):
        return {course_run.language for course_run in self.course_runs if course_run.language is not None}

The return type of languages is a set, so we're returning a set in active_languages as well to maintain consistency in the code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, makes sense.

course_run = CourseRunFactory.create(language=language_de)
program = ProgramFactory.create(language_override=language_es, courses=[course_run.course])

expected_languages = {language_es}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace set with list


program = ProgramFactory.create(language_override=None, courses=[course_run1.course, course_run2.course])

expected_languages = {language_en, language_fr}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace set with list

Comment on lines +3563 to +3568
if self.primary_subject_override:
if self.primary_subject_override not in subjects:
subjects = [self.primary_subject_override] + subjects
else:
subjects = [self.primary_subject_override] + \
[subject for subject in subjects if subject != self.primary_subject_override]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wont this code be simple if we make subjects list set, adding primary override (if present) and convert it back to list?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While converting the subjects list to a set would simplify the code by automatically handling duplicates, we need to ensure the order of subjects is preserved, especially since the primary subject override should always appear first.
The current approach ensures both:

  1. The primary subject is explicitly placed at the front.
  2. Order is maintained for the rest of the subjects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove the inner if else and swap it with the assignment in the else? That would be equivalent to the current implementation?

Comment on lines +3563 to +3568
if self.primary_subject_override:
if self.primary_subject_override not in subjects:
subjects = [self.primary_subject_override] + subjects
else:
subjects = [self.primary_subject_override] + \
[subject for subject in subjects if subject != self.primary_subject_override]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not remove the inner if else and swap it with the assignment in the else? That would be equivalent to the current implementation?

@hamza-56 hamza-56 merged commit f30ed47 into master Sep 16, 2024
11 of 12 checks passed
@hamza-56 hamza-56 deleted the afaq/prod-4167-3 branch September 16, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants