-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Support anonymous users with new (Blockstore-based) XBlock Runtime #22427
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2093,7 +2093,10 @@ | |
|
|
||
| ################## BLOCKSTORE RELATED SETTINGS ######################### | ||
| BLOCKSTORE_PUBLIC_URL_ROOT = 'http://localhost:18250' | ||
| BLOCKSTORE_API_URL = 'http://localhost:18250/api/v1' | ||
| BLOCKSTORE_API_URL = 'http://localhost:18250/api/v1/' | ||
| # Which of django's caches to use for storing anonymous user state for XBlocks | ||
| # in the blockstore-based XBlock runtime | ||
| XBLOCK_RUNTIME_V2_EPHEMERAL_DATA_CACHE = 'default' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, are we calling it v2 runtime or blockstore runtime?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically the v2 runtime can support other backends besides blockstore. But I use the terms somewhat interchangeably. |
||
|
|
||
| ###################### LEARNER PORTAL ################################ | ||
| LEARNER_PORTAL_URL_ROOT = 'https://learner-portal-localhost:18000' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,6 +252,9 @@ def public_view(self, context): | |
| """ | ||
| Returns a fragment that contains the html for the public view | ||
| """ | ||
| if getattr(self.runtime, 'suppports_state_for_anonymous_users', False): | ||
| # The new runtime can support anonymous users as fully as regular users: | ||
| return self.student_view(context) | ||
| return Fragment(self.get_html(view=PUBLIC_VIEW)) | ||
|
|
||
| def get_html(self, view=STUDENT_VIEW): | ||
|
|
@@ -610,12 +613,8 @@ def parse_xml_new_runtime(cls, node, runtime, keys): | |
| field_data = cls.parse_video_xml(node) | ||
| for key, val in field_data.items(): | ||
| setattr(video_block, key, cls.fields[key].from_json(val)) | ||
| # Update VAL with info extracted from `xml_object` | ||
| video_block.edx_video_id = video_block.import_video_info_into_val( | ||
| node, | ||
| runtime.resources_fs, | ||
| keys.usage_id.context_key, | ||
| ) | ||
| # Don't use VAL in the new runtime: | ||
| video_block.edx_video_id = None | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a seemingly unrelated change, but I found that the |
||
| return video_block | ||
|
|
||
| @classmethod | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| Block for testing variously scoped XBlock fields. | ||
| """ | ||
| from __future__ import absolute_import, division, print_function, unicode_literals | ||
| import json | ||
|
|
||
| from webob import Response | ||
| from xblock.core import XBlock, Scope | ||
| from xblock import fields | ||
|
|
||
|
|
||
| class UserStateTestBlock(XBlock): | ||
| """ | ||
| Block for testing variously scoped XBlock fields. | ||
| """ | ||
| BLOCK_TYPE = "user-state-test" | ||
| has_score = False | ||
|
|
||
| display_name = fields.String(scope=Scope.content, name='User State Test Block') | ||
| # User-specific fields: | ||
| user_str = fields.String(scope=Scope.user_state, default='default value') # This usage, one user | ||
| uss_str = fields.String(scope=Scope.user_state_summary, default='default value') # This usage, all users | ||
| pref_str = fields.String(scope=Scope.preferences, default='default value') # Block type, one user | ||
| user_info_str = fields.String(scope=Scope.user_info, default='default value') # All blocks, one user | ||
|
|
||
| @XBlock.json_handler | ||
| def set_user_state(self, data, suffix): # pylint: disable=unused-argument | ||
| """ | ||
| Set the user-scoped fields | ||
| """ | ||
| self.user_str = data["user_str"] | ||
| self.uss_str = data["uss_str"] | ||
| self.pref_str = data["pref_str"] | ||
| self.user_info_str = data["user_info_str"] | ||
| return {} | ||
|
|
||
| @XBlock.handler | ||
| def get_user_state(self, request, suffix=None): # pylint: disable=unused-argument | ||
| """ | ||
| Get the various user-scoped fields of this XBlock. | ||
| """ | ||
| return Response( | ||
| json.dumps({ | ||
| "user_str": self.user_str, | ||
| "uss_str": self.uss_str, | ||
| "pref_str": self.pref_str, | ||
| "user_info_str": self.user_info_str, | ||
| }), | ||
| content_type='application/json', | ||
| charset='UTF-8', | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.