[open-ils-commits] r8283 - in branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb: controllers lib

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Dec 28 11:01:43 EST 2007


Author: erickson
Date: 2007-12-28 10:38:51 -0500 (Fri, 28 Dec 2007)
New Revision: 8283

Added:
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/lib/request.py
Modified:
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq.py
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/admin.py
   branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/base.py
Log:
created a requestmgr class to wrap up context initialization and pre-render cleanup

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq.py
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq.py	2007-12-28 15:37:30 UTC (rev 8282)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq.py	2007-12-28 15:38:51 UTC (rev 8283)
@@ -1,4 +1,5 @@
 from oilsweb.lib.base import *
+from oilsweb.lib.request import RequestMgr
 
 import logging, pylons
 import oilsweb.lib.context
@@ -23,6 +24,9 @@
         self.picklist_item = ContextItem(cgi_name='acq.pi', multi=True)
         self.extract_bib_field = ContextItem(default_value=oilsweb.lib.acq.search.extract_bib_field)
         self.prefix = ContextItem()
+        self.z39_sources = ContextItem()
+        self.search_classes = ContextItem()
+        self.search_classes_sorted = ContextItem()
 
     def postinit(self):
         self.prefix = "%s/acq" % Context.getContext().core.prefix
@@ -33,33 +37,33 @@
 class AcqController(BaseController):
 
     def index(self):
-        c.oils = oilsweb.lib.context.Context.init(request, response)
-        return render('oils/%s/acq/index.html' % c.oils.core.skin)
+        return RequestMgr().render('acq/index.html')
 
     def search(self):
-        c.oils = Context.init(request, response)
-        c.oils_z39_sources = oilsweb.lib.acq.search.fetch_z39_sources(c.oils)
+        r = RequestMgr()
+        r.ctx.acq.z39_sources = oilsweb.lib.acq.search.fetch_z39_sources(r.ctx)
 
         sc = {}
-        for data in c.oils_z39_sources.values():
+        for data in r.ctx.acq.z39_sources.values():
             for key, val in data['attrs'].iteritems():
                 sc[key] = val.get('label') or key
-        c.oils_search_classes = sc
+        r.ctx.acq.search_classes = sc
         keys = sc.keys()
         keys.sort()
-        c.oils_search_classes_sorted = keys
+        r.ctx.acq.search_classes_sorted = keys
+        log.debug("keys = %s" % unicode(r.ctx.acq.z39_sources))
             
-        return render('oils/%s/acq/search.html' % c.oils.core.skin)
+        return r.render('acq/search.html')
         
 
     def pl_builder(self):
-        ctx = oilsweb.lib.context.Context.init(request, response)
+        r = RequestMgr()
         # add logic to see where we are fetching bib data from
+        # XXX fix
+        if r.ctx.acq.search_source:
+            c.oils_acq_records, r.ctx.acq.search_cache_key = self._build_z39_search(r.ctx)
 
-        if ctx.acq.search_source:
-            c.oils_acq_records, ctx.acq.search_cache_key = self._build_z39_search(ctx)
-        c.oils = ctx
-        return render('oils/%s/acq/pl_builder.html' % ctx.core.skin)
+        return r.render('acq/pl_builder.html')
 
 
     def _build_z39_search(self, ctx):
@@ -85,34 +89,33 @@
         return oilsweb.lib.acq.search.multi_search(ctx, search)
 
     def rdetails(self):
-        c.oils = oilsweb.lib.context.Context.init(request, response)
-        rec_id = c.oils.acq.record_id
-        cache_key = c.oils.acq.search_cache_key
+        r = RequestMgr()
+        rec_id = r.ctx.acq.record_id
+        cache_key = r.ctx.acq.search_cache_key
 
         results = osrf.cache.CacheClient().get(cache_key)
         rec = self._find_cached_record(results, rec_id)
         if rec:
-            c.oils.acq.record = rec
-            #c.oils.acq.record_html = oilsweb.lib.bib.marc_to_html(rec['marcxml'])
-            return render('oils/%s/acq/rdetails.html' % c.oils.core.skin)
+            r.ctx.acq.record = rec
+            #r.ctx.acq.record_html = oilsweb.lib.bib.marc_to_html(rec['marcxml'])
+            return r.render('acq/rdetails.html')
         return 'exception -> no record'
 
         
     def create_picklist(self):  
-        ctx = oilsweb.lib.context.Context.init(request, response)
-        if not isinstance(ctx.acq.picklist_item, list):
-            ctx.acq.picklist_item = [ctx.acq.picklist_item]
+        r = RequestMgr()
+        if not isinstance(r.ctx.acq.picklist_item, list):
+            r.ctx.acq.picklist_item = [r.ctx.acq.picklist_item]
 
-        results = osrf.cache.CacheClient().get(ctx.acq.search_cache_key)
+        results = osrf.cache.CacheClient().get(r.ctx.acq.search_cache_key)
 
         records = []
-        for cache_id in ctx.acq.picklist_item:
+        for cache_id in r.ctx.acq.picklist_item:
             rec = self._find_cached_record(results, cache_id)
             records.append(rec)
 
-        c.oils_acq_records = records
-        c.oils = ctx
-        return render('oils/%s/acq/picklist.html' % c.oils.core.skin)
+        c.oils_acq_records = records # XXX
+        return r.render('acq/picklist.html')
 
     def _find_cached_record(self, results, cache_id):
         for res in results:

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/admin.py
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/admin.py	2007-12-28 15:37:30 UTC (rev 8282)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/admin.py	2007-12-28 15:38:51 UTC (rev 8283)
@@ -1,3 +1,4 @@
+from oilsweb.lib.request import RequestMgr
 from oilsweb.lib.base import *
 import oilsweb.lib.util
 from oilsweb.lib.context import Context, SubContext, ContextItem
@@ -21,35 +22,38 @@
 class AdminController(BaseController):
 
     def init(self, type, id=None):
-        c.oils = oilsweb.lib.context.Context.init(request, response)
-        c.oils.adm.object_class = type
-        meta = c.oils.adm.object_meta = oils.utils.idl.oilsGetIDLParser().IDLObject[type]
+        r = RequestMgr()
+        r.ctx.adm.object_class = type
+        meta = r.ctx.adm.object_meta = oils.utils.idl.oilsGetIDLParser().IDLObject[type]
 
         if id is not None:
-            c.oils.adm.object = osrf.ses.AtomicRequest(
+            r.ctx.adm.object = osrf.ses.AtomicRequest(
                 'open-ils.cstore',
                 'open-ils.cstore.direct.%s.retrieve' % 
                     meta['fieldmapper'].replace('::', '.'), id)
+        return r
 
-        c.oils.apply_cookies()
+    def test(self, type, id):
+        r = self.init()
+        return r.render('dashboard.html')
 
     def view(self, type, id):
-        self.init(type, id)
-        return render('oils/%s/admin/object.html' % c.oils.core.skin)
+        r = self.init(type, id)
+        return r.render('admin/object.html')
 
     def update(self, type, id):
-        self.init(type, id)
+        r = self.init(type, id)
         c.oils.adm.mode = 'update'
-        return render('oils/%s/admin/object.html' % c.oils.core.skin)
+        return r.render('admin/object.html')
 
     def create(self, type):
-        self.init(type)
+        r = self.init(type, id)
         c.oils.adm.mode = 'create'
-        return render('oils/%s/admin/object.html' % c.oils.core.skin)
+        return r.render('admin/object.html')
 
     def delete(self, type, id):
-        self.init(type, id)
+        r = self.init(type, id)
         c.oils.adm.mode = 'delete'
-        return render('oils/%s/admin/object.html' % c.oils.core.skin) # show a confirmation page
+        return r.render('admin/object.html')
 
         

Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/base.py
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/base.py	2007-12-28 15:37:30 UTC (rev 8282)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/base.py	2007-12-28 15:38:51 UTC (rev 8283)
@@ -1,5 +1,6 @@
 import logging
 
+from oilsweb.lib.request import RequestMgr
 from oilsweb.lib.base import *
 from oilsweb.lib.context import Context, SubContext, ContextItem
 
@@ -16,6 +17,6 @@
     ''' Controller for globally shared interfaces '''
 
     def dashboard(self):
-        c.oils = Context.init(request, response)
-        return render('oils/%s/dashboard.html' % c.oils.core.skin)
+        r = RequestMgr()
+        return r.render('dashboard.html')
 

Added: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/lib/request.py
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/lib/request.py	                        (rev 0)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/lib/request.py	2007-12-28 15:38:51 UTC (rev 8283)
@@ -0,0 +1,44 @@
+import pylons
+from oilsweb.lib.base import *
+import oilsweb.lib.context
+
+class RequestMgr(object):
+    ''' This is container class for aggregating the various Pylons global
+        variables, initializing the local and pylons context objects, and
+        rendering templates based on the skin
+        '''
+
+    def __init__(self):
+        # pylons request object
+        self.request = request
+        # pylons response object
+        self.response = response
+        # pylons session
+        self.session = session
+        # our local context object.
+        self.ctx = oilsweb.lib.context.Context.init(request, response)
+        # the global pylons context object
+        self.pylons_context = c
+        # true if we've saved the session/cookie data, etc.
+        self.finalized = False
+
+    def finalize(self):
+        ''' Perform any last minute cleanup just prior to sending the result '''
+        if not self.finalized:
+            self.session.save()
+            self.ctx.apply_cookies()
+            self.pylons_context.oils = self.ctx
+            self.finalized = True
+        
+    def render(self, tpath):
+        ''' Renders the given template using the configured skin.
+            @param tpath The path to the template.  The tpath should 
+            only include the path to the template after the skin component.
+            E.g. if the full path is /oils/myskin/base/dashboard.html, tpath
+            would be 'base/dashboard.html'
+            '''
+        self.finalize()
+        return pylons.templating.render('oils/%s/%s' % (self.ctx.core.skin, tpath))
+
+
+



More information about the open-ils-commits mailing list