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
8eca3f26
Commit
8eca3f26
authored
Dec 14, 2015
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Starting aggregate views
parent
1eddb241
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
13 deletions
+33
-13
rate/rate.py
+21
-10
rate/static/css/rate.css
+3
-2
rate/static/html/staff_item.html
+9
-0
rate/static/js/src/rate.js
+0
-1
No files found.
rate/rate.py
View file @
8eca3f26
...
...
@@ -94,12 +94,15 @@ class RateXBlock(XBlock):
data
=
pkg_resources
.
resource_string
(
__name__
,
path
)
return
data
.
decode
(
"utf8"
)
def
get_prompt
(
self
,
index
):
def
get_prompt
(
self
,
index
=-
1
):
"""
Return the current prompt dictionary, doing appropriate
randomization if necessary, and falling back to defaults when
necessary.
"""
if
index
==
-
1
:
index
=
self
.
prompt_choice
_
=
self
.
runtime
.
service
(
self
,
'i18n'
)
.
ugettext
prompt
=
{
'freeform'
:
_
(
"Please provide us feedback on this section."
),
...
...
@@ -127,24 +130,27 @@ class RateXBlock(XBlock):
# we grab the prompt, prepopulated with defaults.
if
self
.
prompt_choice
<
0
or
self
.
prompt_choice
>=
len
(
self
.
prompts
):
self
.
prompt_choice
=
random
.
randint
(
0
,
len
(
self
.
prompts
)
-
1
)
prompt
=
self
.
get_prompt
(
self
.
prompt_choice
)
prompt
=
self
.
get_prompt
()
# Now, we render the RateXBlock. This may be redundant, since we
# don't always show it.
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"
)
if
self
.
vote_aggregate
and
self
.
is_staff
():
scale_item
=
self
.
resource_string
(
"static/html/staff_item.html"
)
else
:
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
]
img_urls
=
[
self
.
runtime
.
local_resource_url
(
self
,
'public/default_icons/{i}t.png'
.
format
(
i
=
i
)
)
for
i
in
range
(
1
,
6
)]
self
.
init_vote_aggregate
(
)
votes
=
self
.
vote_aggregate
scale
=
u""
.
join
(
scale_item
.
format
(
level
=
l
evel
,
icon
=
icon
,
i
=
i
,
active
=
active
)
for
(
l
evel
,
icon
,
i
,
active
)
in
zip
(
prompt
[
'mouseovers'
],
prompt
[
'icons'
],
indexes
,
active_vote
)
scale_item
.
format
(
level
=
l
,
icon
=
icon
,
i
=
i
,
active
=
a
,
votes
=
v
)
for
(
l
,
icon
,
i
,
a
,
v
)
in
zip
(
prompt
[
'mouseovers'
],
prompt
[
'icons'
],
indexes
,
active_vote
,
votes
)
)
if
self
.
user_vote
!=
-
1
:
_
=
self
.
runtime
.
service
(
self
,
'i18n'
)
.
ugettext
...
...
@@ -197,6 +203,12 @@ class RateXBlock(XBlock):
self
.
prompts
[
0
][
'likert'
]
=
data
.
get
(
'likert'
)
return
{
'result'
:
'success'
}
def
init_vote_aggregate
(
self
):
# Make sure we're initialized
print
self
.
get_prompt
()
if
not
self
.
vote_aggregate
:
self
.
vote_aggregate
=
[
0
]
*
(
len
(
self
.
get_prompt
()[
'mouseovers'
]))
def
vote
(
self
,
data
):
"""
Handle voting
...
...
@@ -206,8 +218,7 @@ class RateXBlock(XBlock):
prompt
=
self
.
get_prompt
(
self
.
prompt_choice
)
# Make sure we're initialized
if
not
self
.
vote_aggregate
:
self
.
vote_aggregate
=
[
0
]
*
len
(
prompt
[
'mouseovers'
])
self
.
init_vote_aggregate
()
# Remove old vote if we voted before
if
self
.
user_vote
!=
-
1
:
...
...
rate/static/css/rate.css
View file @
8eca3f26
...
...
@@ -44,8 +44,9 @@
.rate_block
.rate_radio
{
opacity
:
0
;
width
:
1px
;
padding
:
0
;
margin
:
0
;
padding
:
0px
;
margin
:
0px
;
position
:
absolute
;
}
.rate_block
.rate_sr_text
{
...
...
rate/static/html/staff_item.html
0 → 100644
View file @
8eca3f26
<div
style=
"display:inline-block; text-align:center; padding:0px 10px 0px 10px;"
>
<label
title=
"{level}"
>
<input
id=
"radio_{i}"
name=
"rate_scale"
class=
"rate_radio"
type=
"radio"
{
active
}
/>
<span
aria-hidden=
"true"
>
{icon}
</span>
<span
class=
"rate_sr_text"
>
{level}
</span>
<br/>
({votes})
</label>
</div>
rate/static/js/src/rate.js
View file @
8eca3f26
...
...
@@ -11,7 +11,6 @@ if (typeof Logger === 'undefined') {
};
}
function
RateXBlock
(
runtime
,
element
)
{
var
feedback_handler
=
runtime
.
handlerUrl
(
element
,
'feedback'
);
...
...
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