Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crowdsourcehinter
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
OpenEdx
crowdsourcehinter
Commits
9c616d1f
Commit
9c616d1f
authored
Sep 28, 2015
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving Studio view to use JSON instead of AST, and to have slightly cleaner validation logic
parent
a541d654
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
18 deletions
+19
-18
crowdsourcehinter/crowdsourcehinter.py
+19
-18
No files found.
crowdsourcehinter/crowdsourcehinter.py
View file @
9c616d1f
import
ast
import
logging
import
logging
import
operator
import
operator
import
pkg_resources
import
pkg_resources
...
@@ -95,7 +94,8 @@ class CrowdsourceHinter(XBlock):
...
@@ -95,7 +94,8 @@ class CrowdsourceHinter(XBlock):
it in a course. It will allow one to define, for example,
it in a course. It will allow one to define, for example,
which problem the hinter is for.
which problem the hinter is for.
It is currently a dummy function -- we still need to build an authoring view.
It is currently incomplete -- we still need to finish building the
authoring view.
"""
"""
html
=
self
.
resource_string
(
"static/html/crowdsourcehinterstudio.html"
)
html
=
self
.
resource_string
(
"static/html/crowdsourcehinterstudio.html"
)
frag
=
Fragment
(
html
)
frag
=
Fragment
(
html
)
...
@@ -110,23 +110,24 @@ class CrowdsourceHinter(XBlock):
...
@@ -110,23 +110,24 @@ class CrowdsourceHinter(XBlock):
"""
"""
Set intial hints, generic hints, and problem element from the
Set intial hints, generic hints, and problem element from the
studio view.
studio view.
The Studio view is not yet complete.
"""
"""
# TODO: json.loads, or better yet, yaml.
initial_hints
=
json
.
loads
(
data
[
'initial_hints'
])
# ast.literal_eval follows Python syntax, which is not what we want.
generic_hints
=
json
.
loads
(
data
[
'generic_hints'
])
initial
=
ast
.
literal_eval
(
str
(
data
[
'initial_hints'
]))
generic
=
ast
.
literal_eval
(
str
(
data
[
'generic_hints'
]))
if
not
isinstance
(
generic_hints
,
list
):
# TODO: Break into validation and then setting:
return
{
'success'
:
False
,
# if type(generic) is not list or type(initial) is not dict:
'error'
:
'Generic hints should be a list.'
}
# return {'success': False}
if
not
isinstance
(
initial_hints
,
dict
):
# As a matter of style, we're better off using instanceof than
return
{
'success'
:
False
,
# comparing type.
'error'
:
'Initial hints should be a dict.'
}
# ...
if
type
(
generic
)
is
list
and
type
(
initial
)
is
dict
:
self
.
initial_hints
=
initial_hints
self
.
initial_hints
=
initial
self
.
generic_hints
=
generic_hints
self
.
generic_hints
=
generic
if
len
(
str
(
data
[
'element'
]))
>
1
:
self
.
Element
=
str
(
data
[
'element'
])
self
.
Element
=
str
(
data
[
'element'
])
return
{
'success'
:
True
}
return
{
'success'
:
True
}
return
{
'success'
:
False
}
def
student_view
(
self
,
context
=
None
):
def
student_view
(
self
,
context
=
None
):
"""
"""
...
@@ -396,7 +397,7 @@ class CrowdsourceHinter(XBlock):
...
@@ -396,7 +397,7 @@ class CrowdsourceHinter(XBlock):
A minimal working test for parse_xml
A minimal working test for parse_xml
"""
"""
block
=
runtime
.
construct_xblock_from_class
(
cls
,
keys
)
block
=
runtime
.
construct_xblock_from_class
(
cls
,
keys
)
xmlText
=
ast
.
literal_eval
(
str
(
node
.
text
)
)
xmlText
=
json
.
loads
(
node
.
text
)
if
xmlText
:
if
xmlText
:
block
.
generic_hints
.
append
(
str
(
xmlText
[
"generic_hints"
]))
block
.
generic_hints
.
append
(
str
(
xmlText
[
"generic_hints"
]))
block
.
initial_hints
=
copy
.
copy
(
xmlText
[
"initial_hints"
])
block
.
initial_hints
=
copy
.
copy
(
xmlText
[
"initial_hints"
])
...
...
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