Commit db0cd781 by Diana Huang

Remove some outdated code.

parent a69e42dd
# A simple script demonstrating how to have an external program post problem
# responses to an edx server.
#
# ***** NOTE *****
# This is not intended as a stable public API. In fact, it is almost certainly
# going to change. If you use this for some reason, be prepared to change your
# code.
#
# We will be working to define a stable public API for external programs. We
# don't have have one yet (Feb 2013).
import requests
import sys
import getpass
def prompt(msg, default=None, safe=False):
d = ' [{0}]'.format(default) if default is not None else ''
prompt = 'Enter {msg}{default}: '.format(msg=msg, default=d)
if not safe:
print prompt
x = sys.stdin.readline().strip()
else:
x = getpass.getpass(prompt=prompt)
if x == '' and default is not None:
return default
return x
server = 'https://www.edx.org'
course_id = 'HarvardX/PH207x/2012_Fall'
location = 'i4x://HarvardX/PH207x/problem/ex_practice_2'
#server = prompt('Server (no trailing slash)', 'http://127.0.0.1:8000')
#course_id = prompt('Course id', 'MITx/7012x/2013_Spring')
#location = prompt('problem location', 'i4x://MITx/7012x/problem/example_upload_answer')
value = prompt('value to upload')
username = prompt('username on server', 'victor@edx.org')
password = prompt('password', 'abc123', safe=True)
print "get csrf cookie"
session = requests.Session()
r = session.get(server + '/')
r.raise_for_status()
# print session.cookies
# for some reason, the server expects a header containing the csrf cookie, not just the
# cookie itself.
session.headers['X-CSRFToken'] = session.cookies['csrftoken']
# for https, need a referer header
session.headers['Referer'] = server + '/'
login_url = '/'.join([server, 'login'])
print "log in"
r = session.post(login_url, {'email': 'victor@edx.org', 'password': 'Secret!', 'remember': 'false'})
#print "request headers: ", r.request.headers
#print "response headers: ", r.headers
r.raise_for_status()
url = '/'.join([server, 'courses', course_id, 'modx', location, 'problem_check'])
data = {'input_{0}_2_1'.format(location.replace('/','-').replace(':','').replace('--','-')): value}
#data = {'input_i4x-MITx-7012x-problem-example_upload_answer_2_1': value}
print "Posting to '{0}': {1}".format(url, data)
r = session.post(url, data)
r.raise_for_status()
print ("To see the uploaded answer, go to {server}/courses/{course_id}/jump_to/{location}"
.format(server=server, course_id=course_id, location=location))
import os.path
# THIS COMMAND IS OUT OF DATE
from lxml import etree
from django.core.management.base import BaseCommand
from django.conf import settings
from django.contrib.auth.models import User
import xmodule
from xmodule.modulestore.django import modulestore
from courseware.model_data import FieldDataCache
from courseware.module_render import get_module
def check_rendering(module):
'''Check that all modules render'''
all_ok = True
print "Confirming all modules render. Nothing should print during this step. "
def _check_module(module):
try:
module.get_html()
except Exception as ex:
print "==============> Error in ", module.id
print ""
print ex
all_ok = False
for child in module.get_children():
_check_module(child)
_check_module(module)
print "Module render check finished"
return all_ok
def check_sections(course):
all_ok = True
sections_dir = settings.DATA_DIR + "/sections"
print "Checking that all sections exist and parse properly"
if os.path.exists(sections_dir):
print "Checking all section includes are valid XML"
for f in os.listdir(sections_dir):
sectionfile = sections_dir + '/' + f
#print sectionfile
# skip non-xml files:
if not sectionfile.endswith('xml'):
continue
try:
etree.parse(sectionfile)
except Exception as ex:
print "================> Error parsing ", sectionfile
print ex
all_ok = False
print "checked all sections"
else:
print "Skipping check of include files -- no section includes dir (" + sections_dir + ")"
return all_ok
class Command(BaseCommand):
help = "Does basic validity tests on course.xml."
def handle(self, *args, **options):
all_ok = True
# TODO (vshnayder): create dummy user objects. Anon, authenticated, staff.
# Check that everything works for each.
# The objects probably shouldn't be actual django users to avoid unneeded
# dependency on django.
# TODO: use args as list of files to check. Fix loading to work for other files.
print "This command needs updating before use"
return
"""
sample_user = User.objects.all()[0]
print "Attempting to load courseware"
# TODO (cpennington): Get coursename in a legitimate way
course_location = 'i4x://edx/6002xs12/course/6.002_Spring_2012'
student_module_cache = FieldDataCache.cache_for_descriptor_descendents(
course_id,
sample_user, modulestore().get_item(course_location))
course = get_module(sample_user, None, course_location, student_module_cache)
to_run = [
#TODO (vshnayder) : make check_rendering work (use module_render.py),
# turn it on
check_rendering,
check_sections,
]
for check in to_run:
all_ok = check(course) and all_ok
# TODO: print "Checking course properly annotated with preprocess.py"
if all_ok:
print 'Courseware passes all checks!'
else:
print "Courseware fails some checks"
"""
# multicourse/multicourse_settings.py
#
# central module for providing fixed settings (course name, number, title)
# for multiple courses. Loads this information from django.conf.settings
#
# Allows backward compatibility with settings configurations without
# multiple courses specified.
#
# The central piece of configuration data is the dict COURSE_SETTINGS, with
# keys being the COURSE_NAME (spaces ok), and the value being a dict of
# parameter,value pairs. The required parameters are:
#
# - number : course number (used in the wiki pages)
# - title : humanized descriptive course title
#
# Optional parameters:
#
# - xmlpath : path (relative to data directory) for this course (defaults to "")
#
# If COURSE_SETTINGS does not exist, then fallback to 6.002_Spring_2012 default,
# for now.
from django.conf import settings
#-----------------------------------------------------------------------------
# load course settings
if hasattr(settings, 'COURSE_SETTINGS'): # in the future, this could be replaced by reading an XML file
COURSE_SETTINGS = settings.COURSE_SETTINGS
elif hasattr(settings, 'COURSE_NAME'): # backward compatibility
COURSE_SETTINGS = {settings.COURSE_NAME: {'number': settings.COURSE_NUMBER,
'title': settings.COURSE_TITLE,
'location': settings.COURSE_LOCATION,
},
}
else: # default to 6.002_Spring_2012
COURSE_SETTINGS = {'6.002_Spring_2012': {'number': '6.002x',
'title': 'Circuits and Electronics',
'location': 'i4x://edx/6002xs12/course/6.002 Spring 2012',
},
}
#-----------------------------------------------------------------------------
# wrapper functions around course settings
def get_coursename_from_request(request):
if 'coursename' in request.session:
coursename = request.session['coursename']
settings.COURSE_TITLE = get_course_title(coursename) # overwrite settings.COURSE_TITLE based on this
else: coursename = None
return coursename
def get_course_settings(coursename):
if not coursename:
if hasattr(settings, 'COURSE_DEFAULT'):
coursename = settings.COURSE_DEFAULT
else:
coursename = '6.002_Spring_2012'
if coursename in COURSE_SETTINGS:
return COURSE_SETTINGS[coursename]
coursename = coursename.replace(' ', '_')
if coursename in COURSE_SETTINGS:
return COURSE_SETTINGS[coursename]
return None
def is_valid_course(coursename):
return get_course_settings(coursename) is not None
def get_course_property(coursename, property):
cs = get_course_settings(coursename)
# raise exception instead?
if not cs:
return ''
if property in cs:
return cs[property]
# default
return ''
def get_course_xmlpath(coursename):
return get_course_property(coursename, 'xmlpath')
def get_course_title(coursename):
return get_course_property(coursename, 'title')
def get_course_number(coursename):
return get_course_property(coursename, 'number')
def get_course_github_url(coursename):
return get_course_property(coursename, 'github_url')
def get_course_default_chapter(coursename):
return get_course_property(coursename, 'default_chapter')
def get_course_default_section(coursename):
return get_course_property(coursename, 'default_section')
def get_course_location(coursename):
return get_course_property(coursename, 'location')
from django.conf import settings
from edxmako.shortcuts import render_to_response
from multicourse import multicourse_settings
def edxhome(request):
''' Home page (link from main header). List of courses. '''
if settings.DEBUG:
print "[djangoapps.multicourse.edxhome] EDX_ROOT_URL = " + settings.EDX_ROOT_URL
if settings.ENABLE_MULTICOURSE:
context = {'courseinfo': multicourse_settings.COURSE_SETTINGS}
return render_to_response("edXhome.html", context)
return info(request)
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