Commit 1d40ca02 by Calen Pennington

Allow anonymous user access to the site. Requires guest_courses.xml and…

Allow anonymous user access to the site. Requires guest_courses.xml and info/guest_updates.html to be set created in the data repository
parent e0a34f02
...@@ -141,6 +141,9 @@ def propogate_downward_tag(element, attribute_name, parent_attribute = None): ...@@ -141,6 +141,9 @@ def propogate_downward_tag(element, attribute_name, parent_attribute = None):
return return
def user_groups(user): def user_groups(user):
if not user.is_authenticated():
return []
# TODO: Rewrite in Django # TODO: Rewrite in Django
key = 'user_group_names_{user.id}'.format(user=user) key = 'user_group_names_{user.id}'.format(user=user)
cache_expiration = 60 * 60 # one hour cache_expiration = 60 * 60 # one hour
...@@ -171,12 +174,13 @@ def course_xml_process(tree): ...@@ -171,12 +174,13 @@ def course_xml_process(tree):
def course_file(user): def course_file(user):
''' Given a user, return course.xml''' ''' Given a user, return course.xml'''
#import logging
#log = logging.getLogger("tracking")
#log.info( "DEBUG: cf:"+str(user) )
filename = UserProfile.objects.get(user=user).courseware # user.profile_cache.courseware if user.is_authenticated():
groups = user_groups(user) filename = UserProfile.objects.get(user=user).courseware # user.profile_cache.courseware
groups = user_groups(user)
else:
filename = 'guest_course.xml'
groups = []
options = {'dev_content':settings.DEV_CONTENT, options = {'dev_content':settings.DEV_CONTENT,
'groups' : groups} 'groups' : groups}
......
...@@ -32,47 +32,6 @@ def make_track_function(request): ...@@ -32,47 +32,6 @@ def make_track_function(request):
return track.views.server_track(request, event_type, event, page='x_module') return track.views.server_track(request, event_type, event, page='x_module')
return f return f
def modx_dispatch(request, module=None, dispatch=None, id=None):
''' Generic view for extensions. '''
if not request.user.is_authenticated():
return redirect('/')
# Grab the student information for the module from the database
s = StudentModule.objects.filter(student=request.user,
module_id=id)
#s = StudentModule.get_with_caching(request.user, id)
if len(s) == 0 or s is None:
log.debug("Couldnt find module for user and id " + str(module) + " " + str(request.user) + " "+ str(id))
raise Http404
s = s[0]
oldgrade = s.grade
oldstate = s.state
dispatch=dispatch.split('?')[0]
ajax_url = '/modx/'+module+'/'+id+'/'
# Grab the XML corresponding to the request from course.xml
xml = content_parser.module_xml(request.user, module, 'id', id)
# Create the module
instance=courseware.modules.get_module_class(module)(xml,
id,
ajax_url=ajax_url,
state=oldstate,
track_function = make_track_function(request),
render_function = None)
# Let the module handle the AJAX
ajax_return=instance.handle_ajax(dispatch, request.POST)
# Save the state back to the database
s.state=instance.get_state()
if instance.get_score():
s.grade=instance.get_score()['score']
if s.grade != oldgrade or s.state != oldstate:
s.save()
# Return whatever the module wanted to return to the client/caller
return HttpResponse(ajax_return)
def grade_histogram(module_id): def grade_histogram(module_id):
''' Print out a histogram of grades on a given problem. ''' Print out a histogram of grades on a given problem.
...@@ -115,8 +74,9 @@ def render_x_module(user, request, xml_module, module_object_preload): ...@@ -115,8 +74,9 @@ def render_x_module(user, request, xml_module, module_object_preload):
track_function = make_track_function(request), track_function = make_track_function(request),
render_function = lambda x: render_module(user, request, x, 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 instance wasn't already in the database, and this
if not smod: # isn't a guest user, create it
if not smod and user.is_authenticated():
smod=StudentModule(student=user, smod=StudentModule(student=user,
module_type = module_type, module_type = module_type,
module_id=module_id, module_id=module_id,
......
...@@ -316,21 +316,19 @@ class Module(XModule): ...@@ -316,21 +316,19 @@ class Module(XModule):
self.attempts = self.attempts + 1 self.attempts = self.attempts + 1
self.lcp.done=True self.lcp.done=True
success = 'correct' success = 'correct'
for i in correct_map: for i in correct_map:
if correct_map[i]!='correct': if correct_map[i]!='correct':
success = 'incorrect' success = 'incorrect'
js=json.dumps({'correct_map' : correct_map,
'success' : success})
event_info['correct_map']=correct_map event_info['correct_map']=correct_map
event_info['success']=success event_info['success']=success
self.tracker('save_problem_check', event_info) self.tracker('save_problem_check', event_info)
return js return json.dumps({'success': success,
'contents': self.get_problem_html(encapsulate=False)})
def save_problem(self, get): def save_problem(self, get):
event_info = dict() event_info = dict()
......
...@@ -4,7 +4,8 @@ import urllib ...@@ -4,7 +4,8 @@ import urllib
from django.conf import settings from django.conf import settings
from django.core.context_processors import csrf from django.core.context_processors import csrf
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.http import HttpResponse, Http404 from django.contrib.auth.decorators import login_required
from django.http import Http404, HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from mitxmako.shortcuts import render_to_response, render_to_string from mitxmako.shortcuts import render_to_response, render_to_string
#from django.views.decorators.csrf import ensure_csrf_cookie #from django.views.decorators.csrf import ensure_csrf_cookie
...@@ -12,12 +13,12 @@ from django.views.decorators.cache import cache_control ...@@ -12,12 +13,12 @@ from django.views.decorators.cache import cache_control
from lxml import etree from lxml import etree
from module_render import render_module, modx_dispatch from module_render import render_module, make_track_function
from models import StudentModule from models import StudentModule
from student.models import UserProfile from student.models import UserProfile
import courseware.content_parser as content_parser import courseware.content_parser as content_parser
import courseware.modules.capa_module import courseware.modules
import courseware.grades as grades import courseware.grades as grades
...@@ -42,12 +43,11 @@ def gradebook(request): ...@@ -42,12 +43,11 @@ def gradebook(request):
return render_to_response('gradebook.html',{'students':student_info}) return render_to_response('gradebook.html',{'students':student_info})
@login_required
@cache_control(no_cache=True, no_store=True, must_revalidate=True) @cache_control(no_cache=True, no_store=True, must_revalidate=True)
def profile(request, student_id = None): def profile(request, student_id = None):
''' User profile. Show username, location, etc, as well as grades . ''' User profile. Show username, location, etc, as well as grades .
We need to allow the user to change some of these settings .''' We need to allow the user to change some of these settings .'''
if not request.user.is_authenticated():
return redirect('/')
if student_id == None: if student_id == None:
student = request.user student = request.user
...@@ -96,7 +96,7 @@ def render_section(request, section): ...@@ -96,7 +96,7 @@ def render_section(request, section):
''' TODO: Consolidate with index ''' TODO: Consolidate with index
''' '''
user = request.user user = request.user
if not settings.COURSEWARE_ENABLED or not user.is_authenticated(): if not settings.COURSEWARE_ENABLED:
return redirect('/') return redirect('/')
# try: # try:
...@@ -108,8 +108,11 @@ def render_section(request, section): ...@@ -108,8 +108,11 @@ def render_section(request, section):
module_ids = dom.xpath("//@id") module_ids = dom.xpath("//@id")
module_object_preload = list(StudentModule.objects.filter(student=user, if user.is_authenticated():
module_id__in=module_ids)) module_object_preload = list(StudentModule.objects.filter(student=user,
module_id__in=module_ids))
else:
module_object_preload = []
module=render_module(user, request, dom, module_object_preload) module=render_module(user, request, dom, module_object_preload)
...@@ -130,7 +133,7 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti ...@@ -130,7 +133,7 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
''' Displays courseware accordion, and any associated content. ''' Displays courseware accordion, and any associated content.
''' '''
user = request.user user = request.user
if not settings.COURSEWARE_ENABLED or not user.is_authenticated(): if not settings.COURSEWARE_ENABLED:
return redirect('/') return redirect('/')
# Fixes URLs -- we don't get funny encoding characters from spaces # Fixes URLs -- we don't get funny encoding characters from spaces
...@@ -162,8 +165,11 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti ...@@ -162,8 +165,11 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
module_ids = dom.xpath("//course[@name=$course]/chapter[@name=$chapter]//section[@name=$section]//@id", module_ids = dom.xpath("//course[@name=$course]/chapter[@name=$chapter]//section[@name=$section]//@id",
course=course, chapter=chapter, section=section) course=course, chapter=chapter, section=section)
module_object_preload = list(StudentModule.objects.filter(student=user, if user.is_authenticated():
module_id__in=module_ids)) module_object_preload = list(StudentModule.objects.filter(student=user,
module_id__in=module_ids))
else:
module_object_preload = []
module=render_module(user, request, module, module_object_preload) module=render_module(user, request, module, module_object_preload)
...@@ -178,3 +184,49 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti ...@@ -178,3 +184,49 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
result = render_to_response('courseware.html', context) result = render_to_response('courseware.html', context)
return result return result
def modx_dispatch(request, module=None, dispatch=None, id=None):
''' Generic view for extensions. '''
# Grab the student information for the module from the database
if request.user.is_authenticated():
s = StudentModule.objects.filter(student=request.user,
module_id=id)
#s = StudentModule.get_with_caching(request.user, id)
if len(s) == 0 or s is None:
log.debug("Couldnt find module for user and id " + str(module) + " " + str(request.user) + " "+ str(id))
raise Http404
s = s[0]
oldgrade = s.grade
oldstate = s.state
else:
oldstate = "{}"
dispatch=dispatch.split('?')[0]
ajax_url = '/modx/'+module+'/'+id+'/'
# Grab the XML corresponding to the request from course.xml
xml = content_parser.module_xml(request.user, module, 'id', id)
# Create the module
instance=courseware.modules.get_module_class(module)(xml,
id,
ajax_url=ajax_url,
state=oldstate,
track_function = make_track_function(request),
render_function = None)
# Let the module handle the AJAX
ajax_return=instance.handle_ajax(dispatch, request.POST)
# Save the state back to the database
if request.user.is_authenticated():
s.state=instance.get_state()
if instance.get_score():
s.grade=instance.get_score()['score']
if s.grade != oldgrade or s.state != oldstate:
s.save()
# Return whatever the module wanted to return to the client/caller
return HttpResponse(ajax_return)
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import types from django.conf import settings as dj_settings
from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.context_processors import csrf from django.core.context_processors import csrf
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
...@@ -11,13 +9,10 @@ from django.utils import simplejson ...@@ -11,13 +9,10 @@ from django.utils import simplejson
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from mitxmako.shortcuts import render_to_response from mitxmako.shortcuts import render_to_response
from models import * # TODO: Clean up from models import Revision, Article, CreateArticleForm, RevisionFormWithTitle, RevisionForm
from settings import * import settings
def view(request, wiki_url): def view(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url) (article, path, err) = fetch_from_url(request, wiki_url)
if err: if err:
return err return err
...@@ -36,9 +31,6 @@ def view(request, wiki_url): ...@@ -36,9 +31,6 @@ def view(request, wiki_url):
return render_to_response('simplewiki_view.html', d) return render_to_response('simplewiki_view.html', d)
def view_revision(request, revision_number, wiki_url, revision=None): def view_revision(request, revision_number, wiki_url, revision=None):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url) (article, path, err) = fetch_from_url(request, wiki_url)
if err: if err:
return err return err
...@@ -67,8 +59,6 @@ def view_revision(request, revision_number, wiki_url, revision=None): ...@@ -67,8 +59,6 @@ def view_revision(request, revision_number, wiki_url, revision=None):
def root_redirect(request): def root_redirect(request):
if not request.user.is_authenticated():
return redirect('/')
try: try:
root = Article.get_root() root = Article.get_root()
except: except:
...@@ -78,8 +68,6 @@ def root_redirect(request): ...@@ -78,8 +68,6 @@ def root_redirect(request):
return HttpResponseRedirect(reverse('wiki_view', args=(root.get_url()))) return HttpResponseRedirect(reverse('wiki_view', args=(root.get_url())))
def create(request, wiki_url): def create(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
url_path = get_url_path(wiki_url) url_path = get_url_path(wiki_url)
...@@ -152,9 +140,6 @@ def create(request, wiki_url): ...@@ -152,9 +140,6 @@ def create(request, wiki_url):
return render_to_response('simplewiki_edit.html', d) return render_to_response('simplewiki_edit.html', d)
def edit(request, wiki_url): def edit(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url) (article, path, err) = fetch_from_url(request, wiki_url)
if err: if err:
return err return err
...@@ -164,7 +149,7 @@ def edit(request, wiki_url): ...@@ -164,7 +149,7 @@ def edit(request, wiki_url):
if perm_err: if perm_err:
return perm_err return perm_err
if WIKI_ALLOW_TITLE_EDIT: if settings.WIKI_ALLOW_TITLE_EDIT:
EditForm = RevisionFormWithTitle EditForm = RevisionFormWithTitle
else: else:
EditForm = RevisionForm EditForm = RevisionForm
...@@ -186,7 +171,7 @@ def edit(request, wiki_url): ...@@ -186,7 +171,7 @@ def edit(request, wiki_url):
if not request.user.is_anonymous(): if not request.user.is_anonymous():
new_revision.revision_user = request.user new_revision.revision_user = request.user
new_revision.save() new_revision.save()
if WIKI_ALLOW_TITLE_EDIT: if settings.WIKI_ALLOW_TITLE_EDIT:
new_revision.article.title = f.cleaned_data['title'] new_revision.article.title = f.cleaned_data['title']
new_revision.article.save() new_revision.article.save()
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),)))
...@@ -206,9 +191,6 @@ def edit(request, wiki_url): ...@@ -206,9 +191,6 @@ def edit(request, wiki_url):
return render_to_response('simplewiki_edit.html', d) return render_to_response('simplewiki_edit.html', d)
def history(request, wiki_url, page=1): def history(request, wiki_url, page=1):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url) (article, path, err) = fetch_from_url(request, wiki_url)
if err: if err:
return err return err
...@@ -293,9 +275,6 @@ def history(request, wiki_url, page=1): ...@@ -293,9 +275,6 @@ def history(request, wiki_url, page=1):
def revision_feed(request, page=1): def revision_feed(request, page=1):
if not request.user.is_superuser:
return redirect('/')
page_size = 10 page_size = 10
try: try:
...@@ -323,8 +302,6 @@ def revision_feed(request, page=1): ...@@ -323,8 +302,6 @@ def revision_feed(request, page=1):
return render_to_response('simplewiki_revision_feed.html', d) return render_to_response('simplewiki_revision_feed.html', d)
def search_articles(request): def search_articles(request):
if not request.user.is_authenticated():
return redirect('/')
# blampe: We should check for the presence of other popular django search # blampe: We should check for the presence of other popular django search
# apps and use those if possible. Only fall back on this as a last resort. # apps and use those if possible. Only fall back on this as a last resort.
# Adding some context to results (eg where matches were) would also be nice. # Adding some context to results (eg where matches were) would also be nice.
...@@ -371,9 +348,6 @@ def search_articles(request): ...@@ -371,9 +348,6 @@ def search_articles(request):
def search_add_related(request, wiki_url): def search_add_related(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url) (article, path, err) = fetch_from_url(request, wiki_url)
if err: if err:
return err return err
...@@ -426,9 +400,6 @@ def add_related(request, wiki_url): ...@@ -426,9 +400,6 @@ def add_related(request, wiki_url):
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),)))
def remove_related(request, wiki_url, related_id): def remove_related(request, wiki_url, related_id):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url) (article, path, err) = fetch_from_url(request, wiki_url)
if err: if err:
return err return err
...@@ -448,8 +419,6 @@ def remove_related(request, wiki_url, related_id): ...@@ -448,8 +419,6 @@ def remove_related(request, wiki_url, related_id):
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),))) return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),)))
def random_article(request): def random_article(request):
if not request.user.is_authenticated():
return redirect('/')
from random import randint from random import randint
num_arts = Article.objects.count() num_arts = Article.objects.count()
article = Article.objects.all()[randint(0, num_arts-1)] article = Article.objects.all()[randint(0, num_arts-1)]
...@@ -461,8 +430,6 @@ def encode_err(request, url): ...@@ -461,8 +430,6 @@ def encode_err(request, url):
return render_to_response('simplewiki_error.html', d) return render_to_response('simplewiki_error.html', d)
def not_found(request, wiki_url): def not_found(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
"""Generate a NOT FOUND message for some URL""" """Generate a NOT FOUND message for some URL"""
d = {'wiki_err_notfound': True, d = {'wiki_err_notfound': True,
'wiki_url': wiki_url} 'wiki_url': wiki_url}
...@@ -534,17 +501,22 @@ def check_permissions(request, article, check_read=False, check_write=False, che ...@@ -534,17 +501,22 @@ def check_permissions(request, article, check_read=False, check_write=False, che
# LOGIN PROTECTION # # LOGIN PROTECTION #
#################### ####################
if WIKI_REQUIRE_LOGIN_VIEW: if settings.WIKI_REQUIRE_LOGIN_VIEW:
view = login_required(view) view = login_required(view)
history = login_required(history) history = login_required(history)
# search_related = login_required(search_related) search_articles = login_required(search_articles)
# wiki_encode_err = login_required(wiki_encode_err) root_redirect = login_required(root_redirect)
revision_feed = login_required(revision_feed)
if WIKI_REQUIRE_LOGIN_EDIT: random_article = login_required(random_article)
search_add_related = login_required(search_add_related)
not_found = login_required(not_found)
view_revision = login_required(view_revision)
if settings.WIKI_REQUIRE_LOGIN_EDIT:
create = login_required(create) create = login_required(create)
edit = login_required(edit) edit = login_required(edit)
add_related = login_required(add_related) add_related = login_required(add_related)
remove_related = login_required(remove_related) remove_related = login_required(remove_related)
if WIKI_CONTEXT_PREPROCESSORS: if settings.WIKI_CONTEXT_PREPROCESSORS:
settings.TEMPLATE_CONTEXT_PROCESSORS = settings.TEMPLATE_CONTEXT_PROCESSORS + WIKI_CONTEXT_PREPROCESSORS dj_settings.TEMPLATE_CONTEXT_PROCESSORS += settings.WIKI_CONTEXT_PREPROCESSORS
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from mitxmako.shortcuts import render_to_response from mitxmako.shortcuts import render_to_response
@login_required
def index(request, page=0): def index(request, page=0):
if not request.user.is_authenticated():
return redirect('/')
return render_to_response('staticbook.html',{'page':int(page)}) return render_to_response('staticbook.html',{'page':int(page)})
def index_shifted(request, page): def index_shifted(request, page):
......
...@@ -92,12 +92,11 @@ def logout_user(request): ...@@ -92,12 +92,11 @@ def logout_user(request):
logout(request) logout(request)
return redirect('/') return redirect('/')
@login_required
@ensure_csrf_cookie @ensure_csrf_cookie
def change_setting(request): def change_setting(request):
''' JSON call to change a profile setting: Right now, location and language ''' JSON call to change a profile setting: Right now, location and language
''' '''
if not request.user.is_authenticated():
return redirect('/')
up = UserProfile.objects.get(user=request.user) #request.user.profile_cache up = UserProfile.objects.get(user=request.user) #request.user.profile_cache
if 'location' in request.POST: if 'location' in request.POST:
up.location=request.POST['location'] up.location=request.POST['location']
......
...@@ -180,8 +180,8 @@ CELERY_ALWAYS_EAGER = True ...@@ -180,8 +180,8 @@ CELERY_ALWAYS_EAGER = True
djcelery.setup_loader() djcelery.setup_loader()
################################# SIMPLEWIKI ################################### ################################# SIMPLEWIKI ###################################
WIKI_REQUIRE_LOGIN_EDIT = True SIMPLE_WIKI_REQUIRE_LOGIN_EDIT = True
WIKI_REQUIRE_LOGIN_VIEW = True SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False
################################# Middleware ################################### ################################# Middleware ###################################
# List of finder classes that know how to find static files in # List of finder classes that know how to find static files in
......
...@@ -60,7 +60,4 @@ def send_feedback(request): ...@@ -60,7 +60,4 @@ def send_feedback(request):
def info(request): def info(request):
''' Info page (link from main header) ''' ''' Info page (link from main header) '''
if not request.user.is_authenticated():
return redirect('/')
return render_to_response("info.html", {}) return render_to_response("info.html", {})
...@@ -39,8 +39,8 @@ DEFAULT_FEEDBACK_EMAIL = 'feedback@mitx.mit.edu' ...@@ -39,8 +39,8 @@ DEFAULT_FEEDBACK_EMAIL = 'feedback@mitx.mit.edu'
GENERATE_RANDOM_USER_CREDENTIALS = False GENERATE_RANDOM_USER_CREDENTIALS = False
WIKI_REQUIRE_LOGIN_EDIT = True SIMPLE_WIKI_REQUIRE_LOGIN_EDIT = True
WIKI_REQUIRE_LOGIN_VIEW = True SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False
PERFSTATS = False PERFSTATS = False
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<section> <section>
<h1>Circuits &amp; Electronics</h1> <h1>Circuits &amp; Electronics</h1>
<h2>6.002x</h2> <h2>6.002x</h2>
<a class="enroll" rel="leanModal" href="#enroll"><noscript>In order to</noscript> Enroll in 6.002x Circuits <span>&amp;</span> Electronics <noscript>you need to have javascript enabled</noscript></a> <a class="enroll" rel="leanModal" href="/info">View 6.002x Circuits <span>&amp;</span> Electronics as a guest</a>
</section> </section>
<p>6.002x (Circuits and Electronics) is an experimental on-line adaptation of MIT&rsquo;s first undergraduate analog design course: 6.002. This course will run, free of charge, for students worldwide from March 5, 2012 through June 8, 2012.</p> <p>6.002x (Circuits and Electronics) is an experimental on-line adaptation of MIT&rsquo;s first undergraduate analog design course: 6.002. This course will run, free of charge, for students worldwide from March 5, 2012 through June 8, 2012.</p>
</section> </section>
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
</section> </section>
<section class="cta"> <section class="cta">
<a class="enroll" rel="leanModal" href="#enroll"><noscript>In order to</noscript> Enroll in 6.002x Circuits &amp; Electronics <noscript>you need to have javascript enabled</noscript></a> <a class="enroll" rel="leanModal" href="/info">View 6.002x Circuits &amp; Electronics as a guest</a>
</section> </section>
</section> </section>
......
...@@ -23,11 +23,17 @@ $(document).ready(function(){ ...@@ -23,11 +23,17 @@ $(document).ready(function(){
<section class="main-content"> <section class="main-content">
<div class="info-wrapper"> <div class="info-wrapper">
% if user.is_authenticated():
<section class="updates"> <section class="updates">
<%include file="updates.html" /> <%include file="updates.html" />
</section> </section>
<section class="handouts"> <section class="handouts">
<%include file="handouts.html" /> <%include file="handouts.html" />
</section> </section>
% else:
<section class="updates">
<%include file="guest_updates.html" />
</section>
% endif
</div> </div>
</section> </section>
...@@ -85,7 +85,9 @@ ...@@ -85,7 +85,9 @@
</div> </div>
</li> </li>
<li><a href="/s/help.html">Help</a></li> <li><a href="/s/help.html">Help</a></li>
% if user.is_authenticated():
<li><a href="/logout">Log out</a></li> <li><a href="/logout">Log out</a></li>
% endif
</ul> </ul>
</nav> </nav>
</footer> </footer>
......
...@@ -10,10 +10,14 @@ ...@@ -10,10 +10,14 @@
<ul class="coursenav"> <ul class="coursenav">
<li class="courseware"><a href="/courseware">Courseware</a></li> <li class="courseware"><a href="/courseware">Courseware</a></li>
<li class="info"><a href="/info">Course Info</a></li> <li class="info"><a href="/info">Course Info</a></li>
% if user.is_authenticated():
<li class="book"><a href="/book">Textbook</a></li> <li class="book"><a href="/book">Textbook</a></li>
<li class="discussion"><a href="/discussion/questions">Discussion</a></li> <li class="discussion"><a href="/discussion/questions">Discussion</a></li>
% endif
<li class="wiki"><a href="/wiki/view">Wiki</a></li> <li class="wiki"><a href="/wiki/view">Wiki</a></li>
% if user.is_authenticated():
<li class="profile"><a href="/profile">Profile</a></li> <li class="profile"><a href="/profile">Profile</a></li>
% endif
</ul> </ul>
</nav> </nav>
</header> </header>
......
function ${ id }_load() { function ${ id }_content_updated() {
$('#main_${ id }').load('${ ajax_url }problem_get?id=${ id }',
function() {
MathJax.Hub.Queue(["Typeset",MathJax.Hub]); MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
update_schematics(); update_schematics();
$('#check_${ id }').click(function() { $('#check_${ id }').unbind('click').click(function() {
$("input.schematic").each(function(index,element){ element.schematic.update_value(); }); $("input.schematic").each(function(index,element){ element.schematic.update_value(); });
var submit_data={}; var submit_data={};
$.each($("[id^=input_${ id }_]"), function(index,value){ $.each($("[id^=input_${ id }_]"), function(index,value){
submit_data[value.id]=value.value; submit_data[value.id]=value.value;
}); });
postJSON('/modx/problem/${ id }/problem_check', postJSON('/modx/problem/${ id }/problem_check',
submit_data, submit_data,
function(json) { function(json) {
switch(json.success) { switch(json.success) {
case 'incorrect': // Worked, but answer not case 'incorrect': // Worked, but answer not
case 'correct': case 'correct':
${ id }_load(); $('#main_${ id }').html(json.contents);
//alert("!!"+json.success); ${ id }_content_updated();
break; break;
default: default:
alert(json.success); alert(json.success);
} }}
}); );
log_event('problem_check', submit_data); log_event('problem_check', submit_data);
}); });
$('#reset_${ id }').click(function() { $('#reset_${ id }').unbind('click').click(function() {
var submit_data={}; var submit_data={};
$.each($("[id^=input_${ id }_]"), function(index,value){ $.each($("[id^=input_${ id }_]"), function(index,value){
submit_data[value.id]=value.value; submit_data[value.id]=value.value;
}); });
postJSON('/modx/problem/${ id }/problem_reset', {'id':'${ id }'}, function(json) { postJSON('/modx/problem/${ id }/problem_reset', {'id':'${ id }'}, function(html_as_json) {
${ id }_load(); $('#main_${ id }').html(html_as_json);
${ id }_content_updated();
}); });
log_event('problem_reset', submit_data); log_event('problem_reset', submit_data);
}); });
$('#show_${ id }').click(function() { $('#show_${ id }').unbind('click').click(function() {
postJSON('/modx/problem/${ id }/problem_show', {}, function(data) { postJSON('/modx/problem/${ id }/problem_show', {}, function(data) {
for (var key in data) { for (var key in data) {
$("#answer_"+key).text(data[key]); $("#answer_"+key).text(data[key]);
} }
}); });
log_event('problem_show', {'problem':'${ id }'}); log_event('problem_show', {'problem':'${ id }'});
}); });
$('#save_${ id }').click(function() { $('#save_${ id }').unbind('click').click(function() {
$("input.schematic").each(function(index,element){ element.schematic.update_value(); }); $("input.schematic").each(function(index,element){ element.schematic.update_value(); });
var submit_data={}; var submit_data={};
$.each($("[id^=input_${ id }_]"), function(index,value){ $.each($("[id^=input_${ id }_]"), function(index,value) {
submit_data[value.id]=value.value;}); submit_data[value.id]=value.value;
});
postJSON('/modx/problem/${ id }/problem_save', postJSON('/modx/problem/${ id }/problem_save',
submit_data, function(data){ submit_data,
if(data.success) { function(data) {
alert('Saved'); if(data.success) {
}} alert('Saved');
); }});
log_event('problem_save', submit_data); log_event('problem_save', submit_data);
}); });
} }
);}
function ${ id }_load() {
$('#main_${ id }').load('${ ajax_url }problem_get?id=${ id }', ${ id }_content_updated);
}
$(function() { $(function() {
${ id }_load(); ${ id }_load();
......
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