From d77f31dd382eb5c8ee38439b9fd92fad0d15e2cd Mon Sep 17 00:00:00 2001 From: stv Date: Sat, 28 Feb 2015 21:07:23 -0800 Subject: [PATCH 1/3] Remove circuit djangoapp from LMS These endpoints (`edit_circuit` and `save_circuit`) had already been commented out of `urls.py`, so these views were disabled. --- lms/djangoapps/circuit/__init__.py | 0 lms/djangoapps/circuit/models.py | 10 ----- lms/djangoapps/circuit/views.py | 65 ------------------------------ lms/envs/common.py | 1 - lms/static/coffee/src/main.coffee | 9 ----- lms/templates/edit_circuit.html | 8 ---- lms/urls.py | 4 -- 7 files changed, 97 deletions(-) delete mode 100644 lms/djangoapps/circuit/__init__.py delete mode 100644 lms/djangoapps/circuit/models.py delete mode 100644 lms/djangoapps/circuit/views.py delete mode 100644 lms/templates/edit_circuit.html diff --git a/lms/djangoapps/circuit/__init__.py b/lms/djangoapps/circuit/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/lms/djangoapps/circuit/models.py b/lms/djangoapps/circuit/models.py deleted file mode 100644 index 8da678f08a10..000000000000 --- a/lms/djangoapps/circuit/models.py +++ /dev/null @@ -1,10 +0,0 @@ -from django.db import models - - -class ServerCircuit(models.Model): - # Later, add owner, who can edit, part of what app, etc. - name = models.CharField(max_length=32, unique=True, db_index=True) - schematic = models.TextField(blank=True) - - def __unicode__(self): - return self.name + ":" + self.schematic[:8] diff --git a/lms/djangoapps/circuit/views.py b/lms/djangoapps/circuit/views.py deleted file mode 100644 index 3e8a39cb4349..000000000000 --- a/lms/djangoapps/circuit/views.py +++ /dev/null @@ -1,65 +0,0 @@ -import json - -import xml.etree.ElementTree - -from django.http import Http404 -from django.http import HttpResponse -from edxmako.shortcuts import render_to_response - -from .models import ServerCircuit - - -def circuit_line(circuit): - ''' Returns string for an appropriate input element for a circuit. - TODO: Rename. ''' - if not circuit.isalnum(): - raise Http404() - try: - sc = ServerCircuit.objects.get(name=circuit) - schematic = sc.schematic - except: - schematic = '' - - circuit_line = xml.etree.ElementTree.Element('input') - circuit_line.set('type', 'hidden') - circuit_line.set('class', 'schematic') - circuit_line.set('width', '640') - circuit_line.set('height', '480') - circuit_line.set('name', 'schematic') - circuit_line.set('id', 'schematic_' + circuit) - circuit_line.set('value', schematic) # We do it this way for security -- guarantees users cannot put funny stuff in schematic. - return xml.etree.ElementTree.tostring(circuit_line) - - -def edit_circuit(_request, circuit): - try: - sc = ServerCircuit.objects.get(name=circuit) - except: - sc = None - - if not circuit.isalnum(): - raise Http404() - response = render_to_response('edit_circuit.html', {'name': circuit, - 'circuit_line': circuit_line(circuit)}) - response['Cache-Control'] = 'no-cache' - return response - - -def save_circuit(request, circuit): - if not circuit.isalnum(): - raise Http404() - print dict(request.POST) - schematic = request.POST['schematic'] - print schematic - try: - sc = ServerCircuit.objects.get(name=circuit) - except: - sc = ServerCircuit() - sc.name = circuit - sc.schematic = schematic - print ":", sc.schematic - sc.save() - json_str = json.dumps({'results': 'success'}) - response = HttpResponse(json_str, mimetype='application/json') - response['Cache-Control'] = 'no-cache' - return response diff --git a/lms/envs/common.py b/lms/envs/common.py index 9b761399ac50..90a29ee83c7b 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1819,7 +1819,6 @@ 'openedx.core.djangoapps.theming', # Our courseware - 'circuit', 'courseware', 'student', diff --git a/lms/static/coffee/src/main.coffee b/lms/static/coffee/src/main.coffee index 561225761db7..6db41318e5d7 100644 --- a/lms/static/coffee/src/main.coffee +++ b/lms/static/coffee/src/main.coffee @@ -18,15 +18,6 @@ $ -> if $('body').hasClass('courseware') Courseware.start() - # Preserved for backward compatibility - window.submit_circuit = (circuit_id) -> - $("input.schematic").each (index, el) -> - el.schematic.update_value() - - schematic_value $("#schematic_#{circuit_id}").attr("value") - $.postWithPrefix "/save_circuit/#{circuit_id}", schematic: schematic_value, (data) -> - alert('Saved') if data.results == 'success' - window.postJSON = (url, data, callback) -> $.postWithPrefix url, data, callback diff --git a/lms/templates/edit_circuit.html b/lms/templates/edit_circuit.html deleted file mode 100644 index ca72cf040de8..000000000000 --- a/lms/templates/edit_circuit.html +++ /dev/null @@ -1,8 +0,0 @@ -
-
- -${ circuit_line } - - -
-
diff --git a/lms/urls.py b/lms/urls.py index 6ef2f67cdb6a..20fbe25763f5 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -331,10 +331,6 @@ # TODO: These views need to be updated before they work url(r'^calculate$', 'util.views.calculate'), - # TODO: We should probably remove the circuit package. I believe it was only used in the old way of saving wiki - # circuits for the wiki - # url(r'^edit_circuit/(?P[^/]*)$', 'circuit.views.edit_circuit'), - # url(r'^save_circuit/(?P[^/]*)$', 'circuit.views.save_circuit'), url(r'^courses/?$', 'branding.views.courses', name="courses"), url(r'^change_enrollment$', From a8d30c5de28f6816be8be52848f92edfd3cd832c Mon Sep 17 00:00:00 2001 From: stv Date: Tue, 20 Oct 2015 17:41:52 -0700 Subject: [PATCH 2/3] Remove circuit-schematic integration from wiki --- .../xmodule/xmodule/js/src/capa/schematic.js | 18 ----- common/static/js/capa/schematicinput.js | 9 --- .../vendor/CodeMirror/addons/edx_markdown.js | 38 +--------- .../plugins/markdownedx/mdx_circuit.py | 71 ------------------- .../plugins/markdownedx/wiki_plugin.py | 4 +- lms/static/sass/course/wiki/_wiki.scss | 54 -------------- lms/templates/show_circuit.html | 2 - lms/templates/wiki/base.html | 4 -- lms/templates/wiki/includes/cheatsheet.html | 1 - lms/templates/wiki/preview_inline.html | 5 -- 10 files changed, 4 insertions(+), 202 deletions(-) delete mode 100755 lms/djangoapps/course_wiki/plugins/markdownedx/mdx_circuit.py delete mode 100644 lms/templates/show_circuit.html diff --git a/common/lib/xmodule/xmodule/js/src/capa/schematic.js b/common/lib/xmodule/xmodule/js/src/capa/schematic.js index 8e7e9aaa27d6..c856987bc318 100644 --- a/common/lib/xmodule/xmodule/js/src/capa/schematic.js +++ b/common/lib/xmodule/xmodule/js/src/capa/schematic.js @@ -1987,23 +1987,6 @@ function update_schematics() { } window.update_schematics = update_schematics; -// add ourselves to the tasks that get performed when window is loaded -function add_schematic_handler(other_onload) { - return function() { - // execute othe onload functions first - if (other_onload) other_onload(); - - update_schematics(); - } -} - -// ask each schematic input widget to update its value field for submission -function prepare_schematics() { - var schematics = $('.schematic'); - for (var i = schematics.length - 1; i >= 0; i--) - schematics[i].schematic.update_value(); -} - schematic = (function() { var background_style = 'rgb(220,220,220)'; var element_style = 'rgb(255,255,255)'; @@ -6196,4 +6179,3 @@ schematic = (function() { } return module; }()); - diff --git a/common/static/js/capa/schematicinput.js b/common/static/js/capa/schematicinput.js index e4769374c41b..65e81d2e103c 100644 --- a/common/static/js/capa/schematicinput.js +++ b/common/static/js/capa/schematicinput.js @@ -1,8 +1,3 @@ -var schematic_height = 220; -var schematic_width = 400; -var styling_height_delta = 2; //How many pixels are added to the height of the box because of styling (like a shadow) -var styling_width_delta = 2; - $(function() { // TODO: someone should fix all of this... //$("a[rel*=leanModal]").leanModal(); //TODO: Make this work with the new modal library. Try and integrate this with the "slices" @@ -50,9 +45,5 @@ $(function() { editingCircuit.schematic.load_schematic(saving_circuit, ""); editingCircuit.schematic.zoomall(); - - if (editingCircuit.codeMirrorLine) { - editingCircuit.codeMirrorLine.replace(0, null, "circuit-schematic:" + saving_circuit); - } }); }); diff --git a/common/static/js/vendor/CodeMirror/addons/edx_markdown.js b/common/static/js/vendor/CodeMirror/addons/edx_markdown.js index f107b0bac409..3900683e9cfc 100644 --- a/common/static/js/vendor/CodeMirror/addons/edx_markdown.js +++ b/common/static/js/vendor/CodeMirror/addons/edx_markdown.js @@ -19,7 +19,7 @@ CodeMirror.defineMode("edx_markdown", function(cmCfg, modeCfg) { , olRE = /^[0-9]+\.\s+/ , headerRE = /^(?:\={3,}|-{3,})$/ , textRE = /^[^\[*_\\<>`]+/ - , circuitRE = /^circuit-schematic:(.*)$/; + ; function switchInline(stream, state, f) { state.f = state.inline = f; @@ -55,43 +55,9 @@ CodeMirror.defineMode("edx_markdown", function(cmCfg, modeCfg) { .replace(/'/g, "'"); } - var circuit_formatter = { - creator: function(text) { - var circuit_value = text.match(circuitRE)[1] - - circuit_value = escapeHtml(circuit_value); - - var html = ""; - - return html; - }, - size: function(text) { - return {width: schematic_width + styling_width_delta, height:schematic_height + styling_height_delta}; - }, - callback: function(node, line) { - try { - update_schematics(); - var schmInput = node.firstChild.firstChild; - schmInput.codeMirrorLine = line; - if (schmInput.schematic) { //This is undefined if there was an error making the schematic - schmInput.schematic.canvas.style.display = "block"; //Otherwise, it gets line height and is a weird size - schmInput.schematic.always_draw_grid = true; - schmInput.schematic.redraw_background(); - } - } catch (err) { - console.log("Error in edx_markdown callback: " + err); - } - - } - }; - function blockNormal(stream, state) { var match; - if (stream.sol() && stream.match(circuitRE)) { - stream.skipToEnd(); - return circuit_formatter; - } else if (state.indentationDiff >= 4) { + if (state.indentationDiff >= 4) { state.indentation -= state.indentationDiff; stream.skipToEnd(); return code; diff --git a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_circuit.py b/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_circuit.py deleted file mode 100755 index f90cb61123bf..000000000000 --- a/lms/djangoapps/course_wiki/plugins/markdownedx/mdx_circuit.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python -''' -Image Circuit Extension for Python-Markdown -====================================== - - -Any single line beginning with circuit-schematic: and followed by data (which should be json data, but this -is not enforced at this level) will be displayed as a circuit schematic. This is simply an input element with -the value set to the data. It is left to javascript on the page to render that input as a circuit schematic. - -ex: -circuit-schematic:[["r",[128,48,0],{"r":"1","_json_":0},["2","1"]],["view",0,0,2,null,null,null,null,null,null,null],["dc",{"0":0,"1":1,"I(_3)":-1}]] - -(This is a schematic with a single one-ohm resistor. Note that this data is not meant to be user-editable.) - -''' -import markdown -import re - -from django.utils.html import escape - -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): - for key, value in configs: - self.setConfig(key, value) - - def extendMarkdown(self, md, md_globals): - ## Because Markdown treats contigous lines as one block of text, it is hard to match - ## a regex that must occupy the whole line (like the circuit regex). This is why we have - ## a preprocessor that inspects the lines and replaces the matched lines with text that is - ## easier to match - md.preprocessors.add('circuit', CircuitPreprocessor(md), "_begin") - - pattern = CircuitLink(r'processed-schematic:(?P.*?)processed-schematic-end') - pattern.md = md - pattern.ext = self - md.inlinePatterns.add('circuit', pattern, ".*)$') - - def run(self, lines): - def convertLine(line): - m = self.preRegex.match(line) - if m: - return 'processed-schematic:{0}processed-schematic-end'.format(m.group('data')) - else: - return line - - return [convertLine(line) for line in lines] - - -class CircuitLink(markdown.inlinepatterns.Pattern): - def handleMatch(self, m): - data = m.group('data') - data = escape(data) - return etree.fromstring("
") - - -def makeExtension(configs=None): - to_return = CircuitExtension(configs=configs) - return to_return diff --git a/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py b/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py index 4b4ce97749c7..8a497384cc10 100644 --- a/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py +++ b/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py @@ -3,7 +3,7 @@ from wiki.core.plugins.base import BasePlugin from wiki.core.plugins import registry as plugin_registry -from course_wiki.plugins.markdownedx import mdx_circuit, mdx_mathjax, mdx_video +from course_wiki.plugins.markdownedx import mdx_mathjax, mdx_video class ExtendMarkdownPlugin(BasePlugin): @@ -11,7 +11,7 @@ class ExtendMarkdownPlugin(BasePlugin): This plugin simply loads all of the markdown extensions we use in edX. """ - markdown_extensions = [mdx_circuit.CircuitExtension(configs={}), + markdown_extensions = [ mdx_mathjax.MathJaxExtension(configs={}), mdx_video.VideoExtension(configs={})] diff --git a/lms/static/sass/course/wiki/_wiki.scss b/lms/static/sass/course/wiki/_wiki.scss index 03ba78d48e4c..3dbdbf2f5079 100644 --- a/lms/static/sass/course/wiki/_wiki.scss +++ b/lms/static/sass/course/wiki/_wiki.scss @@ -973,57 +973,3 @@ section.wiki { width: 100% !important; margin-left: 0; } - - -#circuit_editor_modal.modal { - @extend %ui-depth4; - width: 648px; - margin-left: -325px; - top: 150px; - - .modal-header { - h1, p { - color: $white; - } - - h1 { - margin: 3px 12px 8px; - font-size: 1.1em; - } - - p { - font-size: 0.9em; - margin: 5px 12px 20px; - line-height: 1em; - } - } - - .modal-body { - padding-bottom: 8px; - } - - .modal-footer { - margin: 12px; - } - - .modal-footer .btn { - @include button(simple, #eee); - font-size: 0.8em; - margin-right: ($baseline/4); - line-height: 1.2em; - text-transform: none !important; - letter-spacing: 0 !important; - - &:hover, &:focus { - color: $base-font-color; - text-decoration: none; - } - - &.btn-primary { - @include button; - font-size: 0.8em; - } - - margin-right: ($baseline/2); - } -} diff --git a/lms/templates/show_circuit.html b/lms/templates/show_circuit.html deleted file mode 100644 index 69a66f9a0336..000000000000 --- a/lms/templates/show_circuit.html +++ /dev/null @@ -1,2 +0,0 @@ -
-
diff --git a/lms/templates/wiki/base.html b/lms/templates/wiki/base.html index f64206fb6e28..52f528168f08 100644 --- a/lms/templates/wiki/base.html +++ b/lms/templates/wiki/base.html @@ -34,10 +34,6 @@ {% addtoblock 'js' %} {% comment %} These scripts load at the bottom of the body {% endcomment %} - - diff --git a/lms/templates/wiki/includes/cheatsheet.html b/lms/templates/wiki/includes/cheatsheet.html index fd2385b8058a..a69edeafc898 100644 --- a/lms/templates/wiki/includes/cheatsheet.html +++ b/lms/templates/wiki/includes/cheatsheet.html @@ -22,7 +22,6 @@

{% trans "Wiki Syntax Help" %}

{% blocktrans with platform_name=settings.PLATFORM_NAME %}{{ platform_name }} Additions:{% endblocktrans %}

-
circuit-schematic:
$LaTeX {% trans "Math Expression" %}$
diff --git a/lms/templates/wiki/preview_inline.html b/lms/templates/wiki/preview_inline.html index 67e26234c2c6..955aa6416bf9 100644 --- a/lms/templates/wiki/preview_inline.html +++ b/lms/templates/wiki/preview_inline.html @@ -41,11 +41,6 @@

{{ title }}

{% compressed_js 'application' %} {% compressed_js 'module-js' %} - - - {% with mathjax_mode='wiki' %} {% include "mathjax_include.html" %} {% endwith %} From c2fe4483ba70f0ca37b4713a51baf0804a68accd Mon Sep 17 00:00:00 2001 From: stv Date: Thu, 22 Oct 2015 19:17:03 -0700 Subject: [PATCH 3/3] Fix PEP8: E126 continuation line over-indented for hanging indent --- .../course_wiki/plugins/markdownedx/wiki_plugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py b/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py index 8a497384cc10..407aa77c750d 100644 --- a/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py +++ b/lms/djangoapps/course_wiki/plugins/markdownedx/wiki_plugin.py @@ -12,7 +12,8 @@ class ExtendMarkdownPlugin(BasePlugin): """ markdown_extensions = [ - mdx_mathjax.MathJaxExtension(configs={}), - mdx_video.VideoExtension(configs={})] + mdx_mathjax.MathJaxExtension(configs={}), + mdx_video.VideoExtension(configs={}), + ] plugin_registry.register(ExtendMarkdownPlugin)