changeset 546:2928037f9a75

ASSIGNED - # 249: Annotations shared in groups https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/249
author casties
date Tue, 28 Aug 2012 20:24:01 +0200
parents fc34eff7b52d
children 7c6fdc31bd35
files SrvTxtUtils.py documentViewer.py zpt/layer_text_annotator.zpt
diffstat 3 files changed, 52 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/SrvTxtUtils.py	Wed Aug 22 16:51:21 2012 +0200
+++ b/SrvTxtUtils.py	Tue Aug 28 20:24:01 2012 +0200
@@ -11,7 +11,7 @@
 import logging
 
 
-srvTxtUtilsVersion = "1.4.1"
+srvTxtUtilsVersion = "1.5"
 
 def getInt(number, default=0):
     """returns always an int (0 in case of problems)"""
@@ -37,7 +37,7 @@
         except:
             return s.decode('latin-1')
     else:
-        return unicode(s)
+        return s
 
 def utf8ify(s):
     """encode unicode object or string into byte string in utf-8 representation.
@@ -47,7 +47,7 @@
     if isinstance(s, str):
         return s
     else:
-        return unicode(s).encode('utf-8')
+        return s.encode('utf-8')
 
 def getText(node, recursive=0):
     """returns all text content of a node and its subnodes"""
@@ -75,7 +75,7 @@
 
 
 
-def getHttpData(url, data=None, num_tries=3, timeout=10):
+def getHttpData(url, data=None, num_tries=3, timeout=10, noExceptions=False):
     """returns result from url+data HTTP request"""
     # we do GET (by appending data to url)
     if isinstance(data, str) or isinstance(data, unicode):
@@ -116,6 +116,9 @@
         response.close()
         return data
     
+    if noExceptions:
+        return None
+    
     raise IOError("ERROR fetching HTTP data from %s: %s"%(url,errmsg))
     #return None
 
--- a/documentViewer.py	Wed Aug 22 16:51:21 2012 +0200
+++ b/documentViewer.py	Tue Aug 28 20:24:01 2012 +0200
@@ -126,8 +126,8 @@
     viewer_images = PageTemplateFile('zpt/viewer_images', globals())
     viewer_index = PageTemplateFile('zpt/viewer_index', globals())
     viewer_thumbs = PageTemplateFile('zpt/viewer_thumbs', globals())
-    # available layer types
-    builtinLayers = {'text': ['dict','search','gis','annotator'],
+    # available layer types (annotator not default)
+    builtinLayers = {'text': ['dict','search','gis'],
                      'xml': None, 'images': None, 'index': None}
     availableLayers = builtinLayers;
     # layer templates
@@ -316,18 +316,6 @@
         # and execute with parameters
         return pt(docinfo=docinfo, pageinfo=pageinfo)
   
-    #WTF?
-    def generateMarks(self,mk):
-        ret=""
-        if mk is None:
-            return ""
-        if not isinstance(mk, list):
-            mk=[mk]
-        for m in mk:
-            ret+="mk=%s"%m
-        return ret
-    
-    
     def getAvailableLayers(self):
         """returns dict with list of available layers per viewMode"""
         return self.availableLayers
@@ -985,6 +973,22 @@
         return batch
         
 
+    def getAnnotatorGroupsForUser(self, user, annotationServerUrl="http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager"):
+        """returns list of groups {name:*, id:*} on the annotation server for the user"""
+        groups = []
+        groupsUrl = "%s/annotator/groups?user=%s"%(annotationServerUrl,user)
+        data = getHttpData(url=groupsUrl, noExceptions=True)
+        if data:
+            res = json.loads(data)
+            rows = res.get('rows', None)
+            if rows is None:
+                return groups
+            for r in rows:
+                groups.append({'id': r.get('id', None), 'name': r.get('name', None), 'uri': r.get('uri', None)})
+                
+        return groups
+    
+
     security.declareProtected('View management screens','changeDocumentViewerForm')    
     changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
     
--- a/zpt/layer_text_annotator.zpt	Wed Aug 22 16:51:21 2012 +0200
+++ b/zpt/layer_text_annotator.zpt	Tue Aug 28 20:24:01 2012 +0200
@@ -33,8 +33,11 @@
     tal:attributes="src string:$rootUrl/template/annotator_files/lib/plugin/filter.js"></script> -->
 
   <script type="text/javascript" 
-    tal:define="annUrl python:'%s?url=%s&pn=%s'%(rootUrl,docinfo['url'],pageinfo['pn']); annUser python:here.getAuthenticatedUser(anon='anonymous');"
-    tal:content="structure string:var annotatorPageUrl='$annUrl'; var annotatorUser='$annUser';"></script>
+    tal:define="annUrl python:'%s?url=%s&pn=%s'%(rootUrl,docinfo['url'],pageinfo['pn']); 
+      global annUser python:here.getAuthenticatedUser(anon='anonymous');
+      global annGroup python:request.get('annotator_group', None);
+      permUser python:test(annGroup, 'group:%s'%annGroup, annUser);"
+    tal:content="structure string:var annotatorPageUrl='$annUrl'; var annotatorUser='$annUser'; var permissionUser='$permUser';"></script>
 
   <script type="text/javascript">
             // <!--
@@ -45,7 +48,7 @@
                 var devAnnotator = new Annotator(elem).addPlugin('Auth', {
                     tokenUrl : 'template/token?user='+annotatorUser
                 }).addPlugin('Permissions', {
-                    user : annotatorUser,
+                    user : permissionUser,
                     userString : function(user) {
                         if (user && user.name) {
                             return user.name;
@@ -59,7 +62,8 @@
                         return user;
                     }
                 }).addPlugin('Store', {
-                    prefix: 'http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator',
+                    //prefix: 'http://tuxserve03.mpiwg-berlin.mpg.de/AnnotationManager/annotator',
+                    prefix: 'http://r583-1.mpiwg-berlin.mpg.de:18080/AnnotationManager/annotator',
                     annotationData : {
                         'uri' : uri
                     },
@@ -88,9 +92,26 @@
 
   <metal:block metal:define-macro="options_box" tal:condition="python:'annotator' in viewLayers">
     <!-- BEGIN ANNOTATIONS -->
-    <div class="options" tal:define="annUser python:here.getAuthenticatedUser(anon='anonymous')">
+    <div class="options">
       <h4>Annotations</h4>
-      <div>You are user "<span tal:replace="annUser"/>"</div>
+      <p>
+        User "<span tal:replace="annUser" />"<span tal:condition="annGroup" tal:content="string: ($annGroup)"/>.
+      </p>
+      <!-- TODO: login button -->
+      <form class="autosubmit" tal:attributes="action viewerUrl">
+        <input type="hidden" tal:define="params python:here.getParams(params={'annotator_group':None});" tal:repeat="param params"
+          tal:attributes="name param; value python:params[param]" />
+        <p>
+          In group
+          <select class="autosubmit" name="annotator_group">
+            <option value="" tal:attributes="selected not:annGroup;"> </option>
+            <option
+              tal:repeat="group python:here.getAnnotatorGroupsForUser(user=annUser,annotationServerUrl='http://localhost:18080/AnnotationManager')"
+              tal:attributes="value group/id; selected python:group['id']==annGroup;" tal:content="group/name" />
+          </select> <br /> 
+          <input type="submit" value="Go!" />
+        </p>
+      </form>
     </div>
     <!-- END ANNOTATIONS -->
   </metal:block>