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
e50fd0f9
Commit
e50fd0f9
authored
May 28, 2012
by
ichuang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add check code to dogfood; cleaned up interface to quickedit
parent
3df1845f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
10 deletions
+59
-10
lib/dogfood/__init__.py
+1
-0
lib/dogfood/check.py
+51
-0
lib/dogfood/views.py
+7
-10
No files found.
lib/dogfood/__init__.py
View file @
e50fd0f9
from
check
import
*
lib/dogfood/check.py
0 → 100644
View file @
e50fd0f9
#!/usr/bin/python
from
random
import
choice
import
string
import
traceback
from
django.conf
import
settings
import
courseware.capa.capa_problem
as
lcp
from
dogfood.views
import
update_problem
def
GenID
(
length
=
8
,
chars
=
string
.
letters
+
string
.
digits
):
return
''
.
join
([
choice
(
chars
)
for
i
in
range
(
length
)])
randomid
=
GenID
()
def
check_problem_code
(
ans
,
the_lcp
,
correct_answers
,
false_answers
):
"""
ans = student's answer
the_lcp = LoncapaProblem instance
returns dict {'ok':is_ok,'msg': message with iframe}
"""
pfn
=
"dog
%
s"
%
randomid
pfn
+=
the_lcp
.
problem_id
.
replace
(
'filename'
,
''
)
# add problem ID to dogfood problem name
update_problem
(
pfn
,
ans
,
filestore
=
the_lcp
.
system
.
filestore
)
msg
=
'<hr width="100
%
"/>'
msg
+=
'<iframe src="
%
s/dogfood/filename
%
s" width="95
%%
" frameborder="1">No iframe support!</iframe>'
%
(
settings
.
MITX_ROOT_URL
,
pfn
)
msg
+=
'<hr width="100
%
"/>'
is_ok
=
True
try
:
# check correctness
fp
=
the_lcp
.
system
.
filestore
.
open
(
'problems/
%
s.xml'
%
pfn
)
test_lcp
=
lcp
.
LoncapaProblem
(
fp
,
'1'
,
system
=
the_lcp
.
system
)
if
not
(
test_lcp
.
grade_answers
(
correct_answers
)[
'1_2_1'
]
==
'correct'
):
is_ok
=
False
if
(
test_lcp
.
grade_answers
(
false_answers
)[
'1_2_1'
]
==
'correct'
):
is_ok
=
False
except
Exception
,
err
:
is_ok
=
False
msg
+=
"<p>Error:
%
s</p>"
%
str
(
err
)
.
replace
(
'<'
,
'<'
)
msg
+=
"<p><pre>
%
s</pre></p>"
%
traceback
.
format_exc
()
.
replace
(
'<'
,
'<'
)
ret
=
{
'ok'
:
is_ok
,
'msg'
:
msg
,
}
return
ret
\ No newline at end of file
lib/dogfood/views.py
View file @
e50fd0f9
...
...
@@ -65,11 +65,11 @@ def df_capa_problem(request, id=None):
Accepts XML for a problem, inserts it into the dogfood course.xml.
Returns rendered problem.
'''
print
"WARNING: UNDEPLOYABLE CODE. FOR DEV USE ONLY."
print
"In deployed use, this will only edit on one server"
print
"We need a setting to disable for production where there is"
print
"a load balanacer"
# "WARNING: UNDEPLOYABLE CODE. FOR DEV USE ONLY."
if
settings
.
DEBUG
:
print
'[lib.dogfood.df_capa_problem] id=
%
s'
%
id
if
not
'coursename'
in
request
.
session
:
coursename
=
DOGFOOD_COURSENAME
else
:
...
...
@@ -133,11 +133,8 @@ def df_capa_problem(request, id=None):
if
not
xml
:
print
"[lib.dogfood.df_capa_problem] problem xml not found!"
# add problem ID to list so that is_staff check can be bypassed
request
.
session
[
'dogfood_id'
]
=
id
# hand over to quickedit to do the rest
try
:
html
=
quickedit
(
request
,
id
=
id
,
qetemplate
=
'dogfood.html'
,
coursename
=
coursename
)
return
html
except
Exception
,
err
:
print
'[lib.dogfood.df_capa_problem] Error generating html on first pass:
%
s'
%
err
return
quickedit
(
request
,
id
=
id
,
qetemplate
=
'dogfood.html'
,
coursename
=
coursename
)
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