changeset 19:cce127a28fc9

added getpurls
author dwinter
date Wed, 21 Nov 2012 15:39:08 +0100
parents 1eb5e3f6444b
children cf4503528b5e
files managePurls/manageIndexMetaPURLs.py restService/config.py restService/getPurls.py restService/restService.py restService/templates/registerPurls.html restService/templates/registeredPurlsResponse.html restService/templates/serviceDescription.html
diffstat 7 files changed, 109 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/managePurls/manageIndexMetaPURLs.py	Mon Nov 19 12:14:25 2012 +0100
+++ b/managePurls/manageIndexMetaPURLs.py	Wed Nov 21 15:39:08 2012 +0100
@@ -38,7 +38,8 @@
     
   
     def __init__(self):
-        self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="p*lWa55eR", host="tuxserve03")
+        #self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="p*lWa55eR", host="tuxserve03")
+        self.purlDB = web.database(dbn="postgres", db="purlDB",user="purlUSER",password="3333")
       
  
     
@@ -191,11 +192,15 @@
         
         return update
     
-    def register(self,path,isIndexMeta,imagePath="",server_url="",user="",update=False):
+    def register(self,path=None,isIndexMeta=False,imagePath="",server_url="",user="",update=False):
         
         
         #teste ob es zu dem Pfad schon eine Purl gibt
-        purl = self.getPurl(path)
+        
+        if path: # wenn ein pfad definiert ist teste ob es schon eine purl dazu gibt.
+            purl = self.getPurl(path)
+        else:
+            purl =None
         if purl!=None:
             
             if update:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/restService/config.py	Wed Nov 21 15:39:08 2012 +0100
@@ -0,0 +1,3 @@
+#TEMPLATE_PATH="/usr/local/metadataServices/purlService/restService/templates/"
+TEMPLATE_PATH="/Users/dwinter/Documents/Projekte/MetaDataManagement/purlService/restService/templates/"
+TEXTER_URL="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Texter?fn=%s"
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/restService/getPurls.py	Wed Nov 21 15:39:08 2012 +0100
@@ -0,0 +1,63 @@
+'''
+Register purls at the server
+Created on 22.11.2012
+
+@author: dwinter
+'''
+
+import web
+import base64
+import re
+import config
+from managePurls.manageIndexMetaPURLs import IndexMetaPURLManager
+
+class getPurls:
+    
+    def __init__(self):
+        self.render = web.template.render(config.TEMPLATE_PATH)
+        self.purlManager = IndexMetaPURLManager()
+        
+    def GET(self):
+       
+        auth = web.ctx.env.get('HTTP_AUTHORIZATION')
+      
+        authreq = False
+        if auth is None:
+            authreq = True
+        else:
+            print auth
+            auth = re.sub('^Basic ','',auth)
+            username,password = base64.decodestring(auth).split(':')
+            
+            
+        if authreq:
+            web.header('WWW-Authenticate','Basic realm="Auth example"')
+            web.ctx.status = '401 Unauthorized'
+            return
+        
+        return self.render.registerPurls(username)
+    
+    def POST(self):
+        inp = web.input()
+        
+        username=inp.get("userName",None)
+        amount=inp.get("amount",None)
+        
+        if (username==None) or (amount==None):
+            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:
+            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)
+        
--- a/restService/restService.py	Mon Nov 19 12:14:25 2012 +0100
+++ b/restService/restService.py	Wed Nov 21 15:39:08 2012 +0100
@@ -3,12 +3,17 @@
 
 @author: dwinter
 '''
+
+
 import web
 import managePurls.manageIndexMetaPURLs as manageIndexMetaPURLs
 from redirector import redirector 
 import logging
 from searcher import searcher
 from searchService.searchLines import searchLines
+from getPurls import getPurls
+import config
+
 
 urls = (
     '/purl/(.+)','purl',
@@ -17,20 +22,22 @@
     '/indexMeta/(.+)','indexMeta',
     '/','serviceDescription',
     '/searchLines','searchLines',
-    '/searchLines/annotator/search','searchLines'
+    '/searchLines/annotator/search','searchLines',
+    '/getPurls','getPurls'
 )
 
+
 app = web.application(urls, globals())
 
 
-TEXTER_URL="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Texter?fn=%s"
+
 
 
 
 class serviceDescription:
     
     def __init__(self):
-        self.render = web.template.render('/usr/local/metadataServices/purlService/restService/templates/')
+        self.render = web.template.render(config.TEMPLATE_PATH)
     def GET(self):
         
         return self.render.serviceDescription()
@@ -55,7 +62,7 @@
             return web.notfound("PURL currently not VALID try later!")
        
         
-        raise web.redirect(TEXTER_URL%path)
+        raise web.redirect(config.TEXTER_URL%path)
 
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/restService/templates/registerPurls.html	Wed Nov 21 15:39:08 2012 +0100
@@ -0,0 +1,8 @@
+$def with (username)
+<h2>Create Purls</h2>
+
+<form method="post">
+<div>Username (if existing your mpiwg username):<input type="text" size="30" name="userName" value="$username"></div>
+<div>How many PURLS do you need (maximum 10):<input type="text" size="5" name="amount"></div>
+<div><input type="submit"/></div>
+</form>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/restService/templates/registeredPurlsResponse.html	Wed Nov 21 15:39:08 2012 +0100
@@ -0,0 +1,6 @@
+$def with (purls)
+
+<h1>New Purls:</h1>
+
+$for i in range(len(purls)):
+	<div>$purls[i][1]</div>
\ No newline at end of file
--- a/restService/templates/serviceDescription.html	Mon Nov 19 12:14:25 2012 +0100
+++ b/restService/templates/serviceDescription.html	Wed Nov 21 15:39:08 2012 +0100
@@ -35,4 +35,13 @@
 <h3>/indexMeta/PURL</h3>
 <p>
 Redirects to the index.meta file of the source, if existing.
-</p>
\ No newline at end of file
+</p>
+
+
+<h3>/getPurls</h3>
+get new purls
+
+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
+