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):
return
def user_groups(user):
if not user.is_authenticated():
return []
# TODO: Rewrite in Django
key = 'user_group_names_{user.id}'.format(user=user)
cache_expiration = 60 * 60 # one hour
......@@ -171,12 +174,13 @@ def course_xml_process(tree):
def course_file(user):
''' 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
groups = user_groups(user)
if user.is_authenticated():
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,
'groups' : groups}
......
......@@ -32,47 +32,6 @@ def make_track_function(request):
return track.views.server_track(request, event_type, event, page='x_module')
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):
''' 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):
track_function = make_track_function(request),
render_function = lambda x: render_module(user, request, x, module_object_preload))
# If instance wasn't already in the database, create it
if not smod:
# If instance wasn't already in the database, and this
# isn't a guest user, create it
if not smod and user.is_authenticated():
smod=StudentModule(student=user,
module_type = module_type,
module_id=module_id,
......
......@@ -316,21 +316,19 @@ class Module(XModule):
self.attempts = self.attempts + 1
self.lcp.done=True
success = 'correct'
for i in correct_map:
if correct_map[i]!='correct':
success = 'incorrect'
js=json.dumps({'correct_map' : correct_map,
'success' : success})
event_info['correct_map']=correct_map
event_info['success']=success
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):
event_info = dict()
......
......@@ -4,7 +4,8 @@ import urllib
from django.conf import settings
from django.core.context_processors import csrf
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 mitxmako.shortcuts import render_to_response, render_to_string
#from django.views.decorators.csrf import ensure_csrf_cookie
......@@ -12,12 +13,12 @@ from django.views.decorators.cache import cache_control
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 student.models import UserProfile
import courseware.content_parser as content_parser
import courseware.modules.capa_module
import courseware.modules
import courseware.grades as grades
......@@ -42,12 +43,11 @@ def gradebook(request):
return render_to_response('gradebook.html',{'students':student_info})
@login_required
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
def profile(request, student_id = None):
''' User profile. Show username, location, etc, as well as grades .
We need to allow the user to change some of these settings .'''
if not request.user.is_authenticated():
return redirect('/')
if student_id == None:
student = request.user
......@@ -96,7 +96,7 @@ def render_section(request, section):
''' TODO: Consolidate with index
'''
user = request.user
if not settings.COURSEWARE_ENABLED or not user.is_authenticated():
if not settings.COURSEWARE_ENABLED:
return redirect('/')
# try:
......@@ -108,8 +108,11 @@ def render_section(request, section):
module_ids = dom.xpath("//@id")
module_object_preload = list(StudentModule.objects.filter(student=user,
module_id__in=module_ids))
if user.is_authenticated():
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)
......@@ -130,7 +133,7 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
''' Displays courseware accordion, and any associated content.
'''
user = request.user
if not settings.COURSEWARE_ENABLED or not user.is_authenticated():
if not settings.COURSEWARE_ENABLED:
return redirect('/')
# 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
module_ids = dom.xpath("//course[@name=$course]/chapter[@name=$chapter]//section[@name=$section]//@id",
course=course, chapter=chapter, section=section)
module_object_preload = list(StudentModule.objects.filter(student=user,
module_id__in=module_ids))
if user.is_authenticated():
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)
......@@ -178,3 +184,49 @@ def index(request, course="6.002 Spring 2012", chapter="Using the System", secti
result = render_to_response('courseware.html', context)
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 -*-
import types
from django.conf import settings
from django.conf import settings as dj_settings
from django.contrib.auth.decorators import login_required
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
......@@ -11,13 +9,10 @@ from django.utils import simplejson
from django.utils.translation import ugettext_lazy as _
from mitxmako.shortcuts import render_to_response
from models import * # TODO: Clean up
from settings import *
from models import Revision, Article, CreateArticleForm, RevisionFormWithTitle, RevisionForm
import settings
def view(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url)
if err:
return err
......@@ -36,9 +31,6 @@ def view(request, wiki_url):
return render_to_response('simplewiki_view.html', d)
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)
if err:
return err
......@@ -67,8 +59,6 @@ def view_revision(request, revision_number, wiki_url, revision=None):
def root_redirect(request):
if not request.user.is_authenticated():
return redirect('/')
try:
root = Article.get_root()
except:
......@@ -78,8 +68,6 @@ def root_redirect(request):
return HttpResponseRedirect(reverse('wiki_view', args=(root.get_url())))
def create(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
url_path = get_url_path(wiki_url)
......@@ -152,9 +140,6 @@ def create(request, wiki_url):
return render_to_response('simplewiki_edit.html', d)
def edit(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url)
if err:
return err
......@@ -164,7 +149,7 @@ def edit(request, wiki_url):
if perm_err:
return perm_err
if WIKI_ALLOW_TITLE_EDIT:
if settings.WIKI_ALLOW_TITLE_EDIT:
EditForm = RevisionFormWithTitle
else:
EditForm = RevisionForm
......@@ -186,7 +171,7 @@ def edit(request, wiki_url):
if not request.user.is_anonymous():
new_revision.revision_user = request.user
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.save()
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),)))
......@@ -206,9 +191,6 @@ def edit(request, wiki_url):
return render_to_response('simplewiki_edit.html', d)
def history(request, wiki_url, page=1):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url)
if err:
return err
......@@ -293,9 +275,6 @@ def history(request, wiki_url, page=1):
def revision_feed(request, page=1):
if not request.user.is_superuser:
return redirect('/')
page_size = 10
try:
......@@ -323,8 +302,6 @@ def revision_feed(request, page=1):
return render_to_response('simplewiki_revision_feed.html', d)
def search_articles(request):
if not request.user.is_authenticated():
return redirect('/')
# 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.
# Adding some context to results (eg where matches were) would also be nice.
......@@ -371,9 +348,6 @@ def search_articles(request):
def search_add_related(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
(article, path, err) = fetch_from_url(request, wiki_url)
if err:
return err
......@@ -426,9 +400,6 @@ def add_related(request, wiki_url):
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),)))
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)
if err:
return err
......@@ -448,8 +419,6 @@ def remove_related(request, wiki_url, related_id):
return HttpResponseRedirect(reverse('wiki_view', args=(article.get_url(),)))
def random_article(request):
if not request.user.is_authenticated():
return redirect('/')
from random import randint
num_arts = Article.objects.count()
article = Article.objects.all()[randint(0, num_arts-1)]
......@@ -461,8 +430,6 @@ def encode_err(request, url):
return render_to_response('simplewiki_error.html', d)
def not_found(request, wiki_url):
if not request.user.is_authenticated():
return redirect('/')
"""Generate a NOT FOUND message for some URL"""
d = {'wiki_err_notfound': True,
'wiki_url': wiki_url}
......@@ -534,17 +501,22 @@ def check_permissions(request, article, check_read=False, check_write=False, che
# LOGIN PROTECTION #
####################
if WIKI_REQUIRE_LOGIN_VIEW:
view = login_required(view)
history = login_required(history)
# search_related = login_required(search_related)
# wiki_encode_err = login_required(wiki_encode_err)
if WIKI_REQUIRE_LOGIN_EDIT:
if settings.WIKI_REQUIRE_LOGIN_VIEW:
view = login_required(view)
history = login_required(history)
search_articles = login_required(search_articles)
root_redirect = login_required(root_redirect)
revision_feed = login_required(revision_feed)
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)
edit = login_required(edit)
add_related = login_required(add_related)
remove_related = login_required(remove_related)
if WIKI_CONTEXT_PREPROCESSORS:
settings.TEMPLATE_CONTEXT_PROCESSORS = settings.TEMPLATE_CONTEXT_PROCESSORS + WIKI_CONTEXT_PREPROCESSORS
if settings.WIKI_CONTEXT_PREPROCESSORS:
dj_settings.TEMPLATE_CONTEXT_PROCESSORS += settings.WIKI_CONTEXT_PREPROCESSORS
from django.contrib.auth.decorators import login_required
from mitxmako.shortcuts import render_to_response
@login_required
def index(request, page=0):
if not request.user.is_authenticated():
return redirect('/')
return render_to_response('staticbook.html',{'page':int(page)})
def index_shifted(request, page):
......
......@@ -92,12 +92,11 @@ def logout_user(request):
logout(request)
return redirect('/')
@login_required
@ensure_csrf_cookie
def change_setting(request):
''' 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
if 'location' in request.POST:
up.location=request.POST['location']
......
......@@ -180,8 +180,8 @@ CELERY_ALWAYS_EAGER = True
djcelery.setup_loader()
################################# SIMPLEWIKI ###################################
WIKI_REQUIRE_LOGIN_EDIT = True
WIKI_REQUIRE_LOGIN_VIEW = True
SIMPLE_WIKI_REQUIRE_LOGIN_EDIT = True
SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False
################################# Middleware ###################################
# List of finder classes that know how to find static files in
......
......@@ -60,7 +60,4 @@ def send_feedback(request):
def info(request):
''' Info page (link from main header) '''
if not request.user.is_authenticated():
return redirect('/')
return render_to_response("info.html", {})
......@@ -39,8 +39,8 @@ DEFAULT_FEEDBACK_EMAIL = 'feedback@mitx.mit.edu'
GENERATE_RANDOM_USER_CREDENTIALS = False
WIKI_REQUIRE_LOGIN_EDIT = True
WIKI_REQUIRE_LOGIN_VIEW = True
SIMPLE_WIKI_REQUIRE_LOGIN_EDIT = True
SIMPLE_WIKI_REQUIRE_LOGIN_VIEW = False
PERFSTATS = False
......
......@@ -9,7 +9,7 @@
<section>
<h1>Circuits &amp; Electronics</h1>
<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>
<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>
......@@ -51,7 +51,7 @@
</section>
<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>
......
......@@ -23,11 +23,17 @@ $(document).ready(function(){
<section class="main-content">
<div class="info-wrapper">
% if user.is_authenticated():
<section class="updates">
<%include file="updates.html" />
</section>
<section class="handouts">
<%include file="handouts.html" />
</section>
% else:
<section class="updates">
<%include file="guest_updates.html" />
</section>
% endif
</div>
</section>
......@@ -85,7 +85,9 @@
</div>
</li>
<li><a href="/s/help.html">Help</a></li>
% if user.is_authenticated():
<li><a href="/logout">Log out</a></li>
% endif
</ul>
</nav>
</footer>
......
......@@ -10,10 +10,14 @@
<ul class="coursenav">
<li class="courseware"><a href="/courseware">Courseware</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="discussion"><a href="/discussion/questions">Discussion</a></li>
% endif
<li class="wiki"><a href="/wiki/view">Wiki</a></li>
% if user.is_authenticated():
<li class="profile"><a href="/profile">Profile</a></li>
% endif
</ul>
</nav>
</header>
......
function ${ id }_load() {
$('#main_${ id }').load('${ ajax_url }problem_get?id=${ id }',
function() {
function ${ id }_content_updated() {
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
update_schematics();
$('#check_${ id }').click(function() {
$("input.schematic").each(function(index,element){ element.schematic.update_value(); });
$('#check_${ id }').unbind('click').click(function() {
$("input.schematic").each(function(index,element){ element.schematic.update_value(); });
var submit_data={};
$.each($("[id^=input_${ id }_]"), function(index,value){
submit_data[value.id]=value.value;
});
postJSON('/modx/problem/${ id }/problem_check',
submit_data,
function(json) {
switch(json.success) {
case 'incorrect': // Worked, but answer not
case 'correct':
${ id }_load();
//alert("!!"+json.success);
submit_data,
function(json) {
switch(json.success) {
case 'incorrect': // Worked, but answer not
case 'correct':
$('#main_${ id }').html(json.contents);
${ id }_content_updated();
break;
default:
alert(json.success);
}
});
default:
alert(json.success);
}}
);
log_event('problem_check', submit_data);
});
$('#reset_${ id }').click(function() {
$('#reset_${ id }').unbind('click').click(function() {
var submit_data={};
$.each($("[id^=input_${ id }_]"), function(index,value){
submit_data[value.id]=value.value;
});
postJSON('/modx/problem/${ id }/problem_reset', {'id':'${ id }'}, function(json) {
${ id }_load();
postJSON('/modx/problem/${ id }/problem_reset', {'id':'${ id }'}, function(html_as_json) {
$('#main_${ id }').html(html_as_json);
${ id }_content_updated();
});
log_event('problem_reset', submit_data);
});
$('#show_${ id }').click(function() {
$('#show_${ id }').unbind('click').click(function() {
postJSON('/modx/problem/${ id }/problem_show', {}, function(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() {
$("input.schematic").each(function(index,element){ element.schematic.update_value(); });
var submit_data={};
$.each($("[id^=input_${ id }_]"), function(index,value){
submit_data[value.id]=value.value;});
$('#save_${ id }').unbind('click').click(function() {
$("input.schematic").each(function(index,element){ element.schematic.update_value(); });
var submit_data={};
$.each($("[id^=input_${ id }_]"), function(index,value) {
submit_data[value.id]=value.value;
});
postJSON('/modx/problem/${ id }/problem_save',
submit_data, function(data){
if(data.success) {
alert('Saved');
}}
);
submit_data,
function(data) {
if(data.success) {
alert('Saved');
}});
log_event('problem_save', submit_data);
});
}
);}
function ${ id }_load() {
$('#main_${ id }').load('${ ajax_url }problem_get?id=${ id }', ${ id }_content_updated);
}
$(function() {
${ 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