--- MPIWGWeb/MPIWGProjects.py 2008/09/08 09:20:26 1.47.2.104 +++ MPIWGWeb/MPIWGProjects.py 2008/10/23 10:02:09 1.47.2.108 @@ -20,8 +20,10 @@ from OFS.SimpleItem import SimpleItem from OFS.Folder import Folder from OFS.Image import Image from AccessControl import ClassSecurityInfo +from AccessControl import getSecurityManager from bibliography import * import time +from OFS.Cache import Cacheable #import xml.dom.minidom import sys #from Ft.Xml.XPath import Evaluate @@ -111,7 +113,7 @@ class MPIWGProject_image(Image): if RESPONSE: RESPONSE.redirect("../manageImages") -class MPIWGProject(CatalogAware,Folder): +class MPIWGProject(CatalogAware,Folder,Cacheable): """Class for Projects""" @@ -379,6 +381,7 @@ class MPIWGProject(CatalogAware,Folder): def hasChildren(self,date=None,onlyActive=1,onlyArchived=1): """check if project has children""" + ct=self.getContexts(childs=self.getContent('xdata_05'), depth=1,date=date,onlyActive=onlyActive) @@ -613,19 +616,23 @@ class MPIWGProject(CatalogAware,Folder): return True; else: return False; + def getCompletedAt(self): """gibt das transformierte Datum zurueck, an dem das Projekt beendet wurde.""" date=getattr(self,'completedAt','') + if date: return self.reTransformDate(date); else: + return "" # test ob parent abgeschlossen ist - - ct=self.getContexts(parents=self.getContent('xdata_05'),depth=1) - if (len(ct)>0): #is there are parent - - return ct[0][0].getCompletedAt() - return ''; + try: #TODO: ersetzte try except durch vernuenftige abfrage + ct=self.getContexts(parents=self.getContent('xdata_05'),depth=1) + if (len(ct)>0): #is there are parent + return ct[0][0].getCompletedAt() + return ''; + except: + return ''; def getStartedAt(self): """gibt das transformierte Datum zurŸck, an dem Projekt begonnen wurde.""" @@ -746,9 +753,66 @@ class MPIWGProject(CatalogAware,Folder): return pt() - + def index_html(self,request=True,context=None): """show homepage""" + + bound_names={} + + if not context: + context=self + if request: + if self.REQUEST.has_key('date') and self.REQUEST.SESSION.get('MPI_redirected',None)==None: + self.REQUEST.SESSION['MPI_redirected']=1 + self.REQUEST.RESPONSE.redirect(self.checkDate(self.REQUEST['date'])+"?date="+self.REQUEST['date']) + else: + self.REQUEST.SESSION['MPI_redirected']=None + + #ext=self.ZopeFind(self.aq_parent,obj_ids=["project_main"]) + + + request2=getattr(self,'REQUEST',None) + + if request2 is not None: + response = request2.response + if not response.headers.has_key('content-type'): + response.setHeader('content-type', 'text/html') + + security = getSecurityManager() + bound_names['user'] = security.getUser() + + + # Retrieve the value from the cache. + keyset = None + if self.ZCacheable_isCachingEnabled(): + + # Prepare a cache key. + keyset = {'here': self, 'params':request2['QUERY_STRING']} + + result = self.ZCacheable_get(keywords=keyset) + + if result is not None: + # Got a cached value. + return result + + pt = getTemplate(self, "project_main") + # Execute the template in a new security context. + security.addContext(self) + + try: + result = pt.pt_render(extra_context=bound_names) + if keyset is not None: + # Store the result in the cache. + self.ZCacheable_set(result, keywords=keyset) + + return result + finally: + security.removeContext(self) + + + + def index_html_old(self,request=True,context=None): + """show homepage""" if not context: context=self if request: @@ -910,6 +974,7 @@ class MPIWGProject(CatalogAware,Folder): return self.preview(newcontent) self.copyObjectToArchive() + self.ZCacheable_invalidate() self.WEB_project_description=newcontent[0:] self.REQUEST.RESPONSE.redirect("./index.html") @@ -962,6 +1027,7 @@ class MPIWGProject(CatalogAware,Folder): baseUrl = "/en/research/projects/" # add in the internal project hierarchy + ct=self.getContexts(parents=self.getContent('xdata_05')) # start with grandparents ct.reverse() @@ -976,6 +1042,7 @@ class MPIWGProject(CatalogAware,Folder): def getRootProject(self): """returns the root (=top level) project of the current project""" + ct=self.getContexts(parents=self.getContent('xdata_05')) if len(ct) > 0: return ct[-1][0] @@ -1119,7 +1186,7 @@ class MPIWGProject(CatalogAware,Folder): lastname=self.myCapitalize(lastname).encode('utf-8') logging.info("Search: %s %s %s"%(name,repr(firstname),repr(lastname))) try: - cataloggedNames=self.MembersCatalog({'firstName':firstname,'lastName':lastname}) + cataloggedNames=self.MembersCatalog(firstName=firstname,lastName=lastname) except: cataloggedNames=[] logging.error("ERROR: identifyNames %s %s"%sys.exc_info()[0:2]) @@ -1142,7 +1209,7 @@ class MPIWGProject(CatalogAware,Folder): """edit the project and archive the old version""" self.copyObjectToArchive() # archive the object - + self.ZCacheable_invalidate() for x in definedFields: if self.REQUEST.has_key(x):