using xslt for formatting z39.50 results
authorartunit <artunit@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Sun, 16 Aug 2009 11:38:50 +0000 (11:38 +0000)
committerartunit <artunit@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Sun, 16 Aug 2009 11:38:50 +0000 (11:38 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@617 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/views/general.py

index 9ca9ed1..63ef485 100644 (file)
-from _common import *
-from django.utils.translation import ugettext as _
-from search import *
-
-#-----------------------------------------------------------------------------
-
-def welcome(request):
-    return g.render('welcome.xhtml')
-
-# MARK: propose we get rid of this. We already have a 'Courses' browser.
-def open_courses(request):
-    page_num = int(request.GET.get('page', 1))
-    count = int(request.GET.get('count', 5))
-    paginator = Paginator(models.Course.objects.all(), count) # fixme, what filter?
-    return g.render('open_courses.xhtml', paginator=paginator,
-                    page_num=page_num,
-                    count=count)
-# MARK: propose we drop this too. We have a browse.
-def instructors(request):
-    page_num = int(request.GET.get('page', 1))
-    count = int(request.GET.get('count', 5))
-    action = request.GET.get('action', 'browse')
-    if action == 'join':
-        paginator = Paginator(models.User.active_instructors(), count)
-    elif action == 'drop':
-        paginator = Paginator(models.Course.objects.all(), count) # fixme, what filter?
-    else:
-        paginator = Paginator(models.Course.objects.all(), count) # fixme, what filter?
-        
-    return g.render('instructors.xhtml', paginator=paginator,
-                    page_num=page_num,
-                    count=count)
-
-def instructor_search(request, instructor):
-    return search(request, with_instructor=instructor)
-
-# MARK: propose we get rid of this. We have browse.
-def departments(request):
-    raise NotImplementedError
-
-
-def user_prefs(request):
-    if request.method != 'POST':
-        return g.render('prefs.xhtml')
-    else:
-        profile = request.user.get_profile()
-        profile.wants_email_notices = bool(request.POST.get('wants_email_notices'))
-        profile.save()
-        return HttpResponseRedirect('../')
-
-def z3950_test(request):
-    #testing JZKitZ3950 - it seems to work, but i have a character set problem
-    #with the returned marc
-    #nope - the problem is weak mapping with the limited solr test set
-    #i think this can be sorted out
-
-    #conn = zoom.Connection ('z3950.loc.gov', 7090)
-    #conn = zoom.Connection ('webvoy.uwindsor.ca', 9000)
-    #solr index with JZKitZ3950 wrapping
-    conn = zoom.Connection ('127.0.0.1', 2100)
-    # conn = zoom.Connection ('127.0.0.1', 2100)
-    print("connecting...")
-    conn.databaseName = 'Test'
-    # conn.preferredRecordSyntax = 'XML'
-    conn.preferredRecordSyntax = 'USMARC'
-    query = zoom.Query ('CCL', 'ti="agar"')
-    res = conn.search (query)
-    collector = []
-    # if we wanted to get into funkiness
-    m = zmarc.MARC8_to_Unicode ()
-    for r in res:
-        print(type(r.data))
-        print(type(m.translate(r.data)))
-        rec = zmarc.MARC (r.data, strict=0)
-        # rec = zmarc.MARC (rec, strict=0)
-        collector.append(str(rec))
-
-    conn.close ()
-    res_str = "" . join(collector)
-    return g.render('z3950_test.xhtml', res_str=res_str)
-
-def browse(request, browse_option=''):
-    #the defaults should be moved into a config file or something...
-    page_num = int(request.GET.get('page', 1))
-    count    = int(request.GET.get('count', 5))
-
-    if browse_option == '':
-        queryset = None
-        template = 'browse_index.xhtml'
-    elif browse_option == 'instructors':
-        queryset = models.User.active_instructors()
-        queryset = queryset.filter(user_filters(request.user)['instructors'])
-        template = 'instructors.xhtml'
-    elif browse_option == 'departments':
-        queryset = models.Department.objects.filter(active=True)
-        template = 'departments.xhtml'
-    elif browse_option == 'courses':
-        # fixme, course filter should not be (active=True) but based on user identity.
-        for_courses = user_filters(request.user)['courses']
-        queryset = models.Course.objects.filter(for_courses)
-        template = 'courses.xhtml'
-
-    queryset = queryset and queryset.distinct()
-    paginator = Paginator(queryset, count)
-    return g.render(template, paginator=paginator,
-                    page_num=page_num,
-                    count=count)
-
-@login_required
-def my_courses(request):
-    return g.render('my_courses.xhtml')
-
-def instructor_detail(request, instructor_id):
-    page_num = int(request.GET.get('page', 1))
-    count = int(request.GET.get('count', 5))
-    '''
-    i am not sure this is the best way to go from instructor
-    to course
-    '''
-    courses = models.Course.objects.filter(member__user=instructor_id,
-                                           member__role='INSTR')
-    filters = user_filters(request.user)
-    courses = courses.filter(filters['courses'])
-    paginator = Paginator(courses.order_by('title'), count)
-
-    '''
-    no concept of active right now, maybe suppressed is a better
-    description anyway?
-    '''
-        # filter(active=True).order_by('title'), count)
-    instructor = models.User.objects.get(pk=instructor_id)
-    return g.render('courses.xhtml', 
-                    custom_title=_('Courses taught by %s') % instructor.get_full_name(),
-                    paginator=paginator,
-                    page_num=page_num,
-                    count=count)
-
-def department_detail(request, department_id):
-    page_num = int(request.GET.get('page', 1))
-    count = int(request.GET.get('count', 5))
-    paginator = Paginator(models.Course.objects.
-        filter(department__id=department_id).
-        filter(active=True).order_by('title'), count)
-
-    return g.render('courses.xhtml', paginator=paginator,
-            page_num=page_num,
-            count=count)
-
+from _common import *\r
+from django.utils.translation import ugettext as _\r
+from search import *\r
+from lxml import etree\r
+import libxml2\r
+import libxslt\r
+import os\r
+\r
+\r
+BASE_DIRECTORY = os.path.abspath(os.path.dirname(__file__))\r
+HERE = lambda s: os.path.join(BASE_DIRECTORY, s)\r
+\r
+\r
+#-----------------------------------------------------------------------------\r
+\r
+def welcome(request):\r
+    return g.render('welcome.xhtml')\r
+\r
+# MARK: propose we get rid of this. We already have a 'Courses' browser.\r
+def open_courses(request):\r
+    page_num = int(request.GET.get('page', 1))\r
+    count = int(request.GET.get('count', 5))\r
+    paginator = Paginator(models.Course.objects.all(), count) # fixme, what filter?\r
+    return g.render('open_courses.xhtml', paginator=paginator,\r
+                    page_num=page_num,\r
+                    count=count)\r
+# MARK: propose we drop this too. We have a browse.\r
+def instructors(request):\r
+    page_num = int(request.GET.get('page', 1))\r
+    count = int(request.GET.get('count', 5))\r
+    action = request.GET.get('action', 'browse')\r
+    if action == 'join':\r
+        paginator = Paginator(models.User.active_instructors(), count)\r
+    elif action == 'drop':\r
+        paginator = Paginator(models.Course.objects.all(), count) # fixme, what filter?\r
+    else:\r
+        paginator = Paginator(models.Course.objects.all(), count) # fixme, what filter?\r
+        \r
+    return g.render('instructors.xhtml', paginator=paginator,\r
+                    page_num=page_num,\r
+                    count=count)\r
+\r
+def instructor_search(request, instructor):\r
+    return search(request, with_instructor=instructor)\r
+\r
+# MARK: propose we get rid of this. We have browse.\r
+def departments(request):\r
+    raise NotImplementedError\r
+\r
+\r
+def user_prefs(request):\r
+    if request.method != 'POST':\r
+        return g.render('prefs.xhtml')\r
+    else:\r
+        profile = request.user.get_profile()\r
+        profile.wants_email_notices = bool(request.POST.get('wants_email_notices'))\r
+        profile.save()\r
+        return HttpResponseRedirect('../')\r
+\r
+def z3950_test(request):\r
+    styledoc = libxml2.parseFile('/conifer/syrupsvn/trunk/conifer/static/xslt/test.xsl')\r
+    styledoc = libxml2.parseFile(HERE('../../static/xslt/test.xsl'))\r
+    test = libxslt.parseStylesheetDoc(styledoc)\r
+    #return g.render('z3950_test.xhtml', res_str="")\r
+\r
+    #testing JZKitZ3950 - it seems to work, but i have a character set problem\r
+    #with the returned marc\r
+    #nope - the problem is weak mapping with the limited solr test set\r
+    #i think this can be sorted out\r
+\r
+    #conn = zoom.Connection ('z3950.loc.gov', 7090)\r
+    #conn = zoom.Connection ('webvoy.uwindsor.ca', 9000)\r
+    #solr index with JZKitZ3950 wrapping\r
+    conn = zoom.Connection ('zed.concat.ca', 210)\r
+    # conn = zoom.Connection ('127.0.0.1', 2100)\r
+    print("connecting...")\r
+    conn.databaseName = 'OWA'\r
+    conn.preferredRecordSyntax = 'XML'\r
+    # conn.preferredRecordSyntax = 'USMARC'\r
+    query = zoom.Query ('CCL', 'ti="agar"')\r
+    res = conn.search (query)\r
+    collector = []\r
+    # if we wanted to get into funkiness\r
+    m = zmarc.MARC8_to_Unicode ()\r
+    for r in res:\r
+        print(type(r.data))\r
+        print(type(m.translate(r.data)))\r
+        #rec = zmarc.MARC (r.data, strict=0)\r
+        # rec = zmarc.MARC (rec, strict=0)\r
+        #collector.append(str(rec))\r
+       #collector.append((m.translate(r.data)))\r
+       # print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")\r
+       zhit = str("<?xml version=\"1.0\"?>") + (m.translate(r.data))\r
+       #zhit = m.translate(r.data)\r
+       #doc = etree.fromstring(zhit)\r
+       #doc = libxml2.xmlNode(zhit)\r
+       doc = libxml2.parseDoc(zhit)\r
+       #print(str("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") + (m.translate(r.data)))\r
+       #print(zhit)\r
+       print(test.applyStylesheet(doc, None))\r
+\r
+    conn.close ()\r
+    res_str = "" . join(collector)\r
+    return g.render('z3950_test.xhtml', res_str=res_str)\r
+\r
+def browse(request, browse_option=''):\r
+    #the defaults should be moved into a config file or something...\r
+    page_num = int(request.GET.get('page', 1))\r
+    count    = int(request.GET.get('count', 5))\r
+\r
+    if browse_option == '':\r
+        queryset = None\r
+        template = 'browse_index.xhtml'\r
+    elif browse_option == 'instructors':\r
+        queryset = models.User.active_instructors()\r
+        queryset = queryset.filter(user_filters(request.user)['instructors'])\r
+        template = 'instructors.xhtml'\r
+    elif browse_option == 'departments':\r
+        queryset = models.Department.objects.filter(active=True)\r
+        template = 'departments.xhtml'\r
+    elif browse_option == 'courses':\r
+        # fixme, course filter should not be (active=True) but based on user identity.\r
+        for_courses = user_filters(request.user)['courses']\r
+        queryset = models.Course.objects.filter(for_courses)\r
+        template = 'courses.xhtml'\r
+\r
+    queryset = queryset and queryset.distinct()\r
+    paginator = Paginator(queryset, count)\r
+    return g.render(template, paginator=paginator,\r
+                    page_num=page_num,\r
+                    count=count)\r
+\r
+@login_required\r
+def my_courses(request):\r
+    return g.render('my_courses.xhtml')\r
+\r
+def instructor_detail(request, instructor_id):\r
+    page_num = int(request.GET.get('page', 1))\r
+    count = int(request.GET.get('count', 5))\r
+    '''\r
+    i am not sure this is the best way to go from instructor\r
+    to course\r
+    '''\r
+    courses = models.Course.objects.filter(member__user=instructor_id,\r
+                                           member__role='INSTR')\r
+    filters = user_filters(request.user)\r
+    courses = courses.filter(filters['courses'])\r
+    paginator = Paginator(courses.order_by('title'), count)\r
+\r
+    '''\r
+    no concept of active right now, maybe suppressed is a better\r
+    description anyway?\r
+    '''\r
+        # filter(active=True).order_by('title'), count)\r
+    instructor = models.User.objects.get(pk=instructor_id)\r
+    return g.render('courses.xhtml', \r
+                    custom_title=_('Courses taught by %s') % instructor.get_full_name(),\r
+                    paginator=paginator,\r
+                    page_num=page_num,\r
+                    count=count)\r
+\r
+def department_detail(request, department_id):\r
+    page_num = int(request.GET.get('page', 1))\r
+    count = int(request.GET.get('count', 5))\r
+    paginator = Paginator(models.Course.objects.\r
+        filter(department__id=department_id).\r
+        filter(active=True).order_by('title'), count)\r
+\r
+    return g.render('courses.xhtml', paginator=paginator,\r
+            page_num=page_num,\r
+            count=count)\r
+\r