# define a @caching decorator to exploit the Django cache. Fixme, move
# this somewhere else.
from django.core.cache import cache
+import cPickle
def caching(prefix, timeout=60):
def g(func):
def f(*args):
- v = cache.get((prefix, args))
+ # wtf! Django encodes string-values as
+ # unicode-strings. That's bad, like stupid-bad! I'm
+ # putting explicit utf8-conversions here to make debugging
+ # easier if this code dies.
+ key = ','.join([prefix] + map(str, args))
+ v = cache.get(key)
if v:
- return v
+ return cPickle.loads(v.encode('utf-8'))
else:
v = func(*args)
if v:
- cache.set((prefix, args), v, timeout)
+ cache.set(key, unicode(cPickle.dumps(v), 'utf-8'), timeout)
return v
return f
return g
from conifer.libsystems.z3950.marcxml import marcxml_to_dictionary
-@caching('itemstatus', timeout=300)
+@caching('patroninfo', timeout=300)
@SIP
def patron_info(conn, barcode):
return conn.patron_info(barcode)
BASE_DIRECTORY = os.path.abspath(os.path.dirname(__file__))
HERE = lambda s: os.path.join(BASE_DIRECTORY, s)
-DEBUG = False
+DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
-ADMIN_MEDIA_PREFIX = '/media/'
+ADMIN_MEDIA_PREFIX = '/syrup/djmedia/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'j$dnxqbi3iih+(@il3m@vv(tuvt2+yu2r-$dxs$s7=iqjz_s!&'
AUTH_PROFILE_MODULE = 'syrup.UserProfile'
-AUTHENTICATION_BACKENDS = [
+AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
-]
+)
# more on this later.
except:
pass
-CACHE_BACKEND = 'locmem:///'
+#CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
+#CACHE_BACKEND = 'db://test_cache_table'
+#CACHE_BACKEND = 'locmem:///'
(r'^browse/(?P<browse_option>.*)/$', 'browse'),
(r'^prefs/$', 'user_prefs'),
(r'^z3950test/$', 'z3950_test'),
- (r'^graham_z3950test/$', 'graham_z3950_test'),
#MARK: propose we kill open_courses, we have browse.
(r'^opencourse/$', 'open_courses'),
(r'^search/$', 'search'),
from django.contrib.auth.models import User, SiteProfileNotAvailable
from django.core.paginator import Paginator
from django.db.models import Q
-from django.http import HttpResponse, HttpResponseRedirect
+from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound
from django.http import HttpResponseForbidden
from django.shortcuts import get_object_or_404
from django.utils import simplejson
def _access_denied(request, message):
if request.user.is_anonymous():
# then take them to login screen....
- dest = '/accounts/login/?next=' + request.environ['PATH_INFO']
+ dest = '/syrup/accounts/login/?next=' + request.environ['PATH_INFO']
return HttpResponseRedirect(dest)
else:
return simple_message(_('Access denied.'), message,
return g.render('phys/mark_arrived_outcome.xhtml')
-
-def custom_error_handler(request):
+def custom_500_handler(request):
cls, inst, tb = sys.exc_info()
- #fixme, set 50x code.
- return simple_message(_('Error: %s') % repr(inst),
- repr((request.__dict__, inst)))
+ msg = simple_message(_('Error: %s') % repr(inst),
+ repr((request.__dict__, inst)))
+ return HttpResponse(msg._container, status=501)
+
+def custom_400_handler(request):
+ msg = simple_message(_('Not found'),
+ _('The page you requested could not be found'))
+ return HttpResponse(msg._container, status=404)
<body>
<h1>${title}</h1>
<ul>
- <li><a href="/admin/">Django Administrative UI</a></li>
+ <li><a href="../djadmin/">Django Administrative UI</a></li>
</ul>
<ul>
<body>
<h1>${title}</h1>
(Note: some course materials may require you
- to <a href="/accounts/login/?next=/syrup/">log in</a>)
+ to <a href="/syrup/accounts/login/?next=/syrup/">log in</a>)
<h2>Choose from one of the options below:</h2>
<ul>
<li><a href="courses">Browse by Course Name</a></li>
<xi:include href="components/course.xhtml"/>
<head>
<title>${title}</title>
- <script type="text/javascript" src="/static/menublocks.js"/>
+ <script type="text/javascript" src="/syrup/static/menublocks.js"/>
</head>
<body>
${course_banner(course)}
<xi:include href="components/course.xhtml"/>
<head>
<title>${title}</title>
- <script type="text/javascript" src="/static/edit_course.js"/>
+ <script type="text/javascript" src="/syrup/static/edit_course.js"/>
</head>
<body>
<div py:if="instance.id">${course_banner(instance)}</div>
<xi:include href="components/course.xhtml"/>
<head>
<title>${title}</title>
- <script type="text/javascript" src="/static/edit_course_permissions.js"/>
+ <script type="text/javascript" src="/syrup/static/edit_course_permissions.js"/>
</head>
<body>
${course_banner(course)}
<xi:include href="../components/course.xhtml"/>
<head>
<title>${title}</title>
- <script type="text/javascript" src="/static/menublocks.js"/>
+ <script type="text/javascript" src="/syrup/static/menublocks.js"/>
</head>
<body>
${course_banner(course)}
<xi:include href="components/course.xhtml"/>
<head>
<title>${title}</title>
- <script type="text/javascript" src="/static/menublocks.js"/>
+ <script type="text/javascript" src="/syrup/static/menublocks.js"/>
</head>
<body>
${course_banner(course)}
<xi:include href="components/course.xhtml"/>
<head>
<title>${title}</title>
- <script type="text/javascript" src="/static/menublocks.js"/>
+ <script type="text/javascript" src="/syrup/static/menublocks.js"/>
</head>
<body>
${course_banner(course)}
<head py:attrs="select('@*')"
py:with="t=list(select('title/text()'))">
<title>${app_name}<py:if test="t">: ${t}</py:if></title>
- <link rel="stylesheet" type="text/css" href="/static/main.css"/>
- <script type="text/javascript" src="/static/jquery/js/jquery-1.3.2.min.js"/>
- <script type="text/javascript" src="/static/jquery/js/jquery-ui-1.7.1.custom.min.js"/>
- <script type="text/javascript" src="/static/jquery/js/jquery.tablesorter.min.js"/>
+ <link rel="stylesheet" type="text/css" href="/syrup/static/main.css"/>
+ <script type="text/javascript" src="/syrup/static/jquery/js/jquery-1.3.2.min.js"/>
+ <script type="text/javascript" src="/syrup/static/jquery/js/jquery-ui-1.7.1.custom.min.js"/>
+ <script type="text/javascript" src="/syrup/static/jquery/js/jquery.tablesorter.min.js"/>
${select('*[local-name()!="title"]')}
</head>
</py:match>
${os.getpid()}
${app_name}
</div>
- <img src="/static/institution-logo.png" style="height: 50;"/>
+ <img src="/syrup/static/institution-logo.png" style="height: 50;"/>
</div>
<!--
<div id="header" py:if="user.is_authenticated()">
</div>
<span py:if="user.is_authenticated()">
<strong style="padding-right: 18;">Welcome, ${user.first_name or user.username}!</strong>
- <a href="/accounts/logout">Log Out</a>
+ <a href="/syrup/accounts/logout">Log Out</a>
• <a href="/syrup/prefs/">Preferences</a>
</span>
<span py:if="not user.is_authenticated()">
<strong style="padding-right: 18;">Welcome!</strong>
- <a class="loginbutton" href="/accounts/login/">Log In</a>
+ <a class="loginbutton" href="/syrup/accounts/login/">Log In</a>
• <a href="/syrup/prefs/">Preferences</a>
</span>
</div>
from django.conf.urls.defaults import *
from django.conf import settings
+import django
+import os
+
+# I know it's not recommended, but this lets us mount django-admin's
+# media through Django, through mod_python.
+
+ADMIN_MEDIA_ROOT = os.path.join(os.path.dirname(django.__file__), 'contrib/admin/media/')
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
- (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+ (r'^syrup/djadmin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
- (r'^admin/(.*)', admin.site.root),
- (r'^syrup/', include('conifer.syrup.urls')),
- (r'^static/(?P<path>.*)$', 'django.views.static.serve',
+ (r'^syrup/djadmin/(.*)', admin.site.root),
+ (r'^syrup/djmedia/(.*)', 'django.views.static.serve',
+ {'document_root': ADMIN_MEDIA_ROOT}),
+ (r'^syrup/static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
- (r'^accounts/(?P<path>.*)$', 'conifer.syrup.views.auth_handler'),
+ (r'^syrup/accounts/(?P<path>.*)$', 'conifer.syrup.views.auth_handler'),
# (r'^syrup/setlang', 'conifer.syrup.views.setlang'),
(r'^syrup/i18n/', include('django.conf.urls.i18n')),
+ (r'^syrup/', include('conifer.syrup.urls')),
)
if not settings.DEBUG:
- handler500 = 'conifer.syrup.views.custom_error_handler'
+ handler500 = 'conifer.syrup.views.custom_500_handler'
+ handler404b = 'conifer.syrup.views.custom_400_handler'