From 7b6b084718d76ec30eb2a017f42bfc4bb8f2511f Mon Sep 17 00:00:00 2001 From: gfawcett Date: Tue, 24 Mar 2009 02:25:29 +0000 Subject: [PATCH] hackety hack. hackish add-physical-item interface (catalogue search). It's primitive. Adding a physical item entails doing a catalogue search, and picking the desired item from the results. This pushes parts of the MARC record into Syrup as an indicator of the wanted item. Resolving bib ID or barcode is out of scope, most likely done in wetware. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@212 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/libsystems/z3950/yaz_search.py | 5 ++- conifer/syrup/urls.py | 3 +- conifer/syrup/views.py | 47 +++++++++++++++++++++++++++- conifer/templates/components/course.xhtml | 4 +-- conifer/templates/item_add_cat_search.xhtml | 48 +++++++++++++++++++++++++++++ conifer/templates/item_add_phys.xhtml | 31 +++++++++++++++++++ 6 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 conifer/templates/item_add_cat_search.xhtml create mode 100644 conifer/templates/item_add_phys.xhtml diff --git a/conifer/libsystems/z3950/yaz_search.py b/conifer/libsystems/z3950/yaz_search.py index 724d235..0b85621 100644 --- a/conifer/libsystems/z3950/yaz_search.py +++ b/conifer/libsystems/z3950/yaz_search.py @@ -9,17 +9,20 @@ import re from xml.etree import ElementTree import pexpect import marctools +import sys + loc_to_unicode = marctools.locToUTF8().replace LOG = None # for pexpect debugging, try LOG = sys.stderr YAZ_CLIENT = 'yaz-client' -GENERAL_TIMEOUT = 3 +GENERAL_TIMEOUT = 10 PRESENT_TIMEOUT = 30 def search(host, database, query, start=1, limit=None): server = pexpect.spawn('yaz-client', timeout=GENERAL_TIMEOUT, logfile=LOG) + #server.expect('Z>') for line in ('open %s' % host, 'base %s' % database, 'format xml'): server.sendline(line) server.expect('Z>') diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index 6499a85..396ca8b 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -9,7 +9,7 @@ GENERIC_REGEX = r'((?P\d+)/)?(?P.+)?$' urlpatterns = patterns('conifer.syrup.views', (r'^$', 'welcome'), (r'^course/$', 'my_courses'), - (r'^course/new/$', 'add_new_course'), + (r'^course/new/$', 'add/$ew_course'), (r'^course/new/ajax_title$', 'add_new_course_ajax_title'), (r'^course/invitation/$', 'course_invitation'), (r'^browse/$', 'browse'), @@ -38,6 +38,7 @@ urlpatterns = patterns('conifer.syrup.views', (ITEM_PREFIX + r'meta$', 'item_metadata'), (ITEM_PREFIX + r'edit/$', 'item_edit'), (ITEM_PREFIX + r'add/$', 'item_add'), # for adding sub-things + (ITEM_PREFIX + r'add/cat_search/$', 'item_add_cat_search'), (r'^admin/$', 'admin_index'), (r'^admin/terms/' + GENERIC_REGEX, 'admin_terms'), (r'^admin/depts/' + GENERIC_REGEX, 'admin_depts'), diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 578ba63..01c3575 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -613,9 +613,13 @@ def item_add(request, course_id, item_id): assert item_type, _('No item_type parameter was provided.') # for the moment, only HEADINGs, URLs and ELECs can be added. fixme. - assert item_type in ('HEADING', 'URL', 'ELEC'), \ + assert item_type in ('HEADING', 'URL', 'ELEC', 'PHYS'), \ _('Sorry, only HEADINGs, URLs and ELECs can be added right now.') + if request.method != 'POST' and item_type == 'PHYS': + # special handling: send to catalogue search + return HttpResponseRedirect('cat_search/') + if request.method != 'POST': item = models.Item() # dummy object metadata_formset = metadata_formset_class(queryset=item.metadata_set.all()) @@ -688,6 +692,47 @@ def item_add(request, course_id, item_id): else: return HttpResponseRedirect(course.course_url()) +@instructors_only +def item_add_cat_search(request, course_id, item_id): + if request.method != 'POST': + return g.render('item_add_cat_search.xhtml', results=[], query='@and dylan thomas') + query = request.POST.get('query','').strip() + pickitem = request.POST.get('pickitem', '').strip() + if not pickitem: + assert query, 'must provide a query.' + from conifer.libsystems.z3950 import yaz_search + host, db, query = ('dwarf.cs.uoguelph.ca:2210', 'conifer', query) + #host, db = ('z3950.loc.gov:7090', 'VOYAGER') + results = yaz_search.search(host, db, query) + return g.render('item_add_cat_search.xhtml', results=results, query=query) + else: + #fixme, this block copied from item_add. refactor. + parent_item_id = item_id + if parent_item_id=='0': + parent_item = None + course = get_object_or_404(models.Course, pk=course_id) + else: + parent_item = get_object_or_404(models.Item, pk=parent_item_id, course__id=course_id) + assert parent_item.item_type == 'HEADING', _('You can only add items to headings!') + course = parent_item.course + if not course.can_edit(request.user): + return _access_denied(_('You are not an editor.')) + + pickitem = eval(pickitem) # fixme, dangerous. cache result server-side instead, or encrypt it. + item = course.item_set.create(parent_heading=parent_item, + title=pickitem.get('245a', 'Untitled'), + item_type='PHYS') + item.save() + # these are a temporary hack, must replace + meta = [('245a', 'dc:title'), ('100a', 'dc:creator'), ('260b', 'dc:publisher'), + ('dc:260c', 'dc:date'), ('700a', 'dc:contributor')] + for marc, dc in meta: + value = pickitem.get(marc) + if value: + md = item.metadata_set.create(item=item, name=dc, value=value) + item.save() + return HttpResponseRedirect('../../../%d/' % item.id) + metadata_formset_class = modelformset_factory(models.Metadata, fields=['name','value'], extra=3, can_delete=True) diff --git a/conifer/templates/components/course.xhtml b/conifer/templates/components/course.xhtml index 7e5ed18..3aefa4a 100644 --- a/conifer/templates/components/course.xhtml +++ b/conifer/templates/components/course.xhtml @@ -74,8 +74,8 @@ searchtext = _('search this course...') -
-

Show more attributes

+
+

Show more attributes

${Markup(metadata_formset.management_form)} diff --git a/conifer/templates/item_add_cat_search.xhtml b/conifer/templates/item_add_cat_search.xhtml new file mode 100644 index 0000000..117d7ef --- /dev/null +++ b/conifer/templates/item_add_cat_search.xhtml @@ -0,0 +1,48 @@ + + + + + + ${title} + + + + +

${title}

+
+ + + +

show more detail

+
+ + + + + + + + + + + + +
${title}${res[k]}
+
+ + +
+
${k}${res[k]}
+ + diff --git a/conifer/templates/item_add_phys.xhtml b/conifer/templates/item_add_phys.xhtml new file mode 100644 index 0000000..460c495 --- /dev/null +++ b/conifer/templates/item_add_phys.xhtml @@ -0,0 +1,31 @@ + + + + + + ${title} + + + + ${course_banner(course)} + ${nested_title(parent_item)} +

${title}

+ +
+ ${item_metadata_formset(show_more=False)} +

+ + +

+ +
+ + -- 2.11.0