changeset 131:c5761a3f3c50

Merge with 741ddaf604b14515efacec8c3110ea04635c1b17
author casties
date Thu, 30 May 2013 22:14:00 +0200
parents 06020bd06a7d (current diff) 741ddaf604b1 (diff)
children 1dc5fee412da
files
diffstat 4 files changed, 164 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MPIWGProjects.py	Thu May 30 22:13:20 2013 +0200
+++ b/MPIWGProjects.py	Thu May 30 22:14:00 2013 +0200
@@ -711,6 +711,129 @@
         return sorted(items, key=lambda x:int(getattr(x, 'place', 0)))
 
 
+
+    def scaleImage(self,REQUEST=None,RESPONSE=None):
+        """scale the last image"""
+        from PIL import Image;
+        from cStringIO import  StringIO;
+        import ImageFilter
+        
+        
+        
+        
+        images = self.getImageList();
+        if len(images)>0:
+            img = images[-1] #nimmt das letze
+            
+            logging.debug(img)
+            datStringIO = StringIO();
+            """
+            data=img.data
+            if isinstance(data, str):
+                    datStringIO.write(data)
+            else:
+                
+                while data is not None:
+                        datStringIO.write(data.data)
+                        data=data.next
+
+            """
+            
+            logging.debug(img.absolute_url())
+            
+            url = img.absolute_url()
+            if not url.startswith("http"):
+                url=REQUEST['URL0']+url
+            ul = urllib.urlopen(url)
+            datStringIO = StringIO(ul.read());
+            
+            
+            try:
+                pilImg = Image.open(datStringIO)
+               
+               
+            except:
+                 logging.error("scale image input:"+self.getId())
+                 return
+                
+            w,h = pilImg.size
+            logging.debug("oldsize: %s %s"%(w,h))
+            targetW=120.
+            targetH=75.
+            
+            if targetW == w and targetH == h:
+                return
+            facW=targetW/w 
+            
+            h1 = int(h*facW)
+            
+            if h1<targetH: #bild zu klein in h
+                facH=targetH/h
+                
+                w1=int(w*facH)
+                 
+                fs = min(max(int(1/facH)+1,3),10)
+                logging.debug(fs)
+                if (1/facH) > 2:
+                        pilImg = pilImg.filter(ImageFilter.BLUR)
+             
+                try:
+                    pilImg = pilImg.filter(ImageFilter.MaxFilter(fs))
+                except:
+                    pilImg = pilImg.filter(ImageFilter.MaxFilter(fs-1))
+               
+                logging.debug("Xnew size: %s %s"%(w1,targetH))
+                res = pilImg.resize((w1,int(targetH)),Image.ANTIALIAS);
+                
+                
+            else:
+                fs = min(max(int(1/facW)+1,3),10)
+                logging.debug(fs)
+                
+                if (1/facW) > 2:
+                    try:
+                        pilImg = pilImg.filter(ImageFilter.BLUR)
+                    except:
+                        pass #some image types cannot be filter, just ignore
+                    
+                try:
+                    pilImg = pilImg.filter(ImageFilter.MaxFilter(fs))
+                except:
+                    
+                    
+                    try:
+                        pilImg = pilImg.filter(ImageFilter.MaxFilter(fs-1))
+                    except:
+                        pass
+                logging.debug("ynew size: %s %s"%(targetW,h1))
+                res = pilImg.resize((int(targetW),h1))
+                
+            nw,nh = res.size
+               
+            cutW1=int(nw/2-(targetW/2))  
+            cutW2=int(nw/2+(targetW/2))   
+            
+            cutH1=int(nh/2-(targetH/2))   
+            cutH2=int(nh/2+(targetH/2))    
+           
+            
+            
+            res2 = res.crop((cutW1,cutH1,cutW2,cutH2))
+            
+            outS =  StringIO()
+          
+            #res2.save("/tmp/"+self.getId()+".jpg")
+           
+            try:
+                res2.save(outS,"JPEG")
+            
+                self.addImage(outS, None, RESPONSE, filename="thumb.jpg")
+        
+            except:
+                logging.error("scale image:"+self.getId())
+        
+            
+        
     def addImage(self, fileHd, caption, RESPONSE=None, filename=None):
         """add an MPIWG_Project_image"""
 
@@ -724,7 +847,11 @@
 
         self._setObject(filename, newImage)
         obj = getattr(self, filename)
-        obj.caption = caption[:]
+        if caption is None:
+            obj.caption=None
+        else:
+            obj.caption = caption[:]
+            
         obj.enabled = True;
         obj.place = self._getLastImageNumber() + 1
         obj.id = filename
@@ -2068,7 +2195,14 @@
                 RESPONSE.flush()
         else:
             return fulllog
-                
+          
+    def scaleImages(self,REQUEST=None):
+        """scaleImages"""
+        prjs = self.getProjectsAsList()
+        for prj in prjs:
+            prj.scaleImage(REQUEST=REQUEST)
+            logging.debug(prj.getId())
+        
         
 def manage_addMPIWGProjectFolderForm(self):
     """form for adding a MPIWGProjectFolder"""
--- a/MPIWGRoot.py	Thu May 30 22:13:20 2013 +0200
+++ b/MPIWGRoot.py	Thu May 30 22:14:00 2013 +0200
@@ -517,6 +517,29 @@
                     fw.flush()
                 
             fw.close()
+            
+    def getBookLinkFromID(self,ident):
+        """holt die url auf eine buchseite, bekommt identifier MPIWG-Book:XXXX"""
+       
+        splitted = ident.split(":")
+        if len(splitted)!=2:
+            logging.debug("getBookLinkFromID: %s not a valid book id, should be MPIWG-Book:XXXX"%ident)
+            return
+        
+        books = getattr(self,'books',None)
+        if books is None:
+            logging.debug("getBookLinkFromID: cannot find books page folder")
+            return
+        
+        
+        bookobj = getattr(books,splitted[1],None)
+        
+        if bookobj is None:
+            logging.debug("getBookLinkFromID: %s not a valid book id"%ident)
+            return
+        
+    
+        return "books/"+splitted[1]
     
 
 def manage_addMPIWGRootForm(self):
--- a/MPIWGStaff.py	Thu May 30 22:13:20 2013 +0200
+++ b/MPIWGStaff.py	Thu May 30 22:14:00 2013 +0200
@@ -761,7 +761,7 @@
                     if not ((entry[1] == publicationType) or  (entry[1] == typesLongShort.get(publicationType,''))) : #stimmt nicht dann weiter
                         continue;
                     
-                pubs.append((selPub.escidocid,entry[0]));
+                pubs.append((selPub.escidocid,entry[0],entry[2]));
                 count+=1
                 
             return pubs
--- a/zpt/staff/pubman/show_publications.zpt	Thu May 30 22:13:20 2013 +0200
+++ b/zpt/staff/pubman/show_publications.zpt	Thu May 30 22:14:00 2013 +0200
@@ -29,8 +29,10 @@
       <tal:block>
         <h3>Books</h3>
         <ul class="plain">
-          <li class="reference" tal:repeat="book books"><a tal:attributes="href python:'http://pubman.mpiwg-berlin.mpg.de/pubman/faces/viewItemFullPage.jsp?itemId='+book[0]"><span
-                tal:replace="structure python:book[1]" /> </a>
+          <li class="reference" tal:repeat="book books"><div><a tal:attributes="href python:'http://pubman.mpiwg-berlin.mpg.de/pubman/faces/viewItemFullPage.jsp?itemId='+book[0]"><span
+                tal:replace="structure python:book[1]" /> </a></div>
+                <div tal:condition="python:book[2] is not None"><a tal:attributes="href python:'/en/resources/publications/'+here.getBookLinkFromID(book[2])">Book page</a></div>
+                
           </li>
         </ul>
       </tal:block>