[open-ils-commits] r9586 - in
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb:
controllers/acq templates/oils/default/acq/po
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue May 13 16:29:55 EDT 2008
Author: erickson
Date: 2008-05-13 16:29:51 -0400 (Tue, 13 May 2008)
New Revision: 9586
Added:
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/po/marc_upload.html
Modified:
branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/po.py
Log:
added initial marc upload to po-creation logic and interface
Modified: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/po.py
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/po.py 2008-05-13 20:00:13 UTC (rev 9585)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/controllers/acq/po.py 2008-05-13 20:29:51 UTC (rev 9586)
@@ -108,3 +108,54 @@
r = RequestMgr()
return r.render('acq/po/search.html')
+ def marc_upload(self):
+ '''
+ Requires pymarc-1.5, elementree
+ $ easy_install elementtree
+ $ easy_install http://pypi.python.org/packages/source/p/pymarc/pymarc-1.5.tar.gz
+
+ Takes a MARC file, converts it to marcxml, and creates a new PO
+ and lineitems from the data.
+ '''
+
+ import pymarc
+ import pymarc.reader
+ import pymarc.marcxml
+ import pylons
+ import oils.system
+
+ r = RequestMgr()
+
+ oils.system.System.connect(
+ config_file = pylons.config['osrf_config'],
+ config_context = pylons.config['osrf_config_ctxt'])
+
+ if 'marc_file' in r.request.params:
+
+ provider = r.request.params['provider']
+ authtoken = r.request.params['authtoken']
+
+ # first, create the PO
+ po = osrf.net_obj.NetworkObject.acqpo()
+ po.provider(provider)
+ po_id = ClientSession.atomic_request('open-ils.acq',
+ 'open-ils.acq.purchase_order.create', authtoken, po)
+ oils.event.Event.parse_and_raise(po_id)
+
+ # now, parse the MARC and create a lineitem per record
+ marc_reader = pymarc.reader.MARCReader(r.request.params['marc_file'].file)
+ for record in marc_reader:
+
+ lineitem = osrf.net_obj.NetworkObject.jub()
+ lineitem.marc(pymarc.marcxml.record_to_xml(record))
+ lineitem.provider(provider)
+ lineitem.purchase_order(po_id)
+
+ stat = ClientSession.atomic_request('open-ils.acq',
+ 'open-ils.acq.lineitem.create', authtoken, lineitem)
+ oils.event.Event.parse_and_raise(stat)
+ return redirect_to(controller='acq/po', action='view', id=po_id)
+
+ return r.render('acq/po/marc_upload.html')
+
+
Added: branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/po/marc_upload.html
===================================================================
--- branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/po/marc_upload.html (rev 0)
+++ branches/acq-experiment/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/po/marc_upload.html 2008-05-13 20:29:51 UTC (rev 9586)
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+<%inherit file='../base.html'/>
+<%def name="page_title()">${_('MARC File Upload')}</%def>
+<%def name="block_content()">
+
+<style>
+ @import url(${c.oils.core.media_prefix.value}/js/dojo/dojox/widget/FileInput/FileInput.css);
+</style>
+
+<script>
+ dojo.require('dijit.form.Form');
+ dojo.require('dijit.form.Button');
+ dojo.require('dijit.form.FilteringSelect');
+ dojo.require('openils.acq.Provider');
+ dojo.require('dojox.widget.FileInput');
+ function load() {
+ openils.acq.Provider.createStore(
+ function(store) {
+ providerSelector.store =
+ new dojo.data.ItemFileReadStore({data:store});
+ },
+ 'MANAGE_PROVIDER'
+ );
+ }
+ dojo.addOnLoad(load);
+</script>
+
+<form dojoType='dijit.form.Form' enctype="multipart/form-data" name='marc_upload_form'
+ action='${c.oils.acq.prefix.value}/po/marc_upload' method='post'>
+ <style>#oils-acq-po-marc-upload-table td {padding: 5px;}</style>
+ <script type="dojo/method" event="onSubmit">
+ document.forms.marc_upload_form.authtoken.value = openils.User.authtoken;
+ return true;
+ </script>
+ <input name='authtoken' type='hidden'> </input>
+ <table id='oils-acq-po-marc-upload-table' style='width:auto;'>
+ <tbody>
+ <tr>
+ <td><label for='provider'>${_('Provider')}</label></td>
+ <td>
+ <select name='provider' style='overflow-y:auto;'
+ jsId="providerSelector" dojoType="dijit.form.FilteringSelect"> </select>
+ </td>
+ </tr>
+ <tr>
+ <td><label for='marc_file'>MARC File</label></td>
+ <td nowrap='nowrap'>
+ <input dojoType="dojox.widget.FileInput" name="marc_file" id='marc_file'/> </input>
+ </td>
+ </tr>
+ <tr>
+ <td colspan='2'>
+ <div dojoType='dijit.form.Button' type='submit'>${_("Upload File")}</div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+</form>
+
+</%def>
+
More information about the open-ils-commits
mailing list