Mercurial > hg > documentViewer
changeset 413:ea9aaecd73f1
better getLink method
author | casties |
---|---|
date | Wed, 22 Dec 2010 12:54:46 +0100 |
parents | 759ed7577eef |
children | ad201f406dd1 |
files | documentViewer.py |
diffstat | 1 files changed, 36 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/documentViewer.py Mon Dec 20 14:52:07 2010 +0100 +++ b/documentViewer.py Wed Dec 22 12:54:46 2010 +0100 @@ -351,9 +351,8 @@ def getBrowser(self): """getBrowser the version of browser """ - names="" - names = browserCheck(self) - return names + bt = browserCheck(self) + return bt def findDigilibUrl(self): """try to get the digilib URL from zogilib""" @@ -372,41 +371,48 @@ else: return style - def getLink(self,param=None,val=None): - """link to documentviewer with parameter param set to val""" - params=self.REQUEST.form.copy() + def getLink(self, param=None, val=None, params=None, baseUrl=None, paramSep='&'): + """returns URL to documentviewer with parameter param set to val or from dict params""" + # copy existing request params + urlParams=self.REQUEST.form.copy() + # change single param if param is not None: if val is None: - if params.has_key(param): - del params[param] + if urlParams.has_key(param): + del urlParams[param] else: - params[param] = str(val) + urlParams[param] = str(val) - if params.get("mode", None) == "filepath": #wenn beim erst Aufruf filepath gesetzt wurde aendere das nun zu imagepath - params["mode"] = "imagepath" - params["url"] = getParentDir(params["url"]) + # change more params + if params is not None: + for k in params.keys(): + v = params[k] + if v is None: + # val=None removes param + if urlParams.has_key(k): + del urlParams[k] + + else: + urlParams[k] = v + + # FIXME: does this belong here? + if urlParams.get("mode", None) == "filepath": #wenn beim erst Aufruf filepath gesetzt wurde aendere das nun zu imagepath + urlParams["mode"] = "imagepath" + urlParams["url"] = getParentDir(urlParams["url"]) - # quote values and assemble into query string - #ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) - ps = urllib.urlencode(params) - url=self.REQUEST['URL1']+"?"+ps + # quote values and assemble into query string (not escaping '/') + ps = paramSep.join(["%s=%s"%(k,urllib.quote_plus(v,'/')) for (k, v) in urlParams.items()]) + #ps = urllib.urlencode(urlParams) + if baseUrl is None: + baseUrl = self.REQUEST['URL1'] + + url = "%s?%s"%(baseUrl, ps) return url - def getLinkAmp(self,param=None,val=None): + + def getLinkAmp(self, param=None, val=None, params=None, baseUrl=None): """link to documentviewer with parameter param set to val""" - params=self.REQUEST.form.copy() - if param is not None: - if val is None: - if params.has_key(param): - del params[param] - else: - params[param] = str(val) - - # quote values and assemble into query string - logging.debug("XYXXXXX: %s"%repr(params.items())) - ps = "&".join(["%s=%s"%(k,urllib.quote(v)) for (k, v) in params.items()]) - url=self.REQUEST['URL1']+"?"+ps - return url + return self.getLink(param, val, params, baseUrl, '&') def getInfo_xml(self,url,mode): """returns info about the document as XML"""