[ckan-changes] commit/ckanext-inspire: amercader: [api] Change the API controller to use the dataset harvest_object_id extra

Bitbucket commits-noreply at bitbucket.org
Mon Nov 14 15:52:04 UTC 2011


1 new commit in ckanext-inspire:


https://bitbucket.org/okfn/ckanext-inspire/changeset/3e7a6ade6542/
changeset:   3e7a6ade6542
user:        amercader
date:        2011-11-14 16:29:54
summary:     [api] Change the API controller to use the dataset harvest_object_id extra
affected #:  2 files

diff -r ea159df68832d02e512311c231aa732e729ac187 -r 3e7a6ade654279121d90e8e374e92b99a4586e30 ckanext/inspire/controllers/api.py
--- a/ckanext/inspire/controllers/api.py
+++ b/ckanext/inspire/controllers/api.py
@@ -4,6 +4,7 @@
 from pkg_resources import resource_stream, resource_filename
 from lxml import etree
 from ckan.model.meta import Session
+from ckan.model import Package,PackageExtra
 from ckan.lib.base import abort
 
 from ckanext.harvest.model import HarvestObject
@@ -14,35 +15,25 @@
 
 class ApiController(BaseApiController):
 
-    def _get_harvest_object(self,guid):
+    def _get_harvest_object(self,id):
+
         obj = Session.query(HarvestObject) \
-                        .filter(HarvestObject.guid==guid) \
-                        .filter(HarvestObject.package!=None) \
-                        .filter(HarvestObject.metadata_modified_date!=None) \
-                        .order_by(HarvestObject.metadata_modified_date.desc()) \
-                        .limit(1).first()
-        if not obj:
-            #Just in case metadata_modified_dates have not been yet set up
-            obj = Session.query(HarvestObject) \
-                            .filter(HarvestObject.guid==guid) \
-                            .filter(HarvestObject.package!=None) \
-                            .order_by(HarvestObject.gathered.desc()) \
-                            .limit(1).first()
+                        .filter(HarvestObject.id==id).first()
         return obj
 
-    def display_xml(self, guid):
-        doc = self._get_harvest_object(guid)
+    def display_xml(self,id):
+        obj = self._get_harvest_object(id)
 
-        if doc is None:
+        if obj is None:
             abort(404)
         response.content_type = "application/xml"
-        response.headers["Content-Length"] = len(doc.content)
-        return doc.content
+        response.headers["Content-Length"] = len(obj.content)
+        return obj.content
 
-    def display_html(self, guid):
-        doc = self._get_harvest_object(guid)
+    def display_html(self,id):
+        obj = self._get_harvest_object(id)
 
-        if doc is None:
+        if obj is None:
             abort(404)
         ## optimise -- read transform only once and compile rather
         ## than at each request
@@ -50,7 +41,7 @@
                              "xml/gemini2-html-stylesheet.xsl") as style:
             style_xml = etree.parse(style)
             transformer = etree.XSLT(style_xml)
-        more_than_meets_the_eyes = etree.parse(StringIO(doc.content.encode("utf-8")))
-        html = transformer(more_than_meets_the_eyes)
+        xml = etree.parse(StringIO(obj.content.encode("utf-8")))
+        html = transformer(xml)
         return etree.tostring(html, pretty_print=True)
 


diff -r ea159df68832d02e512311c231aa732e729ac187 -r 3e7a6ade654279121d90e8e374e92b99a4586e30 ckanext/inspire/plugin.py
--- a/ckanext/inspire/plugin.py
+++ b/ckanext/inspire/plugin.py
@@ -6,9 +6,9 @@
     def before_map(self, route_map):
         controller = "ckanext.inspire.controllers.api:ApiController"
 
-        route_map.connect("/api/2/rest/harvestobject/:guid/xml", controller=controller,
+        route_map.connect("/api/2/rest/harvestobject/:id/xml", controller=controller,
                           action="display_xml")
-        route_map.connect("/api/2/rest/harvestobject/:guid/html", controller=controller,
+        route_map.connect("/api/2/rest/harvestobject/:id/html", controller=controller,
                           action="display_html")

Repository URL: https://bitbucket.org/okfn/ckanext-inspire/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list