Mercurial > hg > purlService
changeset 34:a25bfc49a068
added format parameter
author | dwinter |
---|---|
date | Wed, 23 Oct 2013 12:27:31 +0200 |
parents | ea7017439ab9 |
children | d3ecbfd21e06 |
files | restService/getPurls.py restService/images.py restService/templates/serviceDescription.html |
diffstat | 3 files changed, 22 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/restService/getPurls.py Thu Aug 15 09:02:04 2013 +0200 +++ b/restService/getPurls.py Wed Oct 23 12:27:31 2013 +0200 @@ -61,25 +61,41 @@ username=inp.get("userName",None) amount=inp.get("amount",None) + outFormat=inp.get("format","html") + if (username==None) or (amount==None): - raise web.badrequest("Username and amount have to be send!") + raise web.badrequest("UserName and amount have to be send!") try: amount=int(amount) except: raise web.badrequest("Amount is not an integer!") - if amount>10: + if amount>1000: raise web.badrequest("Amount is to large (maximum 10)") purls=[] for i in range(amount): purls.append(self.purlManager.register(user=username)) - - return self.render.registeredPurlsResponse(purls) - + if outFormat == "html": + return self.render.registeredPurlsResponse(purls) + elif outFormat == "plain": + ret="" + for p in purls: + ret+="%s\n"%p[1] + web.header('Content-Type', 'text/plain') + return ret + elif outFormat == "plain-noPrefix": + ret="" + for p in purls: + ret+="%s\n"%p[1].replace("MPIWG:","") + + web.header('Content-Type', 'text/plain') + return ret + else: + raise web.badrequest("Allowed parameters for format are only html, plain and plain-noPrefix. The default is html was %s.."%outFormat) class randomSearch: def __init__(self):
--- a/restService/images.py Thu Aug 15 09:02:04 2013 +0200 +++ b/restService/images.py Wed Oct 23 12:27:31 2013 +0200 @@ -36,7 +36,6 @@ path=doc.get('TT_image',None) - if (path is not None) and (not isinstance(path, basestring)): #TT_image was defined as multiple , shouldn't be the case ? path=path[0]
--- a/restService/templates/serviceDescription.html Thu Aug 15 09:02:04 2013 +0200 +++ b/restService/templates/serviceDescription.html Wed Oct 23 12:27:31 2013 +0200 @@ -50,7 +50,7 @@ GET: returns an simple web page to enter username and amount of purls needed -POST: expects the parameter "username" and "amount"", return list of purls +POST: expects the parameter "userName" and "amount"", return list of purls <h3>/purls/searchSolr?text-url-path=PATH</h3>