Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
RateXBlock
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
RateXBlock
Commits
0fca1add
Commit
0fca1add
authored
Nov 25, 2015
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Design for testability
parent
367e19c0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
16 deletions
+74
-16
rate/rate.py
+74
-16
No files found.
rate/rate.py
View file @
0fca1add
...
...
@@ -17,10 +17,11 @@ try:
except
ImportError
:
class
tracker
(
object
):
# pylint: disable=invalid-name
"""
Define tracker if eventtracking cannot be imported. This is a workaround
so that the code works in both edx-platform and XBlock workbench (the latter
of which does not support event emission). This should be replaced with XBlock's
emit(), but at present, emit() is broken.
Define tracker if eventtracking cannot be imported. This is a
workaround so that the code works in both edx-platform and
XBlock workbench (the latter of which does not support event
emission). This should be replaced with XBlock's emit(), but
at present, emit() is broken.
"""
def
__init__
(
self
):
""" Do nothing """
...
...
@@ -31,6 +32,7 @@ except ImportError:
""" In workbench, do nothing for event emission """
pass
@XBlock.needs
(
'i18n'
)
class
RateXBlock
(
XBlock
):
"""
...
...
@@ -44,8 +46,10 @@ class RateXBlock(XBlock):
# exposed in the UX. If the prompt is missing any portions, we
# will default to the ones in default_prompt.
prompts
=
List
(
default
=
[{
'freeform'
:
"Please provide us feedback on this section"
,
'likert'
:
"Please rate your overall experience with this section"
}],
default
=
[
{
'freeform'
:
"Please provide us feedback on this section"
,
'likert'
:
"Please rate your overall experience with this section"
}
],
scope
=
Scope
.
settings
,
help
=
"Freeform user prompt"
,
xml_node
=
True
...
...
@@ -80,7 +84,7 @@ class RateXBlock(XBlock):
help
=
"Feedback"
)
display_name
=
String
(
display_name
=
"Display Name"
,
display_name
=
"Display Name"
,
default
=
"Provide Feedback"
,
scopde
=
Scope
.
settings
)
...
...
@@ -97,10 +101,17 @@ class RateXBlock(XBlock):
necessary.
"""
_
=
self
.
runtime
.
service
(
self
,
'i18n'
)
.
ugettext
prompt
=
{
'freeform'
:
_
(
"Please provide us feedback on this section."
),
'likert'
:
_
(
"Please rate your overall experience with this section."
),
'mouseovers'
:
[
_
(
"Excellent"
),
_
(
"Good"
),
_
(
"Average"
),
_
(
"Fair"
),
_
(
"Poor"
)],
'icons'
:
[
u"😁"
,
u"😊"
,
u"😐"
,
u"😞"
,
u"😭"
]}
prompt
=
{
'freeform'
:
_
(
"Please provide us feedback on this section."
),
'likert'
:
_
(
"Please rate your overall experience "
"with this section."
),
'mouseovers'
:
[
_
(
"Excellent"
),
_
(
"Good"
),
_
(
"Average"
),
_
(
"Fair"
),
_
(
"Poor"
)],
'icons'
:
[
u"😁"
,
u"😊"
,
u"😐"
,
u"😞"
,
u"😭"
]
}
prompt
.
update
(
self
.
prompts
[
index
])
return
prompt
...
...
@@ -123,10 +134,16 @@ class RateXBlock(XBlock):
html
=
self
.
resource_string
(
"static/html/rate.html"
)
# The replace allows us to format the HTML nicely without getting
# extra whitespace
scale_item
=
self
.
resource_string
(
"static/html/scale_item.html"
)
.
replace
(
'
\n
'
,
''
)
scale_item
=
self
.
resource_string
(
"static/html/scale_item.html"
)
scale_item
=
scale_item
.
replace
(
'
\n
'
,
''
)
indexes
=
range
(
len
(
prompt
[
'icons'
]))
active_vote
=
[
"checked"
if
i
==
self
.
user_vote
else
""
for
i
in
indexes
]
scale
=
u""
.
join
(
scale_item
.
format
(
level
=
level
,
icon
=
icon
,
i
=
i
,
active
=
active
)
for
(
level
,
icon
,
i
,
active
)
in
zip
(
prompt
[
'mouseovers'
],
prompt
[
'icons'
],
indexes
,
active_vote
))
active_vote
=
[
"checked"
if
i
==
self
.
user_vote
else
""
for
i
in
indexes
]
scale
=
u""
.
join
(
scale_item
.
format
(
level
=
level
,
icon
=
icon
,
i
=
i
,
active
=
active
)
for
(
level
,
icon
,
i
,
active
)
in
zip
(
prompt
[
'mouseovers'
],
prompt
[
'icons'
],
indexes
,
active_vote
)
)
if
self
.
user_vote
!=
-
1
:
_
=
self
.
runtime
.
service
(
self
,
'i18n'
)
.
ugettext
response
=
_
(
"Thank you for voting!"
)
...
...
@@ -199,18 +216,44 @@ class RateXBlock(XBlock):
@XBlock.json_handler
def
feedback
(
self
,
data
,
suffix
=
''
):
'''
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!"
)}
if
'freeform'
in
data
:
response
=
{
"success"
:
True
,
"response"
:
_
(
"Thank you for your feedback!"
)}
tracker
.
emit
(
'edx.ratexblock.freeform_feedback'
,
{
'old_freeform'
:
self
.
user_freeform
,
'new_freeform'
:
data
[
'freeform'
]})
self
.
user_freeform
=
data
[
'freeform'
]
if
'vote'
in
data
:
response
=
{
"success"
:
True
,
"response"
:
_
(
"Thank you for voting!"
)}
tracker
.
emit
(
'edx.ratexblock.likert_rate'
,
{
'old_vote'
:
self
.
user_vote
,
'new_vote'
:
data
[
'vote'
]})
self
.
vote
(
data
)
_
=
self
.
runtime
.
service
(
self
,
'i18n'
)
.
ugettext
return
{
"success"
:
True
,
"response"
:
_
(
"Thank you!"
)}
response
.
update
({
"freeform"
:
self
.
user_freeform
,
"vote"
:
self
.
user_vote
})
if
self
.
is_staff
():
response
[
'aggregate'
]
=
self
.
vote_aggregate
return
response
# TO-DO: change this to create the scenarios you'd like to see in the
# workbench while developing your XBlock.
...
...
@@ -226,3 +269,18 @@ class RateXBlock(XBlock):
</vertical_demo>
"""
),
]
def
is_staff
(
self
):
"""
Return self.xmodule_runtime.user_is_staff if available
This is not a supported part of the XBlocks API in all
runtimes, and this is a workaround so something reasonable
happens in both workbench and edx-platform
"""
if
hasattr
(
self
,
"xmodule_runtime"
)
and
\
hasattr
(
self
.
xmodule_runtime
,
"user_is_staff"
):
return
self
.
xmodule_runtime
.
user_is_staff
else
:
# In workbench and similar settings, always return true
return
True
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment