Skip to content
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
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions feedback/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
course resources, and to think and synthesize about their experience
in the course.
"""
from .feedback import FeedbackXBlock, FeedbackXBlockAside
83 changes: 82 additions & 1 deletion feedback/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
#)
Comment on lines +434 to +437
Copy link
Contributor Author

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


@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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
1 change: 1 addition & 0 deletions feedback_aside/public/default_icons/default_icons
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def package_data(pkg, roots):
],
'xblock.test.v0': [
'feedbacktest = feedbacktests:TestFeedback',
]
],
"xblock_asides.v1": [
"feedback = feedback.feedback:FeedbackXBlockAside",
],
},
package_data=package_data("feedback", ["static", "public", "templates", "translations"]),
)
Loading