Merge branch 'master' into feature/server_split

Conflicts:
	lms/urls.py
This commit is contained in:
David Ormsbee
2012-08-13 09:21:02 -04:00
16 changed files with 258 additions and 75 deletions

View File

@@ -1,10 +1,9 @@
from staticfiles.storage import staticfiles_storage
from mitxmako.shortcuts import render_to_string
from pipeline.conf import settings
from pipeline.packager import Packager
from pipeline.utils import guess_type
from static_replace import try_staticfiles_lookup
def compressed_css(package_name):
@@ -25,9 +24,11 @@ def compressed_css(package_name):
def render_css(package, path):
template_name = package.template_name or "mako/css.html"
context = package.extra_context
url = try_staticfiles_lookup(path)
context.update({
'type': guess_type(path, 'text/css'),
'url': staticfiles_storage.url(path)
'url': url,
})
return render_to_string(template_name, context)
@@ -58,7 +59,7 @@ def render_js(package, path):
context = package.extra_context
context.update({
'type': guess_type(path, 'text/javascript'),
'url': staticfiles_storage.url(path)
'url': try_staticfiles_lookup(path)
})
return render_to_string(template_name, context)

View File

@@ -1,7 +1,25 @@
import logging
import re
from staticfiles.storage import staticfiles_storage
from staticfiles import finders
from django.conf import settings
import re
log = logging.getLogger(__name__)
def try_staticfiles_lookup(path):
"""
Try to lookup a path in staticfiles_storage. If it fails, return
a dead link instead of raising an exception.
"""
try:
url = staticfiles_storage.url(path)
except Exception as err:
log.warning("staticfiles_storage couldn't find path {}: {}".format(
path, str(err)))
# Just return a dead link--don't kill everything.
url = "file_not_found"
return url
def replace(static_url, prefix=None):
@@ -22,7 +40,8 @@ def replace(static_url, prefix=None):
if servable:
return static_url.group(0)
else:
url = staticfiles_storage.url(prefix + static_url.group('rest'))
# don't error if file can't be found
url = try_staticfiles_lookup(prefix + static_url.group('rest'))
return "".join([quote, url, quote])

View File

@@ -128,7 +128,7 @@ def dashboard(request):
try:
courses.append(course_from_id(enrollment.course_id))
except ItemNotFoundError:
log.error("User {0} enrolled in non-existant course {1}"
log.error("User {0} enrolled in non-existent course {1}"
.format(user.username, enrollment.course_id))
message = ""
@@ -182,7 +182,7 @@ def change_enrollment(request):
try:
course = course_from_id(course_id)
except ItemNotFoundError:
log.error("User {0} tried to enroll in non-existant course {1}"
log.warning("User {0} tried to enroll in non-existant course {1}"
.format(user.username, enrollment.course_id))
return {'success': False, 'error': 'The course requested does not exist.'}