Unverified Commit fc195ddf by Matt Tuchfarber Committed by GitHub

Merge pull request #16736 from edx/tuchfarber/WL_1343_instructor_ordering

Order program instructors based on new program field
parents d674f908 a4f5c14c
......@@ -189,6 +189,7 @@ class ProgramFactory(DictFactoryBase):
expected_learning_items = factory.LazyFunction(partial(generate_instances, CourseFactory))
faq = factory.LazyFunction(partial(generate_instances, FAQFactory))
hidden = False
instructor_ordering = factory.LazyFunction(partial(generate_instances, PersonFactory))
is_program_eligible_for_one_click_purchase = True
job_outlook_items = factory.LazyFunction(partial(generate_instances, JobOutlookItemFactory))
marketing_slug = factory.Faker('slug')
......
......@@ -698,7 +698,27 @@ class ProgramMarketingDataExtender(ProgramDataExtender):
program_instructors = self.instructors
cache.set(cache_key, program_instructors, 3600)
self.data['instructors'] = program_instructors
if 'instructor_ordering' not in self.data:
# If no instructor ordering is set in discovery, it doesn't populate this key
self.data['instructor_ordering'] = []
sorted_instructor_names = [
' '.join(filter(None, (instructor['given_name'], instructor['family_name'])))
for instructor in self.data['instructor_ordering']
]
instructors_to_be_sorted = [
instructor for instructor in program_instructors
if instructor['name'] in sorted_instructor_names
]
instructors_to_not_be_sorted = [
instructor for instructor in program_instructors
if instructor['name'] not in sorted_instructor_names
]
sorted_instructors = sorted(
instructors_to_be_sorted,
key=lambda item: sorted_instructor_names.index(item['name'])
)
self.data['instructors'] = sorted_instructors + instructors_to_not_be_sorted
def extend(self):
"""Execute extension handlers, returning the extended data."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment