-
Notifications
You must be signed in to change notification settings - Fork 172
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
Conversation
b237980
to
7aff413
Compare
1c3f1c3
to
0c132e6
Compare
0c132e6
to
de88767
Compare
6b590de
to
8b5f4b7
Compare
96c3510
to
0f7245f
Compare
0f7245f
to
c06627c
Compare
extracted from the course runs. | ||
""" | ||
if self.language_override: | ||
return {self.language_override} |
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.
what's with dict operator?
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.
Shouldn't this be a list?
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.
+1, it should be a list instead of a set
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.
@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.
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.
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} |
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.
replace set with list
|
||
program = ProgramFactory.create(language_override=None, courses=[course_run1.course, course_run2.course]) | ||
|
||
expected_languages = {language_en, language_fr} |
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.
replace set with list
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] |
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.
wont this code be simple if we make subjects list set, adding primary override (if present) and convert it back to list?
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.
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:
- The primary subject is explicitly placed at the front.
- Order is maintained for the rest of the subjects.
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.
Makes sense.
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.
Why not remove the inner if else and swap it with the assignment in the else? That would be equivalent to the current implementation?
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] |
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.
Why not remove the inner if else and swap it with the assignment in the else? That would be equivalent to the current implementation?
PROD-4176
Design methods for subjects and languages, giving preference to overrides rather than using the simple method values.