Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Suppose an XBlock author wants to find out information about the user that's viewing/interacting with an XBlock. How?

...

The code for where the LMS creates an XBlockUser is here:
https://github.com/edx/edx-platform/blob/master/common/djangoapps/xblock_django/user_service.py#L51py#L57

If you're running the XBlock on edx-platform, there are some optional attributes that also get set:

...

If you want to attach user data to your XBlock that is not tied to a particular piece of content, you'll want one of the lesser used field scopes. For example, if you wanted to get the user's name and have a banner in the XBlock say "Hello, <name>", you'd probably want to declare a String field "favorite_color" with a scope of Scope.user_info. Keep in mind that this value will only be accessible from your own XBlock. It will not be accessible from other XBlocks via the user service (though that is an interesting possibility for future extension).