From c9dbd2c30858736e63a5cc0a672ad6a3c6c57227 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 24 Apr 2015 09:30:06 -0400 Subject: [PATCH] Add an empty implementation of XBlockUserStateClient backed by StudentModule --- .../courseware/user_state_client.py | 63 +++++++++++++++++++ lms/djangoapps/xblock_user_state/interface.py | 1 + 2 files changed, 64 insertions(+) create mode 100644 lms/djangoapps/courseware/user_state_client.py diff --git a/lms/djangoapps/courseware/user_state_client.py b/lms/djangoapps/courseware/user_state_client.py new file mode 100644 index 0000000000..19f522d34b --- /dev/null +++ b/lms/djangoapps/courseware/user_state_client.py @@ -0,0 +1,63 @@ +""" +An implementation of :class:`XBlockUserStateClient`, which stores XBlock Scope.user_state +data in a Django ORM model. +""" + +from xblock_user_state.interface import DjangoXBlockUserStateClient + + +class DjangoXBlockUserStateClient(DjangoXBlockUserStateClient): + """ + An interface that uses the Django ORM StudentModule as a backend. + """ + + class ServiceUnavailable(XBlockUserStateClient.ServiceUnavailable): + """ + This error is raised if the service backing this client is currently unavailable. + """ + pass + + class PermissionDenied(XBlockUserStateClient.PermissionDenied): + """ + This error is raised if the caller is not allowed to access the requested data. + """ + pass + + class DoesNotExist(XBlockUserStateClient.DoesNotExist): + """ + This error is raised if the caller has requested data that does not exist. + """ + pass + + def get(username, block_key, scope=Scope.user_state): + return self.get_many(username, [block_key], scope) + + def set(username, block_key, state, scope=Scope.user_state): + self.set_many(username, {block_key: state}, scope) + + def get_many(username, block_keys, scope=Scope.user_state): + """Returns dict of block_id -> state.""" + raise NotImplementedError() + + def set_many(username, block_keys_to_state, scope=Scope.user_state): + raise NotImplementedError() + + def get_history(username, block_key, scope=Scope.user_state): + """We don't guarantee that history for many blocks will be fast.""" + raise NotImplementedError() + + def iter_all_for_block(block_key, scope=Scope.user_state, batch_size=None): + """ + You get no ordering guarantees. Fetching will happen in batch_size + increments. If you're using this method, you should be running in an + async task. + """ + raise NotImplementedError() + + def iter_all_for_course(course_key, block_type=None, scope=Scope.user_state, batch_size=None): + """ + You get no ordering guarantees. Fetching will happen in batch_size + increments. If you're using this method, you should be running in an + async task. + """ + raise NotImplementedError() diff --git a/lms/djangoapps/xblock_user_state/interface.py b/lms/djangoapps/xblock_user_state/interface.py index 5d001de4d1..2c7254d00f 100644 --- a/lms/djangoapps/xblock_user_state/interface.py +++ b/lms/djangoapps/xblock_user_state/interface.py @@ -10,6 +10,7 @@ from xblock.fields import Scope, ScopeBase new_contract('UsageKey', UsageKey) + class XBlockUserStateClient(object): """ First stab at an interface for accessing XBlock User State. This will have