From 5e1f14ffd380af594ae4d49bc378dbc85edbb7cb Mon Sep 17 00:00:00 2001 From: gfawcett Date: Tue, 7 Apr 2009 02:08:57 +0000 Subject: [PATCH] work in progress: fixing absolute /syrup/ root references. Sorry for checking in partially-working code, but I don't want to list this. Some /syrup/ root-prefixes are fixed; some are not. Note, this commit will almost certainly break if running as './manage.py runserver'. Using mod_python, it should still work: SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE conifer.settings PythonOption django.root /syrup PythonDebug Off PythonPath "['/home/graham/projects/evergreen/servres/'] + sys.path" git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@297 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/settings.py | 7 +++---- conifer/syrup/models.py | 17 +++++++++++------ conifer/syrup/views.py | 12 +++++++----- conifer/templates/master.xhtml | 30 +++++++++++------------------- conifer/templates/tabbar.xhtml | 10 +++++----- conifer/urls.py | 14 +++++++------- 6 files changed, 44 insertions(+), 46 deletions(-) diff --git a/conifer/settings.py b/conifer/settings.py index 41f00a3..a2b84ae 100644 --- a/conifer/settings.py +++ b/conifer/settings.py @@ -121,14 +121,13 @@ if EVERGREEN_XMLRPC_SERVER: AUTHENTICATION_BACKENDS.append( 'conifer.custom.auth_evergreen.EvergreenAuthBackend') -# stuff that I really ought not check into svn... -#SIP_HOST = ('hostname', 9999) -#SIP_CREDENTIALS = ('userid', 'password', 'location') - try: # Graham has this right now; it's not official Syrup. Nothing to see here. from private_local_settings import SIP_HOST, SIP_CREDENTIALS except: + # stuff that I really ought not check into svn... + #SIP_HOST = ('hostname', 9999) + #SIP_CREDENTIALS = ('userid', 'password', 'location') pass #CACHE_BACKEND = 'memcached://127.0.0.1:11211/' diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 6ae9ac6..6816a06 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -11,6 +11,7 @@ from conifer.custom import lib_integration import re import random from django.utils import simplejson +from conifer.middleware import genshi_locals def highlight(text, phrase, highlighter='\\1'): @@ -241,7 +242,9 @@ class Course(m.Model): return mbr.role in (u'INSTR', u'PROXY') def course_url(self, suffix=''): - return '/syrup/course/%d/%s' % (self.id, suffix) + req = genshi_locals.get_request() + prefix = req.META['SCRIPT_NAME'] + return '%s/course/%d/%s' % (prefix, self.id, suffix) def generate_new_passkey(self): # todo: have a pluggable passkey algorithm. @@ -465,15 +468,17 @@ class Item(m.Model): return self.item_type in ('ELEC', 'URL', 'PHYS') def item_url(self, suffix='', force_local_url=False): + req = genshi_locals.get_request() + prefix = req.META['SCRIPT_NAME'] if self.item_type == 'ELEC' and suffix == '': - return '/syrup/course/%d/item/%d/dl/%s' % ( - self.course_id, self.id, + return '%s/course/%d/item/%d/dl/%s' % ( + prefix, self.course_id, self.id, self.fileobj.name.split('/')[-1]) if self.item_type == 'URL' and suffix == '' and not force_local_url: return self.url - else: - return '/syrup/course/%d/item/%d/%s' % ( - self.course_id, self.id, suffix) + else: + return '%s/course/%d/item/%d/%s' % ( + prefix, self.course_id, self.id, suffix) def parent_url(self, suffix=''): if self.parent_heading: diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index d37a89d..d3de04c 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -37,6 +37,7 @@ from django.forms.models import modelformset_factory from conifer.custom import lib_integration from conifer.libsystems.z3950.marcxml import marcxml_to_dictionary, marcxml_dictionary_to_dc from fuzzy_match import rank_pending_items +from django.core.urlresolvers import reverse #----------------------------------------------------------------------------- # Z39.50 Support @@ -78,9 +79,10 @@ def log(level, msg): # Authentication def auth_handler(request, path): + default_url = reverse(welcome) #request.META['SCRIPT_NAME'] + '/' if path == 'login/': if request.method == 'GET': - next=request.GET.get('next', '/syrup/') + next=request.GET.get('next', default_url) if request.user.is_authenticated(): return HttpResponseRedirect(next) else: @@ -106,10 +108,10 @@ def auth_handler(request, path): except models.UserProfile.DoesNotExist: profile = models.UserProfile.objects.create(user=user) profile.save() - return HttpResponseRedirect(request.POST.get('next', '/syrup/')) + return HttpResponseRedirect(request.POST.get('next', default_url)) elif path == 'logout': logout(request) - return HttpResponseRedirect('/syrup/') + return HttpResponseRedirect(default_url) else: return HttpResponse('auth_handler: ' + path) @@ -134,7 +136,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 = '/syrup/accounts/login/?next=' + request.environ['PATH_INFO'] + dest = request.META['SCRIPT_NAME'] + '/accounts/login/?next=' + request.environ['PATH_INFO'] return HttpResponseRedirect(dest) else: return simple_message(_('Access denied.'), message, @@ -525,7 +527,7 @@ def delete_course(request, course_id): course = get_object_or_404(models.Course, pk=course_id) if request.POST.get('confirm_delete'): course.delete() - return HttpResponseRedirect('/syrup/course/') + return HttpResponseRedirect(reverse('my_courses')) else: return HttpResponseRedirect('../') diff --git a/conifer/templates/master.xhtml b/conifer/templates/master.xhtml index 2664fd7..cde8578 100644 --- a/conifer/templates/master.xhtml +++ b/conifer/templates/master.xhtml @@ -2,6 +2,7 @@ app_name = _('Syrup E-Reserve System') search = _('search...') import os +rooted = lambda url: request.META['SCRIPT_NAME'] + url ?> ${app_name}<py:if test="t">: ${t}</py:if> - -