Mercurial > hg > MPIWGWeb
changeset 169:2da62e93a1c6
fix editing related projects.
author | casties |
---|---|
date | Fri, 07 Jun 2013 12:47:11 +0200 |
parents | 07beb979e7e4 |
children | 485bf377913a |
files | MPIWGProjects.py zpt/project/edit_related_projects.zpt zpt/project/edit_related_projects_error.zpt zpt/project/edit_template.zpt zpt/project/related_project/edit_basic.zpt |
diffstat | 5 files changed, 125 insertions(+), 128 deletions(-) [+] |
line wrap: on
line diff
--- a/MPIWGProjects.py Fri Jun 07 11:32:05 2013 +0200 +++ b/MPIWGProjects.py Fri Jun 07 12:47:11 2013 +0200 @@ -712,128 +712,6 @@ - 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""" @@ -1809,6 +1687,122 @@ self.redirect(RESPONSE, 'manageImages') + 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 updateProjectMembers(self, updateResponsibleScientistsList=False): """Update project-member table.""" # projects are identified by id
--- a/zpt/project/edit_related_projects.zpt Fri Jun 07 11:32:05 2013 +0200 +++ b/zpt/project/edit_related_projects.zpt Fri Jun 07 12:47:11 2013 +0200 @@ -17,7 +17,7 @@ <!-- <td tal:content="item/objid" /> --> <td tal:content="item/getProjectTitle" /> <td> - <a tal:attributes="href string:$root/$proid/editRelatedProject">Edit</a><br/> + <a tal:attributes="href string:$root/$proid/edit">Edit</a><br/> <a tal:attributes="href string:$root/deleteRelatedProject?id=$proid">Delete</a> </td> </tr>
--- a/zpt/project/edit_related_projects_error.zpt Fri Jun 07 11:32:05 2013 +0200 +++ b/zpt/project/edit_related_projects_error.zpt Fri Jun 07 12:47:11 2013 +0200 @@ -1,8 +1,8 @@ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html metal:use-macro="here/edit_MPIWGProject_main/macros/page" xmlns:metal="http://xml.zope.org/namespaces/metal"> +<html metal:use-macro="here/edit_template/macros/page" xmlns:metal="http://xml.zope.org/namespaces/metal"> <head> -<tal:block metal:fill-slot="navsel" tal:define="global menusel string:description" /> +<tal:block metal:fill-slot="navsel" tal:define="global menusel string:relatedProjects" /> </head> <body> <tal:block metal:fill-slot="body">
--- a/zpt/project/edit_template.zpt Fri Jun 07 11:32:05 2013 +0200 +++ b/zpt/project/edit_template.zpt Fri Jun 07 12:47:11 2013 +0200 @@ -9,7 +9,7 @@ </head> <body tal:attributes="onload onload"> <h3 tal:condition="not:here/isActiveProject">(!!Project is not visible!!)</h3> - <h2 class="title">Edit project <i tal:content="here/getProjectTitle"/></h2> + <h2 class="title">Edit project <i><tal:block metal:define-slot="project_title" tal:content="here/getProjectTitle"/></i></h2> <metal:block metal:define-slot="navsel"/> <div class="mainnav"> <span tal:attributes="class python:test('basic'==menusel, 'mainmenusel', 'mainmenu')"><a
--- a/zpt/project/related_project/edit_basic.zpt Fri Jun 07 11:32:05 2013 +0200 +++ b/zpt/project/related_project/edit_basic.zpt Fri Jun 07 12:47:11 2013 +0200 @@ -5,6 +5,9 @@ </head> <body> <tal:block metal:fill-slot="navsel" tal:define="global menusel string:relatedProjects" /> + + <tal:block metal:fill-slot="project_title" tal:content="here/aq_parent/getProjectTitle"/> + <tal:block metal:fill-slot="body"> <h3>Edit related project</h3> <form action="editRelatedProject" method="post"> @@ -15,12 +18,12 @@ </tr> <tr> <td><b>Project title:</b></td> - <td tal:content="here/getLabel" /> + <td tal:content="here/getProjectLabel" /> </tr> <tr> <td><b>Link</b></td> <td> - <input size="100" tal:attributes="value python:getattr(here,'orginallink','')" name="link"/> + <input size="100" tal:attributes="value here/orginallink | nothing" name="link"/> <input type="submit" value="change" /> </td> </tr>