Commit 8125180e by Piotr Mitros

Major number of minor cleanups. Fixed from e-mail, import order, ==None, etc.

parent 1abeec78
import uuid
from django.db import models
from django.contrib.auth.models import User
import uuid
class UserProfile(models.Model):
## CRITICAL TODO/SECURITY
......
import json
import logging
import random
import string
from djangomako.shortcuts import render_to_response, render_to_string
from django.contrib.auth.models import User
from django.shortcuts import redirect
from django.conf import settings
from django.contrib.auth import logout, authenticate, login
from django.contrib.auth.models import User
from django.http import HttpResponse
import json
from models import Registration, UserProfile
from django.conf import settings
from django.contrib.auth.models import User
from django.core.context_processors import csrf
from django.core.validators import validate_email, validate_slug
import random, string
from django.db import connection
from django.http import HttpResponse
from django.shortcuts import redirect
from djangomako.shortcuts import render_to_response, render_to_string
from models import Registration, UserProfile
log = logging.getLogger("mitx.auth")
......
import uuid
from django.db import models
from django.contrib.auth.models import User
import uuid
class ServerCircuit(models.Model):
# Later, add owner, who can edit, part of what app, etc.
......
from djangomako.shortcuts import render_to_response, render_to_string
from django.shortcuts import redirect
import json
import os
import xml.etree.ElementTree
from django.conf import settings
from django.http import Http404
from models import ServerCircuit
import json
import xml.etree.ElementTree
from django.http import HttpResponse
from django.shortcuts import redirect
from djangomako.shortcuts import render_to_response, render_to_string
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
print "Got"
except:
schematic = ''
print "not got"
print "X", schematic
circuit_line = xml.etree.ElementTree.Element('input')
circuit_line.set('type', 'hidden')
......
import math
import operator
from pyparsing import Word, alphas, nums, oneOf, Literal
from pyparsing import ZeroOrMore, OneOrMore, StringStart
from pyparsing import StringEnd, Optional, Forward
......
import random, numpy, math, scipy
import struct, os
import copy
import math
import numpy
import os
import random
import re
import scipy
import struct
from lxml import etree
from lxml.etree import Element
import copy
from mako.template import Template
from courseware.content_parser import xpath_remove
import calc, eia
from util import contextualize_text
from inputtypes import textline, schematic
from responsetypes import numericalresponse, formularesponse, customresponse, schematicresponse
import calc
import eia
response_types = {'numericalresponse':numericalresponse,
'formularesponse':formularesponse,
'customresponse':customresponse,
......@@ -52,12 +58,14 @@ class LoncapaProblem(object):
self.done = False
self.filename = filename
if id!=None:
if id:
self.problem_id = id
else:
self.problem_id = filename
print "NO ID"
raise Exception("This should never happen (183)")
#self.problem_id = filename
if state!=None:
if state:
if 'seed' in state:
self.seed = state['seed']
if 'student_answers' in state:
......@@ -68,7 +76,7 @@ class LoncapaProblem(object):
self.done = state['done']
# TODO: Does this deplete the Linux entropy pool? Is this fast enough?
if self.seed == None:
if not self.seed:
self.seed=struct.unpack('i', os.urandom(4))[0]
## Parse XML file
......@@ -102,7 +110,7 @@ class LoncapaProblem(object):
for key in self.correct_map:
if self.correct_map[key] == u'correct':
correct += 1
if self.student_answers == None or len(self.student_answers)==0:
if (not self.student_answers) or len(self.student_answers)==0:
return {'score':0,
'total':self.get_max_score()}
else:
......@@ -132,7 +140,7 @@ class LoncapaProblem(object):
for entry in problems_simple.xpath("//"+"|//".join(response_properties+entry_types)):
answer = entry.get('correct_answer')
if answer != None:
if answer:
answer_map[entry.get('id')] = contextualize_text(answer, self.context)
return answer_map
......@@ -162,7 +170,7 @@ class LoncapaProblem(object):
status = self.correct_map[problemtree.get('id')]
value = ""
if self.student_answers != None and problemtree.get('id') in self.student_answers:
if self.student_answers and problemtree.get('id') in self.student_answers:
value = self.student_answers[problemtree.get('id')]
return html_special_response[problemtree.tag](problemtree, value, status) #TODO
......@@ -170,7 +178,7 @@ class LoncapaProblem(object):
tree=Element(problemtree.tag)
for item in problemtree:
subitems = self.extract_html(item)
if subitems != None:
if subitems:
for subitem in subitems:
tree.append(subitem)
for (key,value) in problemtree.items():
......
from djangomako.shortcuts import render_to_response, render_to_string
from lxml.etree import Element
from lxml import etree
from djangomako.shortcuts import render_to_response, render_to_string
class textline(object):
@staticmethod
def render(element, value, state):
......
import random, numpy, math, scipy, json
from util import contextualize_text
import json
import math
import numpy
import random
import scipy
from calc import evaluator
import random, math
from django.conf import settings
import eia
from util import contextualize_text
import calc
import eia
# TODO: Should be the same object as in capa_problem
global_context={'random':random,
......
import math
from numpy import eye, array
import operator
from numpy import eye, array
from pyparsing import Word, alphas, nums, oneOf, Literal
from pyparsing import ZeroOrMore, OneOrMore, StringStart
from pyparsing import StringEnd, Optional, Forward
......
try:
import json
import hashlib
from lxml import etree
try: # This lets us do __name__ == ='__main__'
from django.conf import settings
from auth.models import UserProfile
except:
settings = None
from lxml import etree
import json
import hashlib
''' This file will eventually form an abstraction layer between the
course XML file and the rest of the system.
......
from django.db import models
from django.contrib.auth.models import User
# class Organization(models.Model):
# # Tree structure implemented such that child node has left ID
# # greater than all parents, and right ID less than all parents
# left_tree_id = models.IntegerField(unique=True, db_index=True)
# right_tree_id = models.IntegerField(unique=True, db_index=True)
# # This is a duplicate, but we keep this to enforce unique name
# # constraint
# parent = models.ForeignKey('self', null=True, blank=True)
# name = models.CharField(max_length=200)
# ORG_TYPES= (('course','course'),
# ('chapter','chapter'),
# ('section','section'),)
# org_type = models.CharField(max_length=32, choices=ORG_TYPES)
# available = models.DateField(null=True, blank=True)
# due = models.DateField(null=True, blank=True)
# # JSON dictionary of metadata:
# # Time for a video, format of a section, etc.
# metadata = models.TextField(null=True, blank=True)
# class Modules(models.Model):
# MOD_TYPES = (('hw','homework'),
# ('vid','video_clip'),
# ('lay','layout'),
# (),)
# module_type = models.CharField(max_length=100)
# left_tree_id = models.IntegerField(unique=True, db_index=True)
# right_tree_id = models.IntegerField(unique=True, db_index=True)
# LAYOUT_TYPES = (('leaf','leaf'),
# ('tab','tab'),
# ('seq','sequential'),
# ('sim','simultaneous'),)
# layout_type = models.CharField(max_length=32, choices=LAYOUT_TYPES)
# data = models.TextField(null=True, blank=True)
#class HomeworkProblems(models.Model):
class StudentModule(models.Model):
# For a homework problem, contains a JSON
# object consisting of state
......
import StringIO
import json
import os
import sys
import sys
import urllib
import uuid
from lxml import etree
from django.conf import settings
from django.contrib.auth.models import User
from django.core.context_processors import csrf
from django.db import connection
from django.http import Http404
from django.http import HttpResponse
from django.shortcuts import redirect
from django.template import Context
from django.template import Context, loader
from djangomako.shortcuts import render_to_response, render_to_string
import json, os, sys
from django.core.context_processors import csrf
from django.db import connection
from django.template import Context
from django.contrib.auth.models import User
from auth.models import UserProfile
from django.shortcuts import redirect
import StringIO
from models import StudentModule
import track.views
from django.http import Http404
import urllib
import courseware.content_parser as content_parser
import courseware.modules.capa_module
import courseware.modules.video_module
import courseware.modules.vertical_module
import courseware.modules.html_module
import courseware.modules.schematic_module
import courseware.modules.seq_module
from models import StudentModule
import urllib
from django.conf import settings
import courseware.content_parser as content_parser
import sys
from lxml import etree
import uuid
import courseware.modules.vertical_module
import courseware.modules.video_module
## TODO: Add registration mechanism
modx_modules={'problem':courseware.modules.capa_module.LoncapaModule,
......@@ -93,7 +88,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
ajax_return=instance.handle_ajax(dispatch, request.POST)
# Save the state back to the database
s.state=instance.get_state()
if instance.get_score() != None:
if not instance.get_score():
s.grade=instance.get_score()['score']
s.save()
# Return whatever the module wanted to return to the client/caller
......@@ -107,15 +102,14 @@ def render_x_module(user, request, xml_module, module_object_preload):
module_id=xml_module.get('id') #module_class.id_attribute) or ""
# Grab state from database
s = object_cache(module_object_preload,
user,
module_type,
module_id)
smod = object_cache(module_object_preload,
user,
module_type,
module_id)
if s == None: # If nothing in the database...
if not smod: # If nothing in the database...
state=None
else:
smod = s
state = smod.state
# Create a new instance
......@@ -128,7 +122,7 @@ def render_x_module(user, request, xml_module, module_object_preload):
render_function = lambda x: render_module(user, request, x, module_object_preload))
# If instance wasn't already in the database, create it
if s == None:
if not smod:
smod=StudentModule(student=user,
module_type = module_type,
module_id=module_id,
......
import random, numpy, math, scipy, sys, StringIO, os, struct, json
from x_module import XModule
import sys
from courseware.capa.capa_problem import LoncapaProblem
from django.http import Http404
import StringIO
import datetime
import dateutil
import dateutil.parser
import datetime
import courseware.content_parser as content_parser
import json
import math
import numpy
import os
import random
import scipy
import struct
import sys
import traceback
from lxml import etree
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from django.http import Http404
from x_module import XModule
from courseware.capa.capa_problem import LoncapaProblem
import courseware.content_parser as content_parser
class LoncapaModule(XModule):
''' Interface between capa_problem and x_module. Originally a hack
......@@ -231,6 +237,8 @@ class LoncapaModule(XModule):
for key in get:
answers['_'.join(key.split('_')[1:])]=get[key]
print "XXX", answers, get
event_info['answers']=answers
# Too late. Cannot submit
......@@ -255,6 +263,7 @@ class LoncapaModule(XModule):
correct_map = self.lcp.grade_answers(answers)
except:
self.lcp = LoncapaProblem(filename, id=lcp_id, state=old_state)
traceback.print_exc()
print {'error':sys.exc_info(),
'answers':answers,
'seed':self.lcp.seed,
......
from x_module import XModule
from lxml import etree
import json
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from x_module import XModule
from lxml import etree
class HtmlModule(XModule):
id_attribute = 'filename'
......
from x_module import XModule
import json
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from x_module import XModule
class SchematicModule(XModule):
id_attribute = 'id'
......
from x_module import XModule
from lxml import etree
from django.http import Http404
import json
from lxml import etree
## TODO: Abstract out from Django
from django.http import Http404
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from x_module import XModule
class SequentialModule(XModule):
''' Layout module which lays out content in a temporal sequence
'''
......
from x_module import XModule
from lxml import etree
import json
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from x_module import XModule
from lxml import etree
class VerticalModule(XModule):
id_attribute = 'id'
......
import logging
import json
import logging
from lxml import etree
## TODO: Abstract out from Django
from django.conf import settings
from djangomako.shortcuts import render_to_response, render_to_string
from lxml import etree
from x_module import XModule
......
......@@ -19,8 +19,9 @@ from lxml import etree
from auth.models import UserProfile
from models import StudentModule
from module_render import * # TODO: Clean up
from module_render import render_module, modx_dispatch
import courseware.content_parser as content_parser
import courseware.modules.capa_module
log = logging.getLogger("mitx.courseware")
......
import views, json, tempfile, time
import json
import tempfile
import time
from django.conf import settings
from django.db import connection
import views
class ProfileMiddleware:
def process_request (self, request):
......
# Create your views here.
import middleware
from django.http import HttpResponse
def end_profile(request):
......
......@@ -34,7 +34,7 @@ DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('Piotr Mitros', 'pmitros@csail.mit.edu'),
('Piotr Mitros', 'staff@csail.mit.edu'),
)
MANAGERS = ADMINS
......
......@@ -26,7 +26,7 @@ DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
('Piotr Mitros', 'pmitros@csail.mit.edu'),
('Piotr Mitros', 'staff@csail.mit.edu'),
)
MANAGERS = ADMINS
......
# Source: django-simplewiki. GPL license.
import sys, os
import os
import sys
# allow mdx_* parsers to be just dropped in the simplewiki folder
module_path = os.path.abspath(os.path.dirname(__file__))
......
# Source: django-simplewiki. GPL license.
from django.contrib import admin
from django import forms
from django.contrib import admin
from django.utils.translation import ugettext as _
from models import Article, Revision, Permission, ArticleAttachment
class RevisionInline(admin.TabularInline):
......
from django.utils.translation import ugettext_lazy as _
import difflib
import os
from django import forms
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.db import models
from django.db.models import signals
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from markdown import markdown
from django import forms
from django.core.urlresolvers import reverse
import difflib
import os
from settings import *
class ShouldHaveExactlyOneRootSlug(Exception):
......
from django import template
from django.template.defaultfilters import stringfilter
from simplewiki.settings import *
from django.conf import settings
from django.template.defaultfilters import stringfilter
from django.utils.http import urlquote as django_urlquote
from simplewiki.settings import *
register = template.Library()
@register.filter()
......@@ -14,4 +15,4 @@ def prepend_media_url(value):
@register.filter()
def urlquote(value):
"""Prepend user defined media root to url"""
return django_urlquote(value)
\ No newline at end of file
return django_urlquote(value)
# -*- coding: utf-8 -*-
import types
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.core.context_processors import csrf
from django.core.urlresolvers import get_callable
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseServerError, HttpResponseForbidden, HttpResponseNotAllowed
from django.utils import simplejson
from djangomako.shortcuts import render_to_response, render_to_string
from django.shortcuts import get_object_or_404
from django.template import RequestContext, Context, loader
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from django.db.models import Q
from django.conf import settings
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseServerError, HttpResponseForbidden, HttpResponseNotAllowed
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.shortcuts import redirect
from django.core.context_processors import csrf
from django.template import Context
from django.http import HttpResponse
import djangomako.middleware
from mako.template import Template
from django.template import RequestContext, Context, loader
from django.utils import simplejson
from django.utils.translation import ugettext_lazy as _
from djangomako.shortcuts import render_to_response, render_to_string
from mako.lookup import TemplateLookup
from mako.template import Template
import djangomako.middleware
from models import *
from models import * # TODO: Clean up
from settings import *
def view(request, wiki_url):
......
import os
from django.contrib.auth.decorators import login_required
from django.core.servers.basehttp import FileWrapper
from django.db.models.fields.files import FieldFile
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseForbidden, Http404
from django.template import loader, Context
from django.db.models.fields.files import FieldFile
from django.core.servers.basehttp import FileWrapper
from django.contrib.auth.decorators import login_required
from settings import *
from settings import * # TODO: Clean up
from models import Article, ArticleAttachment, get_attachment_filepath
from views import not_found, check_permissions, get_url_path, fetch_from_url
import os
from simplewiki.settings import WIKI_ALLOW_ANON_ATTACHMENTS
......
# Create your views here.
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
from django.shortcuts import redirect
from djangomako.shortcuts import render_to_response, render_to_string
def index(request, page=0):
if not request.user.is_authenticated():
......
from django.conf.urls.defaults import patterns, include, url
import django.contrib.auth.views
from django.conf import settings
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
import perfstats
import django.contrib.auth.views
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
......
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 datetime
import json
import sys
from django.conf import settings
from django.conf import settings
from django.contrib.auth.models import User
from django.core.context_processors import csrf
from django.core.mail import send_mail
from django.http import Http404
from django.http import HttpResponse
from django.shortcuts import redirect
from djangomako.shortcuts import render_to_response, render_to_string
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
''' Calculator in footer of every page. '''
equation = request.GET['equation']
try:
result = courseware.capa.calc.evaluator({}, {}, equation)
......@@ -27,8 +28,7 @@ def calculate(request):
return HttpResponse(json.dumps({'result':result}))
def send_feedback(request):
# if not request.user.is_authenticated():
# raise Http404
''' Feeback mechanism in footer of every page. '''
try:
username = request.user.username
except:
......@@ -50,4 +50,5 @@ def send_feedback(request):
return HttpResponse(json.dumps({'success':True}))
def info(request):
''' Info page (link from main header) '''
return render_to_response("info.html", {})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment