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
8874d9d7
Commit
8874d9d7
authored
Jan 03, 2013
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a draft implementation of the Poll module for Justice
parent
465c85b0
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
94 additions
and
1 deletions
+94
-1
common/lib/xmodule/setup.py
+2
-1
common/lib/xmodule/xmodule/js/src/poll/display.coffee
+14
-0
common/lib/xmodule/xmodule/poll_module.py
+55
-0
common/test/data/toy/course/2012_Fall.xml
+1
-0
lms/djangoapps/courseware/module_render.py
+12
-0
lms/templates/poll.html
+10
-0
No files found.
common/lib/xmodule/setup.py
View file @
8874d9d7
...
...
@@ -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"
,
],
}
)
common/lib/xmodule/xmodule/js/src/poll/display.coffee
0 → 100644
View file @
8874d9d7
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
)
\ No newline at end of file
common/lib/xmodule/xmodule/poll_module.py
0 → 100644
View file @
8874d9d7
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"
\ No newline at end of file
common/test/data/toy/course/2012_Fall.xml
View file @
8874d9d7
...
...
@@ -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"
/>
...
...
lms/djangoapps/courseware/module_render.py
View file @
8874d9d7
...
...
@@ -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
...
...
lms/templates/poll.html
0 → 100644
View file @
8874d9d7
<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>
\ No newline at end of file
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