Mercurial > hg > documentViewer
changeset 561:9255acc4518d
CLOSED - # 256: display texts from different backends (sandbox)
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/256
author | casties |
---|---|
date | Mon, 01 Oct 2012 18:09:01 +0200 |
parents | 04c330b92cab |
children | 60f5a636bc57 |
files | MpdlXmlTextServer.py documentViewer.py zpt/manage_changeMpdlXmlTextServer.zpt |
diffstat | 3 files changed, 54 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/MpdlXmlTextServer.py Mon Oct 01 15:33:22 2012 +0200 +++ b/MpdlXmlTextServer.py Mon Oct 01 18:09:01 2012 +0200 @@ -32,11 +32,12 @@ manage_changeMpdlXmlTextServerForm = PageTemplateFile("zpt/manage_changeMpdlXmlTextServer", globals()) - def __init__(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40): + def __init__(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40, repositoryType='production'): """constructor""" self.id=id self.title=title self.timeout = timeout + self.repositoryType = repositoryType if serverName is None: self.serverUrl = serverUrl else: @@ -52,6 +53,10 @@ return getHttpData(url,data,timeout=self.timeout) + def getRepositoryType(self): + """returns the repository type, e.g. 'production'""" + return self.repositoryType + def getTextDownloadUrl(self, type='xml', docinfo=None): """returns a URL to download the current text""" docpath = docinfo.get('textURLPath', None) @@ -564,11 +569,13 @@ return tp - def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None): + def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,repositoryType=None,RESPONSE=None): """change settings""" self.title=title self.timeout = timeout self.serverUrl = serverUrl + if repositoryType: + self.repositoryType = repositoryType if RESPONSE is not None: RESPONSE.redirect('manage_main')
--- a/documentViewer.py Mon Oct 01 15:33:22 2012 +0200 +++ b/documentViewer.py Mon Oct 01 18:09:01 2012 +0200 @@ -33,6 +33,13 @@ # stream.close() return s +def getMDText(node): + """returns the @text content from the MetaDataProvider metadata node""" + if isinstance(node, dict): + return node.get('@text', None) + + return node + def browserCheck(self): """check the browsers request to find out the browser type""" bt = {} @@ -219,6 +226,10 @@ """returns one page of the table of contents""" return self.template.fulltextclient.getTocPage(**args) + def getRepositoryType(self, **args): + """get repository type""" + return self.template.fulltextclient.getRepositoryType(**args) + def getTextDownloadUrl(self, **args): """get list of gis places on one page""" return self.template.fulltextclient.getTextDownloadUrl(**args) @@ -570,7 +581,7 @@ docinfo = self.getDocinfoFromResource(docinfo, resource) # texttool info - texttool = self.metadataService.getTexttoolData(dom=metaDom) + texttool = self.metadataService.getTexttoolData(dom=metaDom, recursive=1, all=True) if texttool: docinfo = self.getDocinfoFromTexttool(docinfo, texttool) # document info (including toc) from full text @@ -675,9 +686,14 @@ def getDocinfoFromTexttool(self, docinfo, texttool): """reads contents of texttool element into docinfo""" + logging.debug("texttool=%s"%repr(texttool)) + # unpack list if necessary + if isinstance(texttool, list): + texttool = texttool[0] + # image dir - imageDir = texttool.get('image', None) - docPath = docinfo.get('documentPath', None) + imageDir = getMDText(texttool.get('image', None)) + docPath = getMDText(docinfo.get('documentPath', None)) if imageDir and docPath: #print "image: ", imageDir, " archivepath: ", archivePath imageDir = os.path.join(docPath, imageDir) @@ -685,29 +701,44 @@ docinfo['imagePath'] = imageDir # old style text URL - textUrl = texttool.get('text', None) + textUrl = getMDText(texttool.get('text', None)) if textUrl and docPath: if urlparse.urlparse(textUrl)[0] == "": #keine url textUrl = os.path.join(docPath, textUrl) docinfo['textURL'] = textUrl - # new style text-url-path - textUrl = texttool.get('text-url-path', None) - if textUrl: - docinfo['textURLPath'] = textUrl + # new style text-url-path (can be more than one with "repository" attribute) + textUrlNode = texttool.get('text-url-path', None) + if not isinstance(textUrlNode, list): + textUrlNode = [textUrlNode] + + for tun in textUrlNode: + textUrl = getMDText(tun) + if textUrl: + textUrlAtts = tun.get('@attr') + if (textUrlAtts and 'repository' in textUrlAtts): + textRepo = textUrlAtts['repository'] + # use matching repository + if self.getRepositoryType() == textRepo: + docinfo['textURLPath'] = textUrl + docinfo['textURLRepository'] = textRepo + + else: + # no repo attribute - use always + docinfo['textURLPath'] = textUrl # page flow - docinfo['pageFlow'] = texttool.get('page-flow', 'ltr') + docinfo['pageFlow'] = getMDText(texttool.get('page-flow', 'ltr')) # odd pages are left - docinfo['oddPage'] = texttool.get('odd-scan-position', 'left') + docinfo['oddPage'] = getMDText(texttool.get('odd-scan-position', 'left')) # number of title page (default 1) - docinfo['titlePage'] = texttool.get('title-scan-no', 1) + docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', 1)) # old presentation stuff - presentation = texttool.get('presentation', None) + presentation = getMDText(texttool.get('presentation', None)) if presentation and docPath: if presentation.startswith('http:'): docinfo['presentationUrl'] = presentation
--- a/zpt/manage_changeMpdlXmlTextServer.zpt Mon Oct 01 15:33:22 2012 +0200 +++ b/zpt/manage_changeMpdlXmlTextServer.zpt Mon Oct 01 18:09:01 2012 +0200 @@ -11,6 +11,8 @@ <p class="form-element"><input size="80" tal:attributes="value here/serverUrl | default" name="serverUrl"></p> <p class="form-optional">Timeout (s)</p> <p class="form-element"><input size="3" tal:attributes="value here/timeout | default" name="timeout"></p> + <p class="form-optional">Repository type</p> + <p class="form-element"><input size="10" tal:attributes="value here/repositoryType | default" name="repositoryType"></p> <p><input type="submit" value="change"></p> </form>