Skip to content

Commit

Permalink
refactor: move studio_submit to EditingMixin
Browse files Browse the repository at this point in the history
and generalize it so it can be used by LTI and WordCloud blocks
  • Loading branch information
pomegranited committed Feb 20, 2025
1 parent ad42812 commit 57ce36c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
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',
}
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

0 comments on commit 57ce36c

Please sign in to comment.