Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx-platform
Commits
b67bed62
Commit
b67bed62
authored
Jan 25, 2013
by
Alexander Kryklia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve format, send poll divs via json
parent
d597ac4c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
59 deletions
+23
-59
common/lib/xmodule/xmodule/poll_module.py
+19
-40
lms/templates/poll.html
+4
-19
No files found.
common/lib/xmodule/xmodule/poll_module.py
View file @
b67bed62
...
...
@@ -54,8 +54,7 @@ class PollModule(XModule):
downvotes
=
Integer
(
help
=
"Number of downvotes this poll has recieved"
,
scope
=
Scope
.
content
,
default
=
0
)
# voted = Boolean(help="Whether this student has voted on the poll", scope=Scope.student_state, default=False)
html_render
=
String
(
scope
=
Scope
.
content
)
sequence
=
String
(
scope
=
Scope
.
content
)
xml_object
=
String
(
scope
=
Scope
.
content
)
def
handle_ajax
(
self
,
dispatch
,
get
):
'''
...
...
@@ -80,35 +79,24 @@ class PollModule(XModule):
def
get_html
(
self
):
""" Renders parameters to template. """
self
.
html_id
=
self
.
location
.
html_id
()
self
.
html_class
=
self
.
location
.
category
self
.
poll_units_list
=
[]
# import ipdb; ipdb.set_trace()
params
=
{
'element_html'
:
self
.
html_render
,
'element_id'
:
self
.
html_id
,
'element_class'
:
self
.
html_class
,
'element_id'
:
self
.
location
.
html_id
(),
'element_class'
:
self
.
location
.
category
,
'ajax_url'
:
self
.
system
.
ajax_url
,
'poll_chain'
:
self
.
parse_sequence
(
self
.
sequence
),
'configuration_json'
:
json
.
dumps
({}),
'poll_units'
:
self
.
poll_units_list
'configuration_json'
:
self
.
dump_poll
(),
}
self
.
content
=
self
.
system
.
render_template
(
'poll.html'
,
params
)
self
.
content
=
self
.
system
.
render_template
(
'poll.html'
,
params
)
return
self
.
content
def
get_poll_unit_html
(
self
,
i
,
question
,
css_class
):
""" """
return
"""
"""
.
format
(
poll_number
=
i
,
question
=
question
,
css_class
=
css_class
)
def
parse_sequence
(
self
,
html_string
):
""" substitute sequence """
return
[(
stringify_children
(
pu
.
xpath
(
'//question'
)[
0
]),
(
pu
.
get
(
'plot'
,
"no"
),
pu
.
get
(
'next_yes'
,
"end"
),
pu
.
get
(
'next_no'
,
"end"
),
pu
.
get
(
'id'
)))
for
pu
in
html
.
fromstring
(
html_string
)
.
xpath
(
'//unit'
)]
def
dump_poll
(
self
):
""" """
return
json
.
dumps
({
'poll_chain'
:
[{
'question'
:
stringify_children
(
q
),
'id'
:
q
.
get
(
'id'
),
'upvote_id'
:
q
.
get
(
'upvote'
,
""
),
'downvote_id'
:
q
.
get
(
'downvote'
,
""
),
'show_stats'
:
q
.
get
(
'show_stats'
,
"yes"
)}
for
q
in
self
.
xml_object
.
xpath
(
'question'
)]})
class
PollDescriptor
(
MakoModuleDescriptor
,
XmlDescriptor
):
...
...
@@ -127,21 +115,12 @@ class PollDescriptor(MakoModuleDescriptor, XmlDescriptor):
Returns:
dict
"""
# import ipdb; ipdb.set_trace()
# check for presense of required tags in xml
expected_children_level_0
=
[
'render'
,
'sequence'
]
for
child
in
expected_children_level_0
:
if
len
(
xml_object
.
xpath
(
child
))
!=
1
:
raise
ValueError
(
"Poll definition must include
\
exactly one '{0}' tag"
.
format
(
child
))
def
parse
(
k
):
"""Assumes that xml_object has child k"""
return
stringify_children
(
xml_object
.
xpath
(
k
)[
0
])
return
{
'html_render'
:
parse
(
'render'
),
'sequence'
:
parse
(
'sequence'
)
},
[]
if
len
(
xml_object
.
xpath
(
'question'
))
==
0
:
raise
ValueError
(
"Poll definition must include
\
at least one 'question' tag"
)
return
{
'xml_object'
:
xml_object
},
[]
def
definition_to_xml
(
self
,
resource_fs
):
'''Return an xml element representing this definition.'''
...
...
lms/templates/poll.html
View file @
b67bed62
<section
id=
"poll_${element_id}"
class=
"${element_class}"
data-ajax-url=
"${ajax_url}"
>
data-ajax-url=
"${ajax_url}"
>
<!-- Hidden field to read configuration JSON from. -->
<div
class=
"${element_class}_div"
id=
"${element_id}_json"
style=
"display: none;"
>
${configuration_json}
</div>
<!-- Main HTML. -->
${element_html}
style=
"display: none;"
>
${configuration_json}
</div>
% for question, controls in poll_chain:
<div
id=
"poll_unit_${loop.index}"
class=
"${'' if loop.index == 0 else 'hidden'} polls"
>
${question}
<div
class=
"vote_and_submit"
>
<div
id=
"vote_block-${loop.index}"
class=
"vote"
>
<a
class=
"upvote"
>
Yes
</a>
<a
class=
"downvote"
>
No
</a>
</div>
</div>
<div
class=
"graph_answer"
></div>
</div>
% endfor
</section>
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