Skip to content
Merged
19 changes: 18 additions & 1 deletion xmodule/editing_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import logging

from xblock.fields import Scope, String
from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String

from xmodule.mako_block import MakoTemplateBlockBase

Expand Down Expand Up @@ -43,3 +44,19 @@ def get_context(self):
# Add our specific template information (the raw data body)
_context.update({'data': self.data})
return _context

@XBlock.json_handler
def studio_submit(self, submissions, suffix=''): # pylint: disable=unused-argument
"""
Change the settings for this XBlock given by the Studio user
"""
for field_name in self.editable_metadata_fields:
if field_name in submissions and field_name in self.fields:
field = self.fields[field_name]
if isinstance(field, Boolean):
setattr(self, field_name, submissions[field_name] == 'True')
else:
setattr(self, field_name, submissions[field_name])
return {
'result': 'success',
}
10 changes: 8 additions & 2 deletions xmodule/lti_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
from django.conf import settings
from lxml import etree
from oauthlib.oauth1.rfc5849 import signature
from opaque_keys.edx.keys import CourseKey
from pytz import UTC
from web_fragments.fragment import Fragment
from webob import Response
Expand Down Expand Up @@ -609,8 +610,12 @@ def get_lis_result_sourcedid(self):
def get_course(self):
"""
Return course by course id.

Returns None if the current block is not part of a course (i.e part of a library).
"""
return self.runtime.modulestore.get_course(self.course_id)
if isinstance(self.course_id, CourseKey):
return self.runtime.modulestore.get_course(self.course_id)
return None

@property
def context_id(self):
Expand Down Expand Up @@ -960,7 +965,8 @@ def get_client_key_secret(self):
Obtains client_key and client_secret credentials from current course.
"""
course = self.get_course()
for lti_passport in course.lti_passports:
lti_passports = course.lti_passports if course else []
for lti_passport in lti_passports:
try:
lti_id, key, secret = [i.strip() for i in lti_passport.split(':')]
except ValueError:
Expand Down
20 changes: 0 additions & 20 deletions xmodule/word_cloud_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,26 +315,6 @@ def index_dictionary(self):

return xblock_body

@XBlock.json_handler
def studio_submit(self, submissions, suffix=''): # pylint: disable=unused-argument
"""
Change the settings for this XBlock given by the Studio user
"""
if 'display_name' in submissions:
self.display_name = submissions['display_name']
if 'instructions' in submissions:
self.instructions = submissions['instructions']
if 'num_inputs' in submissions:
self.num_inputs = submissions['num_inputs']
if 'num_top_words' in submissions:
self.num_top_words = submissions['num_top_words']
if 'display_student_percents' in submissions:
self.display_student_percents = submissions['display_student_percents'] == 'True'

return {
'result': 'success',
}


WordCloudBlock = (
_ExtractedWordCloudBlock if settings.USE_EXTRACTED_WORD_CLOUD_BLOCK
Expand Down