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: Add language support in courses #3335

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

arslanashraf7
Copy link
Contributor

@arslanashraf7 arslanashraf7 commented Dec 12, 2024

What are the relevant tickets?

https://github.com/mitodl/hq/issues/6239

Description (What does it do?)

  • Add language support for courses and programs
  • Adds a new model CourseLanguage to manage supported languages, The model has priority field that defines the sorting order of course by language on Catalog
  • Also, updates the external sync API command and task to add/update the languages as received from the external APIs (Emeritus, Global Alumni atm). if there is no language key available in the API the default language would be set to English
  • Prefills the language model with currently supported languages. Supported languages list contains English, Spanish, Portuguese, Mandarin, Italian, French as per https://github.com/mitodl/hq/issues/6111
  • Pre-fills the courseware pages with languages (Sets English to all the existing pages), If a course has different language from the external API that would be synced accordingly
  • Adds the language key in the courses & programs APIs
  • Updates the seed data commands to add default language as well

Screenshots (if appropriate):

TBA

  • Desktop screenshots
  • Mobile width screenshots

Manage Languages
image

Assign languages (CMS)
image

image

How can this be tested?

Testing language Model & data Prefill

  • Setup a couple of courses on the master branch
  • Now set up on this branch to run migrations, a New table Course Languages should now be available in Django Admin with pre-filled languages as mentioned above. The English language would have the priority set to 1 whereas the other languages should have 100. This is because we want to sort the courses by English language for now. However, this priority key can be used to test different languages with different priority values. 1 means highest priority
  • Test that the language name is case insensitive, which means there should only be one language with a name in the system
  • Once, you have tested the above, Open any Course/Program pages in CMS and they should all have a language field (Set to English by default)
  • A language object should be protected, e.g. if a language is associated with a course page it should not be deleted

Testing External APIs

  • Once you have tested above, you should run the command sync_external_course_runs --vendor-name emeritus/Global Alunmni
  • Test that the course pages from the extern vendors have updated language acquired by the external API set to them
  • If there is a language in the external API that was not pre-filled, it should now be created automatically after running the command
  • This has two test cases, 1) when the command was already run and data was present and you run the command 2) When command is run for the first time. In both cases the course page languages should be updated accordingly

Testing internal APIs

  • Test that api/courses & /api/programs have a language field in the JSON response

Testing Catalog Course sorting

  • Currently, the courses on the catalog are sorted by next run date, but after this PR they should be sorted first by language priority and then the next run date (This behavior is only for default sorting)
  • If a different sort is selected on Catalog, then courses/programs should not be sorted on language priority

Testing Seed Data

  • Test seed data command, it should create course pages with the language English set to the by default

There are no frontend-level changes for now, except for the ones mentioned above


Additional Context

@arslanashraf7 arslanashraf7 force-pushed the arslan/6239-add-language-support branch 4 times, most recently from 91c897f to 70a3859 Compare January 8, 2025 10:53
@arslanashraf7 arslanashraf7 marked this pull request as ready for review January 8, 2025 13:15
@arslanashraf7 arslanashraf7 force-pushed the arslan/6239-add-language-support branch from b14ab48 to 0085b1c Compare January 8, 2025 19:19
@arslanashraf7 arslanashraf7 force-pushed the arslan/6239-add-language-support branch from 0085b1c to 8025f03 Compare January 9, 2025 07:38
@asadali145 asadali145 self-assigned this Jan 9, 2025
Copy link
Contributor

@asadali145 asadali145 left a comment

Choose a reason for hiding this comment

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

Looks good overall. A couple of small suggestions +
We should use select_related in the API Views and Catalog to avoid n+1 queries for the language table.

Also, I haven't noticed any discussion/comment but It would be a good idea to display the course language in the Catalog Card or a card in the product detail page. I know these will be done in a follow up but just wanted to leave my thoughts here for reference.

Comment on lines +927 to +928
null=False,
blank=False,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: null and blank default to False, can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These flags were added and then changed in the same PR and this thing has 2 migrations so I intentionally kept it like this to keep readability

Comment on lines 295 to 296
if not has_language:
assert external_course_page.language.name == "English"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not able to understand this test condition.

Copy link
Contributor Author

@arslanashraf7 arslanashraf7 Jan 9, 2025

Choose a reason for hiding this comment

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

This was added to test the case where if there is no language key available from the external APIs the default English language should be assigned to the course. But, As discussed I'll add the else condition to check for provided language and I'll add a code comment above for more readability


class Meta:
constraints = [
models.UniqueConstraint(Lower("name"), name="unique_language_name")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can provide a better message by passing violation_error_message. Otherwise, it will display a less user-friendly message Constraint “unique_language_name” is violated..

@arslanashraf7 arslanashraf7 force-pushed the arslan/6239-add-language-support branch from bcdb271 to 7a8e3aa Compare January 9, 2025 12:44
@arslanashraf7
Copy link
Contributor Author

@asadali145 I've addressed the feedback in 7a8e3aa. Let me know if all the changes look good to you.

Copy link
Contributor

@asadali145 asadali145 left a comment

Choose a reason for hiding this comment

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

Neatly done, Looks GooD!

"platform",
"programpage__language",
"externalprogrampage__language",
)
.prefetch_related(courses_prefetch, products_prefetch)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noticed we need to select_related the course language for the program courses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants