Get Author and Language for a Course, XBlock, ContentLibrary or LibraryBlock

Hello team! I expect everyone is going well!

I’m working on the auto-tagging feature for system taxonomies and struggling to get these entities’ Author and Language metadata, using their opaque key as starting point.

For the course, I manage to get the author and language using the following code:

from xmodule.modulestore.django import modulestore

course = modulestore().get_course(course_key)
author = course.edited_by
lang = course.language

How can I do the same for XBlock, LibraryBlock, and ContentLibrary?

For the XBlock and LibraryBlock, I have the UsageKey.
For the ContentLibrary, I have the LibraryLocator.

I’ll continue reading the code, but I appreciate it if someone gives me a shortcut!

Thank you!

PS: Is this the right place for this type of question?

@rpenido The github issue says that the “language” tag should be pulled from the current user’s preferred language, not from the block or library.

You could start with the account views to figure out how to get that; unfortunately there isn’t a get_user_language function in the accounts.api. :frowning:

But since the course has a language setting already, it’s better to pull the language for the blocks it contains course.language.

Also note that the whole “Author” tag thing has been descoped for MVP, so no need to worry about that here. It’s late-breaking news though, so it’s ok that you missed it :slight_smile:

PS: Is this the right place for this type of question?

It’s not a bad place for it if your task reviewer hasn’t been able to help. :slight_smile: But whenever we post questions or discussions, we reference a ticket so that OpenCrafters can log their time.

The ticket here is FAL-3460

1 Like

It’s not a bad place for it if your task reviewer hasn’t been able to help.

This is not the case at all! Sorry! I just thought the forum was a good place to have these questions answered and “searchable”. :sweat_smile:

2 Likes