for better mod_python deployment, moving all URLs under /syrup/
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 7 Apr 2009 01:42:22 +0000 (01:42 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 7 Apr 2009 01:42:22 +0000 (01:42 +0000)
That will change next! I will move them all up to a relative root, and
then Apache can decide what the root-prefix will be.

git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@296 6d9bc8c9-1ec2-4278-b937-99fde70a366f

14 files changed:
conifer/custom/lib_integration.py
conifer/settings.py
conifer/syrup/urls.py
conifer/syrup/views.py
conifer/templates/admin/index.xhtml
conifer/templates/browse_index.xhtml
conifer/templates/course_detail.xhtml
conifer/templates/edit_course.xhtml
conifer/templates/edit_course_permissions.xhtml
conifer/templates/feeds/course_feed_index.xhtml
conifer/templates/item_heading_detail.xhtml
conifer/templates/item_relocate.xhtml
conifer/templates/master.xhtml
conifer/urls.py

index 3b0c218..bf9bcb5 100644 (file)
 # 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
@@ -41,7 +47,7 @@ from conifer.libsystems.z3950 import yaz_search
 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)
index eb79a7e..41f00a3 100644 (file)
@@ -8,7 +8,7 @@ import os
 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 = (
@@ -59,7 +59,7 @@ MEDIA_URL = ''
 # 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!&'
@@ -102,9 +102,9 @@ INSTALLED_APPS = (
 AUTH_PROFILE_MODULE = 'syrup.UserProfile'
 
 
-AUTHENTICATION_BACKENDS = [
+AUTHENTICATION_BACKENDS = (
     'django.contrib.auth.backends.ModelBackend',
-]
+)
 
 
 # more on this later.
@@ -131,4 +131,6 @@ try:
 except:
     pass
 
-CACHE_BACKEND = 'locmem:///'
+#CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
+#CACHE_BACKEND = 'db://test_cache_table'
+#CACHE_BACKEND = 'locmem:///'
index 36b9170..0ad0ec0 100644 (file)
@@ -16,7 +16,6 @@ urlpatterns = patterns('conifer.syrup.views',
     (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'),
index c7d0949..d37a89d 100644 (file)
@@ -22,7 +22,7 @@ from django.contrib.auth.decorators import login_required
 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
@@ -134,7 +134,7 @@ def _fast_user_membership_query(user_id, course_id, where=None):
 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,
@@ -1379,9 +1379,13 @@ def phys_mark_arrived_match(request):
     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)
index ff7df8a..2c09a6e 100644 (file)
@@ -11,7 +11,7 @@ title = _('Administrative Options')
 <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>
index 95d40c4..02cf5ae 100644 (file)
@@ -11,7 +11,7 @@ title = _('Browse the Reserves')
 <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>
index 51054d9..c8b60ec 100644 (file)
@@ -10,7 +10,7 @@ is_editor = course.can_edit(request.user)
   <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)}
index fcde573..87c32f4 100644 (file)
@@ -11,7 +11,7 @@ else:
 <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>
index dee75ed..e754bdf 100644 (file)
@@ -9,7 +9,7 @@ instructors = [m for m in models.Member.objects.filter(course=course) if m.role
   <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)}
index 8d1b8f0..f7999c9 100644 (file)
@@ -8,7 +8,7 @@ title = _('Available Feeds')
   <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)}
index e98bbbd..9a6c639 100644 (file)
@@ -12,7 +12,7 @@ item_tree = course.item_tree(subtree=item)
   <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)}
index 4cfc64f..f5f88dc 100644 (file)
@@ -8,7 +8,7 @@ title = 'Move item under a different heading'
   <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)}
index 7a8cee5..2664fd7 100644 (file)
@@ -11,10 +11,10 @@ import os
     <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>
@@ -26,7 +26,7 @@ import os
          ${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()">
@@ -44,12 +44,12 @@ import os
         </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>
        &bull; <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>
        &bull; <a href="/syrup/prefs/">Preferences</a>
       </span>
     </div>
index cf2d782..c2874cb 100644 (file)
@@ -1,5 +1,12 @@
 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
@@ -11,19 +18,22 @@ urlpatterns = patterns('',
 
     # 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'