From: erickson Date: Tue, 13 May 2008 20:29:51 +0000 (+0000) Subject: added initial marc upload to po-creation logic and interface X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=f4b4c1436a8aae8a148e3e3c1a075d260eca9f5b;p=Evergreen.git added initial marc upload to po-creation logic and interface git-svn-id: svn://svn.open-ils.org/ILS/branches/acq-experiment@9586 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/web/oilsweb/oilsweb/controllers/acq/po.py b/Open-ILS/web/oilsweb/oilsweb/controllers/acq/po.py index 8159486314..fbb962e278 100644 --- a/Open-ILS/web/oilsweb/oilsweb/controllers/acq/po.py +++ b/Open-ILS/web/oilsweb/oilsweb/controllers/acq/po.py @@ -108,3 +108,54 @@ class PoController(BaseController): 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') + + diff --git a/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/po/marc_upload.html b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/po/marc_upload.html new file mode 100644 index 0000000000..7e6834925a --- /dev/null +++ b/Open-ILS/web/oilsweb/oilsweb/templates/oils/default/acq/po/marc_upload.html @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +<%inherit file='../base.html'/> +<%def name="page_title()">${_('MARC File Upload')} +<%def name="block_content()"> + + + + + +
+ + + + + + + + + + + + + + + + + +
+ +
+ +
+
${_("Upload File")}
+
+
+ + +