This commit is contained in:
Piotr Mitros
2012-01-14 11:09:38 -08:00
15 changed files with 90 additions and 71 deletions

View File

@@ -245,6 +245,10 @@ class LoncapaModule(XModule):
correct_map = self.lcp.grade_answers(answers)
except:
self.lcp = LoncapaProblem(filename, id=lcp_id, state=old_state)
print {'error':sys.exc_info(),
'answers':answers,
'seed':self.lcp.seed,
'filename':self.lcp.filename}
return json.dumps({'success':'syntax'})
self.attempts = self.attempts + 1

View File

@@ -125,7 +125,12 @@ LOGGING = {
}
}
TRACK_DIR = None
#TRACK_DIR = None
DEBUG_TRACK_LOG = False
# Maximum length of a tracking string. We don't want e.g. a file upload in our log
TRACK_MAX_EVENT = 1000
# Maximum length of log file before starting a new one.
MAXLOG = 500
execfile("../settings.py")

13
simplewiki/mdx_camelcase.py Normal file → Executable file
View File

@@ -1,7 +1,5 @@
#!/usr/bin/env python
print "Hello"
'''
WikiLink Extention for Python-Markdown
======================================
@@ -69,6 +67,13 @@ Dependencies:
'''
import markdown
try:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
# but import the 2.0.3 version if it fails
from markdown.util import etree
except:
from markdown import etree
class CamelCaseExtension(markdown.Extension):
def __init__(self, configs):
@@ -97,14 +102,14 @@ class CamelCaseExtension(markdown.Extension):
class CamelCaseLinks(markdown.inlinepatterns.Pattern):
def handleMatch(self, m) :
if m.group('escape') == '\\':
a = markdown.etree.Element('a')#doc.createTextNode(m.group('camelcase'))
a = etree.Element('a')#doc.createTextNode(m.group('camelcase'))
else :
url = m.group('camelcase')
#'%s%s%s'% (self.md.wiki_config['base_url'][0], \
#m.group('camelcase'), \
#self.md.wiki_config['end_url'][0])
label = m.group('camelcase').replace('_', ' ')
a = markdown.etree.Element('a')
a = etree.Element('a')
a.set('href', url)
a.text = label
a.set('class', 'wikilink')

16
simplewiki/mdx_circuit.py Normal file → Executable file
View File

@@ -7,12 +7,16 @@ circuit:name becomes the circuit.
'''
import simplewiki.settings as settings
import markdown
from markdown import etree_loader
from djangomako.shortcuts import render_to_response, render_to_string
ElementTree=etree_loader.importETree()
import markdown
try:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
# but import the 2.0.3 version if it fails
from markdown.util import etree
except:
from markdown import etree
class CircuitExtension(markdown.Extension):
def __init__(self, configs):
@@ -26,18 +30,16 @@ class CircuitExtension(markdown.Extension):
md.inlinePatterns.add(name, pattern, "<reference")
def extendMarkdown(self, md, md_globals):
print "Here"
self.add_inline(md, 'circuit', CircuitLink, r'^circuit:(?P<name>[a-zA-Z0-9]*)$')
class CircuitLink(markdown.inlinepatterns.Pattern):
def handleMatch(self, m):
name = m.group('name')
if not name.isalnum():
return ElementTree.fromstring("<div>Circuit name must be alphanumeric</div>")
return etree.fromstring("<div>Circuit name must be alphanumeric</div>")
return ElementTree.fromstring(render_to_string('show_circuit.html', {'name':name}))
return etree.fromstring(render_to_string('show_circuit.html', {'name':name}))
def makeExtension(configs=None) :
print "Here"
return CircuitExtension(configs=configs)

10
simplewiki/mdx_image.py Normal file → Executable file
View File

@@ -16,7 +16,15 @@ Requires Python-Markdown 1.6+
'''
import simplewiki.settings as settings
import markdown
try:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
# but import the 2.0.3 version if it fails
from markdown.util import etree
except:
from markdown import etree
class ImageExtension(markdown.Extension):
def __init__(self, configs):
@@ -35,7 +43,7 @@ class ImageExtension(markdown.Extension):
class ImageLink(markdown.inlinepatterns.Pattern):
def handleMatch(self, m):
img = markdown.etree.Element('img')
img = etree.Element('img')
proto = m.group('proto') or "http://"
domain = m.group('domain')
path = m.group('path')

View File

@@ -1,8 +1,12 @@
# Source: https://github.com/mayoff/python-markdown-mathjax
print "Hello"
import markdown
try:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
# but import the 2.0.3 version if it fails
from markdown.util import etree, AtomicString
except:
from markdown import etree, AtomicString
class MathJaxPattern(markdown.inlinepatterns.Pattern):
@@ -10,7 +14,9 @@ class MathJaxPattern(markdown.inlinepatterns.Pattern):
markdown.inlinepatterns.Pattern.__init__(self, r'(?<!\\)(\$\$?)(.+?)\2')
def handleMatch(self, m):
return markdown.AtomicString(m.group(2) + m.group(3) + m.group(2))
el = etree.Element('span')
el.text = AtomicString(m.group(2) + m.group(3) + m.group(2))
return el
class MathJaxExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):

17
simplewiki/mdx_video.py Normal file → Executable file
View File

@@ -128,6 +128,13 @@ u'<p><object data="http://www.gametrailers.com/remote_wrap.php?mid=58079" height
"""
import markdown
try:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
# but import the 2.0.3 version if it fails
from markdown.util import etree
except:
from markdown import etree
version = "0.1.6"
@@ -229,7 +236,7 @@ class Yahoo(markdown.inlinepatterns.Pattern):
width = self.ext.config['yahoo_width'][0]
height = self.ext.config['yahoo_height'][0]
obj = flash_object(url, width, height)
param = markdown.etree.Element('param')
param = etree.Element('param')
param.set('name', 'flashVars')
param.set('value', "id=%s&vid=%s" % (m.group('yahooid'),
m.group('yahoovid')))
@@ -244,20 +251,20 @@ class Youtube(markdown.inlinepatterns.Pattern):
return flash_object(url, width, height)
def flash_object(url, width, height):
obj = markdown.etree.Element('object')
obj = etree.Element('object')
obj.set('type', 'application/x-shockwave-flash')
obj.set('width', width)
obj.set('height', height)
obj.set('data', url)
param = markdown.etree.Element('param')
param = etree.Element('param')
param.set('name', 'movie')
param.set('value', url)
obj.append(param)
param = markdown.etree.Element('param')
param = etree.Element('param')
param.set('name', 'allowFullScreen')
param.set('value', 'true')
obj.append(param)
#param = markdown.etree.Element('param')
#param = etree.Element('param')
#param.set('name', 'allowScriptAccess')
#param.set('value', 'sameDomain')
#obj.append(param)

View File

@@ -247,7 +247,6 @@ class Revision(models.Model):
# Create pre-parsed contents - no need to parse on-the-fly
ext = WIKI_MARKDOWN_EXTENSIONS
print "Waka", WIKI_MARKDOWN_EXTENSIONS
ext += ["wikilinks(base_url=%s/)" % reverse('wiki_view', args=('',))]
self.contents_parsed = markdown(self.contents,
extensions=ext,

View File

@@ -94,7 +94,6 @@ WIKI_MARKDOWN_EXTENSIONS = getattr(settings, 'SIMPLE_WIKI_MARKDOWN_EXTENSIONS',
'circuit'
])
print WIKI_MARKDOWN_EXTENSIONS
WIKI_IMAGE_EXTENSIONS = getattr(settings,
'SIMPLE_WIKI_IMAGE_EXTENSIONS',

View File

View File

@@ -1,3 +0,0 @@
from django.db import models
# Create your models here.

View File

@@ -1,16 +0,0 @@
"""
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)

View File

@@ -1,18 +0,0 @@
from djangomako.shortcuts import render_to_response, render_to_string
from django.shortcuts import redirect
import os
from django.conf import settings
from django.http import Http404
# We don't do subdirectories to reduce odds of possible future
# security issues. Feel free to re-add them if needed -- just make
# sure things like /../../etc/passwd are handled okay.
valid_files=os.listdir(settings.TEXTBOOK_DIR)
def index(request, filename):
if filename in valid_files:
text=open(settings.TEXTBOOK_DIR+filename).read()
return render_to_response('textbook.html',{'text':text})
else:
raise Http404

View File

@@ -14,7 +14,6 @@ else:
logfile = None
file_index = 0
log_index = 0
MAXLOG = 5
filename = None
def make_file():
@@ -31,20 +30,28 @@ def make_file():
def log_event(event):
global logfile, log_index
event_str = json.dumps(event)
if settings.TRACK_DIR == None:
# print event
return
if logfile == None or log_index >= MAXLOG:
if logfile == None or log_index >= settings.MAXLOG:
make_file()
event_str = json.dumps(event)
logfile.write(event_str+'\n')
logfile.write(event_str[:settings.TRACK_MAX_EVENT]+'\n')
if settings.DEBUG_TRACK_LOG:
print event_str
log_index = log_index + 1
def user_track(request):
try: # TODO: Do the same for many of the optional META parameters
username = request.user.username
except:
username = "anonymous"
# TODO: Move a bunch of this into log_event
event = {
"username" : request.user.username,
"username" : username,
"session" : request.META['HTTP_COOKIE'],
"ip" : request.META['REMOTE_ADDR'],
"event_source" : "browser",
@@ -57,8 +64,13 @@ def user_track(request):
return HttpResponse('success')
def server_track(request, event_type, event, page=None):
try:
username = request.user.username
except:
username = "anonymous"
event = {
"username" : request.user.username,
"username" : username,
"ip" : request.META['REMOTE_ADDR'],
"event_source" : "server",
"event_type" : event_type,

View File

@@ -10,27 +10,36 @@ import courseware.capa.calc
from django.core.mail import send_mail
from django.conf import settings
import datetime
import sys
import track.views
def calculate(request):
if not request.user.is_authenticated():
raise Http404
# if not request.user.is_authenticated():
# raise Http404
equation = request.GET['equation']
try:
result = courseware.capa.calc.evaluator({}, {}, equation)
except:
event = {'error':map(str,sys.exc_info()),
'equation':equation}
track.views.server_track(request, 'error:calc', event, page='calc')
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
# if not request.user.is_authenticated():
# raise Http404
try:
username = request.user.username
except:
username = "anonymous"
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})
"user":username})
send_mail("MITx Feedback / " +request.POST['subject'],
feedback,