From 98b93a67742e6437da0368b85f846f3022aec839 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 21 Dec 2007 15:23:11 +0000 Subject: [PATCH] added a field extractor for the marc data. added an isbn scrubber to clean up the interface some. added initial marc2html logic git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@8268 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/oilsweb/development.ini | 1 + Open-ILS/web/oilsweb/oilsweb/controllers/acq.py | 18 ++-- Open-ILS/web/oilsweb/oilsweb/lib/bib.py | 19 ++++ Open-ILS/web/oilsweb/oilsweb/lib/context.py | 4 +- Open-ILS/web/oilsweb/oilsweb/public/index.html | 108 --------------------- .../public/oils/media/css/skin/acq_default.css | 2 +- .../public/oils/media/css/theme/acq_default.css | 1 + .../public/oils/media/xsl/oilsMARC21slim2HTML.xsl | 91 +++++++++++++++++ .../templates/oils/default/acq/pl_builder.html | 4 +- .../templates/oils/default/acq/rdetails.html | 5 + 10 files changed, 134 insertions(+), 119 deletions(-) create mode 100644 Open-ILS/web/oilsweb/oilsweb/lib/bib.py delete mode 100644 Open-ILS/web/oilsweb/oilsweb/public/index.html create mode 100644 Open-ILS/web/oilsweb/oilsweb/public/oils/media/xsl/oilsMARC21slim2HTML.xsl diff --git a/Open-ILS/web/oilsweb/development.ini b/Open-ILS/web/oilsweb/development.ini index b200829d86..9ed840ed0a 100644 --- a/Open-ILS/web/oilsweb/development.ini +++ b/Open-ILS/web/oilsweb/development.ini @@ -32,6 +32,7 @@ oils_username = admin oils_password = open-ils oils_xsl_prefix = oilsweb/public/oils/media/xsl oils_xsl_acq_bib = acq-bibdata-marc.xslt +oils_xsl_marc2html = oilsMARC21slim2HTML.xsl # If you'd like to fine-tune the individual locations of the cache data dirs diff --git a/Open-ILS/web/oilsweb/oilsweb/controllers/acq.py b/Open-ILS/web/oilsweb/oilsweb/controllers/acq.py index 2c9142cb2c..8b6b684ae6 100644 --- a/Open-ILS/web/oilsweb/oilsweb/controllers/acq.py +++ b/Open-ILS/web/oilsweb/oilsweb/controllers/acq.py @@ -5,6 +5,7 @@ import pylons import oilsweb.lib.context import oilsweb.lib.util import oilsweb.lib.acq.search +import oilsweb.lib.bib import osrf.cache, osrf.json from oilsweb.lib.context import Context, SubContext, ContextItem @@ -43,14 +44,16 @@ class AcqController(BaseController): def pl_builder(self): - c.oils = oilsweb.lib.context.Context.init(request) + ctx = oilsweb.lib.context.Context.init(request) # add logic to see where we are fetching bib data from - if c.oils.acq.search_source: - c.oils_acq_records, c.oils.acq.search_cache_key = self._build_z39_search(c.oils) + if ctx.acq.search_source: + c.oils_acq_records, ctx.acq.search_cache_key = self._build_z39_search(ctx) - c.oils.acq.extract_bib_field = oilsweb.lib.acq.search.extract_bib_field - return render('oils/%s/acq/pl_builder.html' % c.oils.core.skin) + ctx.scrub_isbn = oilsweb.lib.bib.scrub_isbn # XXX add more generically to the context object + ctx.acq.extract_bib_field = oilsweb.lib.acq.search.extract_bib_field + c.oils = ctx + return render('oils/%s/acq/pl_builder.html' % ctx.core.skin) def _build_z39_search(self, ctx): @@ -63,13 +66,13 @@ class AcqController(BaseController): } # collect the sources and credentials - for src in c.oils.acq.search_source: + for src in ctx.acq.search_source: search['service'].append(src) search['username'].append("") # XXX config values? in-db? search['password'].append("") # XXX config values? in-db? # collect the search classes - for cls in c.oils.acq.search_class: + for cls in ctx.acq.search_class: if request.params[cls]: search['search'][cls] = request.params[cls] @@ -85,6 +88,7 @@ class AcqController(BaseController): for rec in res['records']: if str(rec['cache_id']) == str(rec_id): 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) return 'exception -> no record' diff --git a/Open-ILS/web/oilsweb/oilsweb/lib/bib.py b/Open-ILS/web/oilsweb/oilsweb/lib/bib.py new file mode 100644 index 0000000000..381a10ee27 --- /dev/null +++ b/Open-ILS/web/oilsweb/oilsweb/lib/bib.py @@ -0,0 +1,19 @@ +import os, re +import pylons +import osrf.ses +import oils.utils.csedit +import oilsweb.lib.util + +def marc_to_html(marcxml): + # create a path building utility function .... + xslFile = os.path.join(os.getcwd(), pylons.config['oils_xsl_prefix'], pylons.config['oils_xsl_marc2html']) + html = oilsweb.lib.util.apply_xsl(marcxml, xslFile) + # XXX encoding problems need resolving... + return html + +def scrub_isbn(isbn): + ''' removes trailing data from an ISBN ''' + if not isbn: return isbn + return re.sub('\s.*','', isbn) + + diff --git a/Open-ILS/web/oilsweb/oilsweb/lib/context.py b/Open-ILS/web/oilsweb/oilsweb/lib/context.py index 18176d82e2..6badcfa99a 100644 --- a/Open-ILS/web/oilsweb/oilsweb/lib/context.py +++ b/Open-ILS/web/oilsweb/oilsweb/lib/context.py @@ -21,8 +21,10 @@ class Context(object): def wrap(self): return {'oils': self} + ''' def applySubContext(self, app, subContext): setattr(self, app, subContext) + ''' def make_query_string(self): q = '' @@ -44,7 +46,7 @@ class Context(object): def applySubContext(app, ctx): global _subContexts _subContexts[app] = ctx - + @staticmethod def getContext(): global _context diff --git a/Open-ILS/web/oilsweb/oilsweb/public/index.html b/Open-ILS/web/oilsweb/oilsweb/public/index.html deleted file mode 100644 index defce375d3..0000000000 --- a/Open-ILS/web/oilsweb/oilsweb/public/index.html +++ /dev/null @@ -1,108 +0,0 @@ - - - - Pylons Default Page - - - - -

Welcome to your Pylons Web Application

- -

Weren't expecting to see this page?

- -

The oilsweb/public/ directory is searched for static files - before your controllers are run. Remove this file (oilsweb/public/index.html) - and edit the routes in oilsweb/config/routing.py to point the - root path to a 'hello' controller we'll create below: -

 map.connect('', controller='hello', action='index')
-

- -

Getting Started

-

You're now ready to start creating your own web application. To create a 'hello' controller, - run the following command in your project's root directory: -

-oilsweb$ paster controller hello
-
- - This generates the following the following code in oilsweb/controllers/hello.py: -
-import logging
-
-from oilsweb.lib.base import *
-
-log = logging.getLogger(__name__)
-
-class HelloController(BaseController):
-
-    def index(self):
-        # Return a rendered template
-        #   return render('/some/template.mako)
-        # or, Return a response
-        return 'Hello World'
-
-

-

This controller simply prints out 'Hello World' to the browser. Pylons' default routes - automatically set up this controller to respond at the /hello URL. - With the additional route described above, this controller will also respond at the - root path. -

- -

Using a template

-

To call a template and do something a little more complex, this following example - shows how to print out some request information from a - Mako template. -

-

Create a serverinfo.mako file in your project's oilsweb/templates/ - directory with the following contents: -

-
-<h2>
-Server info for ${request.host}
-</h2>
-
-<p>
-The URL you called: ${h.url_for()}
-</p>
-
-<p>
-The name you set: ${c.name}
-</p>
-
-<p>The WSGI environ:<br />
-<pre>${c.pretty_environ}</pre>
-</p>
-
- -Then add the following to your 'hello' controller class: -
-    def serverinfo(self):
-        import cgi
-        import pprint
-        c.pretty_environ = cgi.escape(pprint.pformat(request.environ))
-        c.name = 'The Black Knight'
-        return render('/serverinfo.mako')
-
- -You can now view the page at: /hello/serverinfo -

- - diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/css/skin/acq_default.css b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/css/skin/acq_default.css index d313aed07f..15ef414f0e 100644 --- a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/css/skin/acq_default.css +++ b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/css/skin/acq_default.css @@ -15,4 +15,4 @@ .oils-acq-pl_builder-records-author-row td { padding-left: 30px; } .oils-acq-pl_builder-records-phys_desc-row td { padding-left: 30px; } .oils-acq-pl_builder-records-phys_desc-row {} - +#oils-acq-rdetail-marc-block { margin-top: 10px; padding: 10px; } diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/css/theme/acq_default.css b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/css/theme/acq_default.css index 5b6627ecc4..c9acd4ae92 100644 --- a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/css/theme/acq_default.css +++ b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/css/theme/acq_default.css @@ -8,3 +8,4 @@ #oils-acq-search-sources-label { font-weight: bold; } #oils-acq-pl_builder-table thead td { font-weight: bold; } #oils-acq-pl_builder-table td { border-bottom: 1px solid #808080;} +#oils-acq-rdetail-marc-block { border-top: 1px solid #808080; } diff --git a/Open-ILS/web/oilsweb/oilsweb/public/oils/media/xsl/oilsMARC21slim2HTML.xsl b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/xsl/oilsMARC21slim2HTML.xsl new file mode 100644 index 0000000000..f41b110acb --- /dev/null +++ b/Open-ILS/web/oilsweb/oilsweb/public/oils/media/xsl/oilsMARC21slim2HTML.xsl @@ -0,0 +1,91 @@ + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + +
+ LDR + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + . + + + + + + + + + + + ‡ + + + +
+ + diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/pl_builder.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/pl_builder.html index 1abee2a158..b978e536c8 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/pl_builder.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/pl_builder.html @@ -13,12 +13,12 @@ + src='${c.oils.core.ac_prefix}/jacket/small/${c.oils.scrub_isbn(c.oils.acq.extract_bib_field(rec,"isbns.isbn"))}'/> ${c.oils.acq.extract_bib_field(rec, 'title')} - ${c.oils.acq.extract_bib_field(rec, 'isbns.isbn')} + ${c.oils.scrub_isbn(c.oils.acq.extract_bib_field(rec, 'isbns.isbn'))} ${res['service']} diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/rdetails.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/rdetails.html index 1c8244306f..002f9ed78a 100644 --- a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/rdetails.html +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/rdetails.html @@ -9,5 +9,10 @@ % endfor + -- 2.11.0