Add a draft implementation of the Poll module for Justice
This commit is contained in:
@@ -39,7 +39,8 @@ setup(
|
||||
"course_info = xmodule.html_module:CourseInfoDescriptor",
|
||||
"static_tab = xmodule.html_module:StaticTabDescriptor",
|
||||
"custom_tag_template = xmodule.raw_module:RawDescriptor",
|
||||
"about = xmodule.html_module:AboutDescriptor"
|
||||
"about = xmodule.html_module:AboutDescriptor",
|
||||
"poll = xmodule.poll_module:PollDescriptor",
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
13
common/lib/xmodule/xmodule/js/src/poll/display.coffee
Normal file
13
common/lib/xmodule/xmodule/js/src/poll/display.coffee
Normal file
@@ -0,0 +1,13 @@
|
||||
class @PollModule
|
||||
constructor: (element) ->
|
||||
@el = element
|
||||
@ajaxUrl = @$('.container').data('url')
|
||||
@$('.upvote').on('click', () => $.postWithPrefix(@url('upvote'), @handleVote))
|
||||
@$('.downvote').on('click', () => $.postWithPrefix(@url('downvote'), @handleVote))
|
||||
|
||||
$: (selector) -> $(selector, @el)
|
||||
|
||||
url: (target) -> "#{@ajaxUrl}/#{target}"
|
||||
|
||||
handleVote: (response) =>
|
||||
@$('.container').replaceWith(response.results)
|
||||
54
common/lib/xmodule/xmodule/poll_module.py
Normal file
54
common/lib/xmodule/xmodule/poll_module.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import json
|
||||
import logging
|
||||
|
||||
from lxml import etree
|
||||
from pkg_resources import resource_string, resource_listdir
|
||||
|
||||
from xmodule.x_module import XModule
|
||||
from xmodule.raw_module import RawDescriptor
|
||||
from .model import Int, Scope, Boolean
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PollModule(XModule):
|
||||
|
||||
js = {'coffee': [resource_string(__name__, 'js/src/poll/display.coffee')]}
|
||||
js_module_name = "PollModule"
|
||||
|
||||
upvotes = Int(help="Number of upvotes this poll has recieved", scope=Scope.content, default=0)
|
||||
downvotes = Int(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)
|
||||
|
||||
def handle_ajax(self, dispatch, get):
|
||||
'''
|
||||
Handle ajax calls to this video.
|
||||
TODO (vshnayder): This is not being called right now, so the position
|
||||
is not being saved.
|
||||
'''
|
||||
if self.voted:
|
||||
return json.dumps({'error': 'Already Voted!'})
|
||||
elif dispatch == 'upvote':
|
||||
self.upvotes += 1
|
||||
self.voted = True
|
||||
return json.dumps({'results': self.get_html()})
|
||||
elif dispatch == 'downvote':
|
||||
self.downvotes += 1
|
||||
self.voted = True
|
||||
return json.dumps({'results': self.get_html()})
|
||||
|
||||
return json.dumps({'error': 'Unknown Command!'})
|
||||
|
||||
def get_html(self):
|
||||
return self.system.render_template('poll.html', {
|
||||
'upvotes': self.upvotes,
|
||||
'downvotes': self.downvotes,
|
||||
'voted': self.voted,
|
||||
'ajax_url': self.system.ajax_url,
|
||||
})
|
||||
|
||||
|
||||
class PollDescriptor(RawDescriptor):
|
||||
module_class = PollModule
|
||||
stores_state = True
|
||||
template_dir_name = "poll"
|
||||
@@ -3,6 +3,7 @@
|
||||
<videosequence url_name="Toy_Videos">
|
||||
<html url_name="secret:toylab"/>
|
||||
<video url_name="Video_Resources" youtube="1.0:1bK-WdDi6Qw"/>
|
||||
<poll url_name="test_poll" display_name="Test Poll"/>
|
||||
</videosequence>
|
||||
<video url_name="Welcome" youtube="1.0:p2Q6BrNhdh8"/>
|
||||
<video url_name="video_123456789012" youtube="1.0:p2Q6BrNhdh8"/>
|
||||
|
||||
@@ -231,6 +231,18 @@ def _get_module(user, request, location, student_module_cache, course_id, positi
|
||||
student_module.max_grade = event.get('max_value')
|
||||
student_module.save()
|
||||
|
||||
#Bin score into range and increment stats
|
||||
score_bucket = get_score_bucket(student_module.grade, student_module.max_grade)
|
||||
org, course_num, run = course_id.split("/")
|
||||
statsd.increment("lms.courseware.question_answered",
|
||||
tags=["org:{0}".format(org),
|
||||
"course:{0}".format(course_num),
|
||||
"run:{0}".format(run),
|
||||
"score_bucket:{0}".format(score_bucket),
|
||||
"type:ajax"])
|
||||
|
||||
|
||||
|
||||
# TODO (cpennington): When modules are shared between courses, the static
|
||||
# prefix is going to have to be specific to the module, not the directory
|
||||
# that the xml was loaded from
|
||||
|
||||
9
lms/templates/poll.html
Normal file
9
lms/templates/poll.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<div class='container' data-url="${ajax_url}">
|
||||
% if voted:
|
||||
<div>Upvotes: ${upvotes}</div>
|
||||
<div>Downvotes: ${downvotes}</div>
|
||||
% else:
|
||||
<a class="upvote">Yes</a>
|
||||
<a class="downvote">No</a>
|
||||
% endif
|
||||
</div>
|
||||
Reference in New Issue
Block a user