Merged Mako simplewiki changes.
This commit is contained in:
@@ -4,7 +4,7 @@ from pyparsing import Word, alphas, nums, oneOf, Literal
|
||||
from pyparsing import ZeroOrMore, OneOrMore, StringStart
|
||||
from pyparsing import StringEnd, Optional, Forward
|
||||
from pyparsing import CaselessLiteral, Group, StringEnd
|
||||
from pyparsing import NoMatch
|
||||
from pyparsing import NoMatch, stringEnd
|
||||
|
||||
|
||||
def evaluator(variables, functions, string):
|
||||
@@ -105,7 +105,7 @@ def evaluator(variables, functions, string):
|
||||
term = term.setParseAction(prod_parse_action)
|
||||
expr << Optional((plus|minus)) + term + ZeroOrMore((plus|minus)+term)
|
||||
expr=expr.setParseAction(sum_parse_action)
|
||||
return expr.parseString(string)[0]
|
||||
return (expr+stringEnd).parseString(string)[0]
|
||||
|
||||
if __name__=='__main__':
|
||||
variables={'R1':2.0, 'R3':4.0}
|
||||
@@ -117,4 +117,4 @@ if __name__=='__main__':
|
||||
print evaluator({'a': 2.2997471478310274, 'k': 9, 'm': 8, 'x': 0.66009498411213041}, {}, "5")
|
||||
print evaluator({},{}, "-1")
|
||||
print evaluator({},{}, "-(7+5)")
|
||||
print evaluator({},{}, "QWSEKO")
|
||||
print evaluator({},{}, "5+7 QWSEKO")
|
||||
|
||||
@@ -13,7 +13,7 @@ def strip_dict(d):
|
||||
(type(d[k]) == float or type(d[k]) == int) ])
|
||||
return d
|
||||
|
||||
class LoncapaProblem():
|
||||
class LoncapaProblem(object):
|
||||
def get_state(self):
|
||||
''' Stored per-user session data neeeded to:
|
||||
1) Recreate the problem
|
||||
@@ -168,9 +168,9 @@ class LoncapaProblem():
|
||||
return html
|
||||
|
||||
def grade_schem(self, element):
|
||||
print element
|
||||
return "correct"
|
||||
|
||||
|
||||
def grade_nr(self, question, answer):
|
||||
error = abs(evaluator({},{},answer) - question['answer'])
|
||||
allowed_error = abs(question['answer']*question['tolerance'])
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class XModule:
|
||||
class XModule(object):
|
||||
''' Implements a generic learning module.
|
||||
Initialized on access with __init__, first time with state=None, and
|
||||
then with state
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
ASKBOT_ENABLED = True
|
||||
|
||||
DEFAULT_FROM_EMAIL = 'pmitros@csail.mit.edu'
|
||||
DEFAULT_FEEDBACK_EMAIL = 'pmitros@csail.mit.edu'
|
||||
|
||||
WIKI_REQUIRE_LOGIN_EDIT = True
|
||||
WIKI_REQUIRE_LOGIN_VIEW = True
|
||||
|
||||
2
urls.py
2
urls.py
@@ -40,6 +40,8 @@ urlpatterns = ('',
|
||||
# url(r'^show_circuit/(?P<circuit>[^/]*)$', 'circuit.views.show_circuit'),
|
||||
url(r'^edit_circuit/(?P<circuit>[^/]*)$', 'circuit.views.edit_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:
|
||||
|
||||
0
util/__init__.py
Normal file
0
util/__init__.py
Normal file
3
util/models.py
Normal file
3
util/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
16
util/tests.py
Normal file
16
util/tests.py
Normal file
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
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)
|
||||
41
util/views.py
Normal file
41
util/views.py
Normal file
@@ -0,0 +1,41 @@
|
||||
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}))
|
||||
Reference in New Issue
Block a user