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
d561504c
Commit
d561504c
authored
Jan 09, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Plain Diff
Merged Mako simplewiki changes.
parents
5d3d5489
2aec53aa
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
69 additions
and
6 deletions
+69
-6
courseware/calc.py
+3
-3
courseware/capa_problem.py
+2
-2
courseware/x_module.py
+1
-1
settings.py
+1
-0
urls.py
+2
-0
util/__init__.py
+0
-0
util/models.py
+3
-0
util/tests.py
+16
-0
util/views.py
+41
-0
No files found.
courseware/calc.py
View file @
d561504c
...
@@ -4,7 +4,7 @@ from pyparsing import Word, alphas, nums, oneOf, Literal
...
@@ -4,7 +4,7 @@ from pyparsing import Word, alphas, nums, oneOf, Literal
from
pyparsing
import
ZeroOrMore
,
OneOrMore
,
StringStart
from
pyparsing
import
ZeroOrMore
,
OneOrMore
,
StringStart
from
pyparsing
import
StringEnd
,
Optional
,
Forward
from
pyparsing
import
StringEnd
,
Optional
,
Forward
from
pyparsing
import
CaselessLiteral
,
Group
,
StringEnd
from
pyparsing
import
CaselessLiteral
,
Group
,
StringEnd
from
pyparsing
import
NoMatch
from
pyparsing
import
NoMatch
,
stringEnd
def
evaluator
(
variables
,
functions
,
string
):
def
evaluator
(
variables
,
functions
,
string
):
...
@@ -105,7 +105,7 @@ def evaluator(variables, functions, string):
...
@@ -105,7 +105,7 @@ def evaluator(variables, functions, string):
term
=
term
.
setParseAction
(
prod_parse_action
)
term
=
term
.
setParseAction
(
prod_parse_action
)
expr
<<
Optional
((
plus
|
minus
))
+
term
+
ZeroOrMore
((
plus
|
minus
)
+
term
)
expr
<<
Optional
((
plus
|
minus
))
+
term
+
ZeroOrMore
((
plus
|
minus
)
+
term
)
expr
=
expr
.
setParseAction
(
sum_parse_action
)
expr
=
expr
.
setParseAction
(
sum_parse_action
)
return
expr
.
parseString
(
string
)[
0
]
return
(
expr
+
stringEnd
)
.
parseString
(
string
)[
0
]
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
variables
=
{
'R1'
:
2.0
,
'R3'
:
4.0
}
variables
=
{
'R1'
:
2.0
,
'R3'
:
4.0
}
...
@@ -117,4 +117,4 @@ if __name__=='__main__':
...
@@ -117,4 +117,4 @@ if __name__=='__main__':
print
evaluator
({
'a'
:
2.2997471478310274
,
'k'
:
9
,
'm'
:
8
,
'x'
:
0.66009498411213041
},
{},
"5"
)
print
evaluator
({
'a'
:
2.2997471478310274
,
'k'
:
9
,
'm'
:
8
,
'x'
:
0.66009498411213041
},
{},
"5"
)
print
evaluator
({},{},
"-1"
)
print
evaluator
({},{},
"-1"
)
print
evaluator
({},{},
"-(7+5)"
)
print
evaluator
({},{},
"-(7+5)"
)
print
evaluator
({},{},
"QWSEKO"
)
print
evaluator
({},{},
"
5+7
QWSEKO"
)
courseware/capa_problem.py
View file @
d561504c
...
@@ -13,7 +13,7 @@ def strip_dict(d):
...
@@ -13,7 +13,7 @@ def strip_dict(d):
(
type
(
d
[
k
])
==
float
or
type
(
d
[
k
])
==
int
)
])
(
type
(
d
[
k
])
==
float
or
type
(
d
[
k
])
==
int
)
])
return
d
return
d
class
LoncapaProblem
():
class
LoncapaProblem
(
object
):
def
get_state
(
self
):
def
get_state
(
self
):
''' Stored per-user session data neeeded to:
''' Stored per-user session data neeeded to:
1) Recreate the problem
1) Recreate the problem
...
@@ -168,9 +168,9 @@ class LoncapaProblem():
...
@@ -168,9 +168,9 @@ class LoncapaProblem():
return
html
return
html
def
grade_schem
(
self
,
element
):
def
grade_schem
(
self
,
element
):
print
element
return
"correct"
return
"correct"
def
grade_nr
(
self
,
question
,
answer
):
def
grade_nr
(
self
,
question
,
answer
):
error
=
abs
(
evaluator
({},{},
answer
)
-
question
[
'answer'
])
error
=
abs
(
evaluator
({},{},
answer
)
-
question
[
'answer'
])
allowed_error
=
abs
(
question
[
'answer'
]
*
question
[
'tolerance'
])
allowed_error
=
abs
(
question
[
'answer'
]
*
question
[
'tolerance'
])
...
...
courseware/x_module.py
View file @
d561504c
class
XModule
:
class
XModule
(
object
)
:
''' Implements a generic learning module.
''' Implements a generic learning module.
Initialized on access with __init__, first time with state=None, and
Initialized on access with __init__, first time with state=None, and
then with state
then with state
...
...
settings.py
View file @
d561504c
ASKBOT_ENABLED
=
True
ASKBOT_ENABLED
=
True
DEFAULT_FROM_EMAIL
=
'pmitros@csail.mit.edu'
DEFAULT_FROM_EMAIL
=
'pmitros@csail.mit.edu'
DEFAULT_FEEDBACK_EMAIL
=
'pmitros@csail.mit.edu'
WIKI_REQUIRE_LOGIN_EDIT
=
True
WIKI_REQUIRE_LOGIN_EDIT
=
True
WIKI_REQUIRE_LOGIN_VIEW
=
True
WIKI_REQUIRE_LOGIN_VIEW
=
True
...
...
urls.py
View file @
d561504c
...
@@ -40,6 +40,8 @@ urlpatterns = ('',
...
@@ -40,6 +40,8 @@ urlpatterns = ('',
# url(r'^show_circuit/(?P<circuit>[^/]*)$', 'circuit.views.show_circuit'),
# url(r'^show_circuit/(?P<circuit>[^/]*)$', 'circuit.views.show_circuit'),
url
(
r'^edit_circuit/(?P<circuit>[^/]*)$'
,
'circuit.views.edit_circuit'
),
url
(
r'^edit_circuit/(?P<circuit>[^/]*)$'
,
'circuit.views.edit_circuit'
),
url
(
r'^save_circuit/(?P<circuit>[^/]*)$'
,
'circuit.views.save_circuit'
),
url
(
r'^save_circuit/(?P<circuit>[^/]*)$'
,
'circuit.views.save_circuit'
),
url
(
r'^calculate$'
,
'util.views.calculate'
),
url
(
r'^send_feedback$'
,
'util.views.send_feedback'
),
)
)
if
settings
.
ASKBOT_ENABLED
:
if
settings
.
ASKBOT_ENABLED
:
...
...
util/__init__.py
0 → 100644
View file @
d561504c
util/models.py
0 → 100644
View file @
d561504c
from
django.db
import
models
# Create your models here.
util/tests.py
0 → 100644
View file @
d561504c
"""
This file demonstrates writing tests using the unittest module. These will pass
when you run "manage.py test".
Replace this with more appropriate tests for your application.
"""
from
django.test
import
TestCase
class
SimpleTest
(
TestCase
):
def
test_basic_addition
(
self
):
"""
Tests that 1 + 1 always equals 2.
"""
self
.
assertEqual
(
1
+
1
,
2
)
util/views.py
0 → 100644
View file @
d561504c
from
djangomako.shortcuts
import
render_to_response
,
render_to_string
from
django.shortcuts
import
redirect
from
django.contrib.auth.models
import
User
from
django.http
import
HttpResponse
import
json
from
django.conf
import
settings
from
django.core.context_processors
import
csrf
from
django.http
import
Http404
import
courseware.calc
from
django.core.mail
import
send_mail
from
django.conf
import
settings
import
datetime
def
calculate
(
request
):
if
not
request
.
user
.
is_authenticated
():
raise
Http404
equation
=
request
.
GET
[
'equation'
]
try
:
result
=
courseware
.
calc
.
evaluator
({},
{},
equation
)
except
:
return
HttpResponse
(
json
.
dumps
({
'result'
:
'Invalid syntax'
}))
return
HttpResponse
(
json
.
dumps
({
'result'
:
result
}))
def
send_feedback
(
request
):
if
not
request
.
user
.
is_authenticated
():
raise
Http404
feedback
=
render_to_string
(
"feedback_email.txt"
,
{
"subject"
:
request
.
POST
[
'subject'
],
"url"
:
request
.
POST
[
'url'
],
"time"
:
datetime
.
datetime
.
now
()
.
isoformat
(),
"feedback"
:
request
.
POST
[
'message'
],
"user"
:
request
.
user
.
username
})
send_mail
(
"MITx Feedback / "
+
request
.
POST
[
'subject'
],
feedback
,
settings
.
DEFAULT_FROM_EMAIL
,
[
settings
.
DEFAULT_FEEDBACK_EMAIL
],
fail_silently
=
False
)
return
HttpResponse
(
json
.
dumps
({
'success'
:
True
}))
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