-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: xblock aside #31
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,11 +11,16 @@ | |
import pkg_resources | ||
import six | ||
|
||
from xblock.core import XBlock | ||
from xblock.core import XBlock, XBlockAside | ||
from xblock.fields import Scope, Integer, String, List, Float | ||
from web_fragments.fragment import Fragment | ||
from xblock.utils.resources import ResourceLoader | ||
|
||
from django.template import Context, Template | ||
from web_fragments.fragment import Fragment | ||
|
||
from xmodule.x_module import STUDENT_VIEW | ||
|
||
resource_loader = ResourceLoader(__name__) | ||
|
||
# We provide default text which is designed to elicit student thought. We'd | ||
|
@@ -415,3 +420,79 @@ def is_staff(self): | |
else: | ||
# In workbench and similar settings, always return true | ||
return True | ||
|
||
|
||
@XBlockAside.needs('completion') | ||
class FeedbackXBlockAside(FeedbackXBlock, XBlockAside): | ||
""" | ||
XBlock Aside version of FeedbackXBlock | ||
""" | ||
|
||
# The scope user_state_summary is not supported in XBlockAside unless | ||
# this XBlockAside is limited to a subsection. This is because the | ||
# user_state_summary means the key used is the unit ID. | ||
#vote_aggregate = List( | ||
# default=None, scope=Scope.user_state, | ||
# help=_("A list of user votes") | ||
#) | ||
|
||
@XBlockAside.aside_for(STUDENT_VIEW) | ||
def student_view_aside( | ||
self, block, context=None | ||
): # pylint: disable=unused-argument | ||
""" | ||
Render the aside contents for the student view. | ||
""" | ||
return super().student_view() | ||
|
||
@XBlock.json_handler | ||
def feedback(self, data, suffix=''): # pylint: disable=unused-argument | ||
''' | ||
Allow students to submit feedback, both numerical and | ||
qualitative. We only update the specific type of feedback | ||
submitted. | ||
|
||
We return the current state. While this is not used by the | ||
client code, it is helpful for testing. For staff users, we | ||
also return the aggregate results. | ||
''' | ||
_ = self.runtime.service(self, 'i18n').ugettext | ||
|
||
if 'freeform' not in data and 'vote' not in data: | ||
response = {"success": False, | ||
"response": _("Please vote!")} | ||
#self.runtime.publish(self, | ||
# 'edx.feedbackxblock.nothing_provided', | ||
# {}) | ||
if 'vote' in data: | ||
response = {"success": True, | ||
"response": _("Thank you for voting!")} | ||
#self.runtime.publish(self, | ||
# 'edx.feedbackxblock.likert_provided', | ||
# {'old_vote': self.user_vote, | ||
# 'new_vote': data['vote']}) | ||
Comment on lines
+470
to
+473
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 can be updated in the base xblock to try - except this |
||
self.vote(data) | ||
if 'freeform' in data: | ||
response = {"success": True, | ||
"response": _("Thank you for your feedback!")} | ||
#self.runtime.publish(self, | ||
# 'edx.feedbackxblock.freeform_provided', | ||
# {'old_freeform': self.user_freeform, | ||
# 'new_freeform': data['freeform']}) | ||
self.user_freeform = data['freeform'] | ||
|
||
response.update({ | ||
"freeform": self.user_freeform, | ||
"vote": self.user_vote | ||
}) | ||
|
||
if self.is_staff(): | ||
response['aggregate'] = self.vote_aggregate | ||
|
||
return response | ||
|
||
@classmethod | ||
def should_apply_to_block(cls, block): | ||
if getattr(block, 'category', None) != 'vertical': | ||
return False | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
feedback/public/default_icons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The scope
user_state_summary
is not compatible with the XBlockAside as the fields are not cached.This is because the fields are behind a write through cache that is not prefetch correctly due to incorrect implementations in edx-platform. More context here: openedx/edx-platform#33554