Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions xblocks_contrib/discussion/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,12 @@ def discussion_config(self):
"""
return self.runtime.service(self, 'discussion_config_service')

@property
def course_key(self):
return getattr(self.scope_ids.usage_id, 'course_key', None)

@property
def is_visible(self):
"""
Discussion Xblock does not support new OPEN_EDX provider
"""
return self.discussion_config.is_discussion_visible(self.course_key)
return self.discussion_config.is_discussion_visible(self.context_key)

@property
def django_user(self):
Expand Down Expand Up @@ -160,7 +156,7 @@ def has_permission(self, permission): # pylint: disable=unused-argument
:rtype: bool
"""
if self.discussion_config:
return self.discussion_config.has_permission(self.django_user, permission, self.course_key)
return self.discussion_config.has_permission(self.django_user, permission, self.context_key)
else:
return False

Expand All @@ -179,7 +175,7 @@ def student_view(self, context=None):

if not self.django_user.is_authenticated:
qs = urllib.parse.urlencode({
'course_id': self.course_key,
'course_id': self.context_key,
'enrollment_action': 'enroll',
'email_opt_in': False,
})
Expand All @@ -200,7 +196,7 @@ def student_view(self, context=None):
'discussion_id': self.discussion_id,
'display_name': self.display_name if self.display_name else _("Discussion"),
'user': self.django_user,
'course_id': self.course_key,
'course_id': self.context_key,
'discussion_category': self.discussion_category,
'discussion_target': self.discussion_target,
'can_create_thread': self.has_permission("create_thread"),
Expand Down Expand Up @@ -276,7 +272,7 @@ def _apply_metadata_and_policy(cls, block, node, runtime):
return

metadata = cls.load_metadata(definition_xml)
cls.apply_policy(metadata, runtime.get_policy(block.scope_ids.usage_id))
cls.apply_policy(metadata, runtime.get_policy(block.usage_key))

for field_name, value in metadata.items():
if field_name in block.fields:
Expand Down
33 changes: 4 additions & 29 deletions xblocks_contrib/poll/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import markupsafe
from django.utils.translation import gettext_noop as _
from lxml import etree
from opaque_keys.edx.keys import UsageKey
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import Boolean, Dict, List, Scope, String
Expand Down Expand Up @@ -119,30 +118,6 @@ def xblock_kvs(self):
self.save()
return self._field_data._kvs # pylint: disable=protected-access

@property
def url_name(self):
return self.location.block_id

@property
def course_id(self):
return self.location.course_key

@property
def category(self):
return self.scope_ids.block_type

@property
def location(self):
return self.scope_ids.usage_id

@location.setter
def location(self, value):
assert isinstance(value, UsageKey)
self.scope_ids = self.scope_ids._replace(
def_id=value, # Note: assigning a UsageKey as def_id is OK in old mongo / import system but wrong in split
usage_id=value,
)

def handle_ajax(self, dispatch, data): # legacy support for tests
"""
Legacy method to mimic old ajax handler behavior for backward compatibility.
Expand All @@ -162,8 +137,8 @@ def student_view(self, _context):
resource_loader.render_django_template(
"templates/poll.html",
{
"element_id": self.scope_ids.usage_id.html_id(),
"element_class": self.scope_ids.usage_id.block_type,
"element_id": self.usage_key.html_id(),
"element_class": self.usage_key.block_type,
"configuration_json": self.dump_poll(),
},
i18n_service=self.runtime.service(self, "i18n"),
Expand Down Expand Up @@ -251,7 +226,7 @@ def handle_submit_state(self, data, suffix=""): # pylint: disable=unused-argume
return self.submit_answer(answer)

@XBlock.json_handler
def handle_reset_state(self):
def handle_reset_state(self, data, suffix=""): # pylint: disable=unused-argument
"""
handler to Reset poll answer.
"""
Expand Down Expand Up @@ -298,7 +273,7 @@ def get_explicitly_set_fields_by_scope(self, scope=Scope.content):
result[field.name] = field.read_json(self)
except TypeError as exception:
exception_message = "{message}, Block-location:{location}, Field-name:{field_name}".format(
message=str(exception), location=str(self.location), field_name=field.name
message=str(exception), location=str(self.usage_key), field_name=field.name
)
raise TypeError(exception_message) # pylint: disable=raise-missing-from
return result
Expand Down
Loading