Mercurial > hg > ZopePubmanConnector
diff zopePubmanConnector.py @ 0:373e6610e290
initial
author | dwinter |
---|---|
date | Fri, 26 Apr 2013 19:07:19 +0200 |
parents | |
children | c6478f155400 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/zopePubmanConnector.py Fri Apr 26 19:07:19 2013 +0200 @@ -0,0 +1,102 @@ +# -*- coding: utf-8 -*- + +#Verbindet Zope mit pubman. + + +from OFS.SimpleItem import SimpleItem +from Products.PageTemplates.PageTemplateFile import PageTemplateFile +import os.path + +from Globals import package_home +import httplib2 +import urlparse +import urllib +import re +import xml.etree.ElementTree as ET +import json + +def zptFile(self, path, orphaned=False): + """returns a page template file from the product""" + if orphaned: + # unusual case + pt=PageTemplateFile(os.path.join(package_home(globals()), path)) + else: + + pt=PageTemplateFile(os.path.join(package_home(globals()), path)).__of__(self) + return pt + +class ZopePubmanConnector(SimpleItem): + + + connectorString="http://pubman.mpiwg-berlin.mpg.de/search/SearchAndExport?" + connectorString+="cqlQuery=escidoc.any-identifier=%22http://pubman.mpiwg-berlin.mpg.de/cone/persons/resource/303%22&" + connectorString+="exportFormat=APA&outputFormat=snippet&language=all&sortKeys=escidoc.any-dates&sortOrder=descending" + + + meta_type="ZopePubmanConnector" + + manage_options= ({'label':'Main Config','action': 'changeMain'},) + SimpleItem.manage_options + + def __init__(self,id,title,pubmanURL): + self.id=id + self.title=title + self.pubmanURL=pubmanURL #URL einer pubman instance bzw. einer collection, falls nicht die default collection benutzt werden soll + + + + def changeMain(self,pubmanURL=None,title=None,REQUEST=None,RESPONSE=None): + """change main settings""" + if pubmanURL: + self.pubmanURL=pubmanURL + self.title=title + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + + else: + pt=zptFile(self, 'zpt/ChangeZopePubmanConnector.zpt') + return pt() + + + def getPublications(self,personID): + """get all publications der personID""" + h = httplib2.Http() + resp, content = h.request(self.connectorString) + ET.register_namespace("dcterms", "http://purl.org/dc/terms/") + + root = ET.fromstring(content) + + citationxpath=".//{http://purl.org/dc/terms/}bibliographicCitation" + + citations=root.findall(citationxpath) + + ret=[] + + for citation in citations: + ret.append(citation.text) + + + + return ret + + def pubmanConnectorURL(self): + return self.connectorString + +def manage_addZopePubmanConnectorForm(self): + """Form for external Links""" + pt=zptFile(self, 'zpt/AddZopePubmanConnector.zpt') + return pt() + + +def manage_addZopePubmanConnector(self,id,title,pubmanURL,RESPONSE=None): + """Add an external Link""" + + newObj=ZopePubmanConnector(id,title,pubmanURL) + + self._setObject(id,newObj) + + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + \ No newline at end of file