Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
RecommenderXBlock
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
RecommenderXBlock
Commits
0c6cbf77
Commit
0c6cbf77
authored
Jun 03, 2014
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Untested code server-side AJAX code
parent
98543f2c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
3 deletions
+43
-3
recommender/recommender.py
+43
-3
No files found.
recommender/recommender.py
View file @
0c6cbf77
...
...
@@ -61,9 +61,9 @@ class RecommenderXBlock(XBlock):
# Scope-wide. List of JSON objects corresponding to recommendations as defined in XML.
recommendations
=
List
(
help
=
"List of help resources"
,
default
=
[],
scope
=
Scope
.
content
)
# Upvotes for this particular user
upvotes
=
List
(
help
=
"List of items user gave upvote to"
,
default
=
False
,
scope
=
Scope
.
user_state
)
upvotes
=
List
(
help
=
"List of items user gave upvote to"
,
default
=
[]
,
scope
=
Scope
.
user_state
)
# Downvotes for this particular user
downvotes
=
List
(
help
=
"List of items user gave downvote to"
,
default
=
False
,
scope
=
Scope
.
user_state
)
downvotes
=
List
(
help
=
"List of items user gave downvote to"
,
default
=
[]
,
scope
=
Scope
.
user_state
)
template_lookup
=
None
...
...
@@ -73,16 +73,53 @@ class RecommenderXBlock(XBlock):
return
data
.
decode
(
"utf8"
)
@XBlock.json_handler
def
handle_upvote
(
slef
,
data
,
suffix
=
''
):
def
handle_upvote
(
self
,
data
,
suffix
=
''
):
''' untested '''
resource
=
data
[
'resource'
]
if
resource
in
upvotes
:
return
{
"Success"
:
False
}
if
resource
in
self
.
downvotes
:
del
self
.
downvotes
[
self
.
downvotes
.
index
(
resource
)]
self
.
recommendations
[
resource
][
'downvotes'
]
-=
1
self
.
upvotes
.
append
(
resource
)
self
.
recommendations
[
resource
][
'upvotes'
]
+=
1
print
"Upvote clicked!"
return
{
"Success"
:
True
}
@XBlock.json_handler
def
add_resource
(
self
,
data
,
suffix
=
''
):
''' untested '''
resource
=
data
[
'resource'
]
## TODO: Return if already in resources
# Construct new resource
valid_fields
=
[
'url'
,
'title'
,
'description'
]
new_resource
=
{}
for
field
in
valid_fields
:
new_resource
[
field
]
=
data
[
'resource'
][
field
]
new_resource
[
'upvotes'
]
=
0
new_resource
[
'downvotes'
]
=
0
self
.
resources
.
append
(
new_resource
)
return
{
"Success"
:
True
}
@XBlock.json_handler
def
edit_resource
(
self
,
data
,
suffix
=
''
):
pass
@XBlock.json_handler
def
flag_resource
(
self
,
data
,
suffix
=
''
):
return
{
"Success"
:
True
}
# TO-DO: change this view to display your data your own way.
def
student_view
(
self
,
context
=
None
):
"""
The primary view of the RecommenderXBlock, shown to students
when viewing courses.
"""
print
"entered"
if
not
self
.
recommendations
:
self
.
recommendations
=
self
.
default_recommendations
...
...
@@ -92,6 +129,9 @@ class RecommenderXBlock(XBlock):
self
.
template_lookup
.
put_string
(
"resourcebox.html"
,
self
.
resource_string
(
"static/html/resourcebox.html"
))
resources
=
[{
'title'
:
r
[
'title'
],
"votes"
:
r
[
'up'
]
-
r
[
'down'
]}
for
r
in
self
.
recommendations
]
# TODO: Sort by votes
# Ideally, we'd estimate score based on votes, such that items with 1 vote have a sensible ranking (rather than a perfect rating)
#
frag
=
Fragment
(
self
.
template_lookup
.
get_template
(
"recommender.html"
)
.
render
(
resources
=
resources
))
frag
.
add_css_url
(
"//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css"
)
...
...
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