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
76252ae6
Commit
76252ae6
authored
Dec 12, 2014
by
swdanielli
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/pmitros/RecommenderXBlock
parents
d714edfa
21dce2e1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
27 deletions
+17
-27
recommender/recommender.py
+17
-27
No files found.
recommender/recommender.py
View file @
76252ae6
...
@@ -27,7 +27,7 @@ except ImportError:
...
@@ -27,7 +27,7 @@ except ImportError:
from
mako.lookup
import
TemplateLookup
from
mako.lookup
import
TemplateLookup
from
xblock.core
import
XBlock
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
List
,
Dict
,
Boolean
from
xblock.fields
import
Scope
,
List
,
Dict
,
Boolean
,
String
from
xblock.fragment
import
Fragment
from
xblock.fragment
import
Fragment
from
xblock.reference.plugins
import
Filesystem
from
xblock.reference.plugins
import
Filesystem
...
@@ -69,11 +69,11 @@ class RecommenderXBlock(XBlock):
...
@@ -69,11 +69,11 @@ class RecommenderXBlock(XBlock):
scope
=
Scope
.
user_info
scope
=
Scope
.
user_info
)
)
#
recommender_version = String(
recommender_version
=
String
(
#
help="The version of this RecommenderXBlock",
help
=
"The version of this RecommenderXBlock"
,
#
default="recommender.v1.0",
default
=
"recommender.v1.0"
,
#
scope=Scope.content
scope
=
Scope
.
content
#
)
)
intro_enabled
=
Boolean
(
intro_enabled
=
Boolean
(
help
=
"Take users on a little tour the first time they see the XBlock?"
,
default
=
True
,
scope
=
Scope
.
content
help
=
"Take users on a little tour the first time they see the XBlock?"
,
default
=
True
,
scope
=
Scope
.
content
...
@@ -82,7 +82,7 @@ class RecommenderXBlock(XBlock):
...
@@ -82,7 +82,7 @@ class RecommenderXBlock(XBlock):
default_recommendations
=
Dict
(
default_recommendations
=
Dict
(
help
=
"Dict of default help resources"
,
default
=
{},
scope
=
Scope
.
content
help
=
"Dict of default help resources"
,
default
=
{},
scope
=
Scope
.
content
)
)
# A dict of default recommenations, it is a JSON object across all users,
# A dict of default recommen
d
ations, it is a JSON object across all users,
# all runs of a course, for this xblock.
# all runs of a course, for this xblock.
# Usage: default_recommendations[index] = {
# Usage: default_recommendations[index] = {
# "id": (String) id of a resource,
# "id": (String) id of a resource,
...
@@ -94,12 +94,11 @@ class RecommenderXBlock(XBlock):
...
@@ -94,12 +94,11 @@ class RecommenderXBlock(XBlock):
# "description" : (String) the url of a resource's screenshot,
# "description" : (String) the url of a resource's screenshot,
# "descriptionText" : (String) a paragraph of
# "descriptionText" : (String) a paragraph of
# description/summary of a resource }
# description/summary of a resource }
# we use url as key (index) of resources
# we use url as key (index) of resourcs
recommendations
=
Dict
(
recommendations
=
Dict
(
help
=
"Dict of help resources"
,
default
=
{},
scope
=
Scope
.
user_state_summary
help
=
"Dict of help resources"
,
default
=
{},
scope
=
Scope
.
user_state_summary
)
)
# A dict of recommenations provided by students, it is a JSON object
# A dict of recommen
d
ations provided by students, it is a JSON object
# aggregated across many users of a single block.
# aggregated across many users of a single block.
# Usage: the same as default_recommendations
# Usage: the same as default_recommendations
...
@@ -221,18 +220,6 @@ class RecommenderXBlock(XBlock):
...
@@ -221,18 +220,6 @@ class RecommenderXBlock(XBlock):
data
=
pkg_resources
.
resource_string
(
__name__
,
path
)
data
=
pkg_resources
.
resource_string
(
__name__
,
path
)
return
data
.
decode
(
"utf8"
)
return
data
.
decode
(
"utf8"
)
def
md5_check_sum
(
self
,
data
):
"""
Generate the MD5 hash of file
Args:
data: the content of the file (e.g., open(filePath, 'rb').read())
Returns:
The MD5 hash
"""
md5
=
hashlib
.
md5
()
md5
.
update
(
data
)
return
md5
.
hexdigest
()
def
get_onetime_url
(
self
,
filename
):
def
get_onetime_url
(
self
,
filename
):
"""
"""
Return one time url for uploaded screenshot
Return one time url for uploaded screenshot
...
@@ -414,7 +401,7 @@ class RecommenderXBlock(XBlock):
...
@@ -414,7 +401,7 @@ class RecommenderXBlock(XBlock):
try
:
try
:
content
=
request
.
POST
[
'file'
]
.
file
.
read
()
content
=
request
.
POST
[
'file'
]
.
file
.
read
()
file_id
=
self
.
md5_check_sum
(
content
)
file_id
=
hashlib
.
md5
(
content
)
.
hexdigest
(
)
file_name
=
(
file_id
+
'.'
+
file_type
)
file_name
=
(
file_id
+
'.'
+
file_type
)
fhwrite
=
self
.
fs
.
open
(
file_name
,
"wb"
)
fhwrite
=
self
.
fs
.
open
(
file_name
,
"wb"
)
...
@@ -512,6 +499,7 @@ class RecommenderXBlock(XBlock):
...
@@ -512,6 +499,7 @@ class RecommenderXBlock(XBlock):
result
=
{}
result
=
{}
result
[
'id'
]
=
resource_id
result
[
'id'
]
=
resource_id
result
[
'old_id'
]
=
resource_id
result
[
'old_id'
]
=
resource_id
for
field
in
self
.
resource_content_fields
:
for
field
in
self
.
resource_content_fields
:
result
[
'old_'
+
field
]
=
self
.
recommendations
[
resource_id
][
field
]
result
[
'old_'
+
field
]
=
self
.
recommendations
[
resource_id
][
field
]
if
data
[
field
]
==
""
:
if
data
[
field
]
==
""
:
...
@@ -652,6 +640,7 @@ class RecommenderXBlock(XBlock):
...
@@ -652,6 +640,7 @@ class RecommenderXBlock(XBlock):
result
=
{}
result
=
{}
result
[
'id'
]
=
resource_id
result
[
'id'
]
=
resource_id
if
resource_id
in
self
.
endorsed_recommendation_ids
:
if
resource_id
in
self
.
endorsed_recommendation_ids
:
result
[
'status'
]
=
'undo endorsement'
result
[
'status'
]
=
'undo endorsement'
endorsed_index
=
self
.
endorsed_recommendation_ids
.
index
(
resource_id
)
endorsed_index
=
self
.
endorsed_recommendation_ids
.
index
(
resource_id
)
...
@@ -795,10 +784,11 @@ class RecommenderXBlock(XBlock):
...
@@ -795,10 +784,11 @@ class RecommenderXBlock(XBlock):
The primary view of the RecommenderXBlock, shown to students
The primary view of the RecommenderXBlock, shown to students
when viewing courses.
when viewing courses.
"""
"""
if
not
self
.
recommendations
:
self
.
recommendations
=
(
self
.
recommendations
=
self
.
default_recommendations
self
.
recommendations
or
if
not
self
.
recommendations
:
self
.
default_recommendations
or
self
.
recommendations
=
{}
{}
)
# Transition between two versions. In the previous version, there is
# Transition between two versions. In the previous version, there is
# no endorsed_recommendation_reasons. Thus, we add empty reasons to
# no endorsed_recommendation_reasons. Thus, we add empty reasons to
...
...
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