--- basket/basket.py 2006/04/06 16:49:14 1.8 +++ basket/basket.py 2007/08/15 15:49:03 1.14 @@ -22,9 +22,10 @@ from Globals import Persistent, package_ from Acquisition import Implicit from Products.ZCatalog.CatalogPathAwareness import CatalogAware - from groups import manage_addGroupFolder +from Products.ECHO_content.ECHO_helpers import unicodify + refBasis="http://vlp.mpiwg-berlin.mpg.de/references?id=%s" basketMetatypes=['BasketXRef','BasketInternalLink','BasketExternalLink','BasketText','BasketFile'] @@ -39,6 +40,16 @@ class BasketBasis(OrderedFolder): security=ClassSecurityInfo() + def content_html(self,type): + """generische ausgabe des objectes als html""" + if hasattr(self,type+"_template"): + obj=getattr(self,type+"_template") + return obj() + else: + pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','%s_template_standard.zpt'%type)).__of__(self) + pt.content_type="text/html" + return pt() + def checkPermission(self,modus): """check permission""" if modus=='open': @@ -131,9 +142,11 @@ class BasketBasis(OrderedFolder): def getOwner(self): """get Owner as string""" - return self.owner + return unicodify(self.owner) - + def getTitle(self): + """get title""" + return unicodify(self.title) def getActualUserName(self): """get username of actual user""" @@ -141,11 +154,13 @@ class BasketBasis(OrderedFolder): def getObjects(self): """"get objects""" - return [getattr(self,x['id']) for x in self._objects] + return self.objectValues() + #return [getattr(self,x['id']) for x in self._objects] def numberOfObjects(self): """anzahl der elemente im basket""" return len(self._objects) + class BasketFolder(BasketBasis): """Folder for Baskets""" @@ -167,9 +182,7 @@ class BasketFolder(BasketBasis): elif mode=='open_intern': print "open_intern" if self.checkPermission('authorized'): - print "---public" for object in self.getObjects(): - print object.getId(),object.publicationStatus if object.publicationStatus=='open_intern' or object.publicationStatus=='open': ret.append(object) return ret @@ -202,8 +215,8 @@ class BasketFolder(BasketBasis): #check if user has right for other modi if hasattr(self,"BasketFolder_template"): - obj=getattr(self,"BaskeFolder_template") - return obj() + obj=getattr(self,"BasketFolder_template") + return obj(mode=mode) else: pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','BasketFolder_template_standard.zpt')).__of__(self) pt.content_type="text/html" @@ -278,7 +291,7 @@ class Basket(BasketBasis): """return the save button""" ret=""" save - + onClick="forms.changeSetContents.actualId.value='%s';forms.changeSetContents.submit();">save - """%actualId return ret @@ -296,13 +309,14 @@ class Basket(BasketBasis): def getBasketObjects(self): """get all basket objects""" - - objs=self.getObjects() - ret=[] - for x in objs: - if x.meta_type in basketMetatypes: - ret.append(x) - return ret +# objs=self.getObjects() +# ret=[] +# for x in objs: +# if x.meta_type in basketMetatypes: +# ret.append(x) +# return ret + return self.objectValues(basketMetatypes) + def checkRef(self,xref): """check if XRef is already in Basket""" @@ -331,11 +345,16 @@ class Basket(BasketBasis): self.publicationStatus=publicationStatus self.shortDescription=shortDescription + + def getComment(self): + """get the comment""" + return unicodify(self.title) - - def getTitle(self): - """print name""" - return self.title + + def getShortDescription(self): + """get the short description""" + return unicodify(self.shortDescription) + security.declareProtected('Manage','changeBasketForm') def changeBasketForm(self): @@ -496,6 +515,15 @@ class BasketObject(SimpleItem): self.id=id self.title=title self.comment=comment + + def getTitle(self): + """get the title""" + return unicodify(self.title) + + def getComment(self): + """get the comment""" + return unicodify(self.comment) + def changeBasketBasisForm(self): """form for changing the basket""" @@ -544,13 +572,19 @@ class BasketFile(BasketObject,File): def download(self): """download the file""" + self.REQUEST.RESPONSE.setHeader("Content-Disposition","""attachement; filename=%s"""%self.title) self.REQUEST.RESPONSE.setHeader("Content-Type","application/octet-stream") self.content_type="application/octet-stream" - self.REQUEST.RESPONSE.write(self.data) - - + try: + self.REQUEST.RESPONSE.write(self.data) + except: + try: + self.REQUEST.RESPONSE.write(str(self.data)) + except: + self.REQUEST.RESPONSE.write(repr(self.data)) + def upDateFile(self,fileUpload=None,comment=None,title="",REQUEST=None): """update file""" @@ -577,7 +611,7 @@ class BasketFile(BasketObject,File): """format object as html fragment""" - return BasketBasis.content_html(self,"BasketFile") + return BasketObject.content_html(self,"BasketFile") def manage_addBasketFile(self,id,title,comment,fileUpload,content_type='',precondition='',REQUEST=None): """add a basket file""" @@ -638,7 +672,7 @@ class BasketXRef(BasketObject): """format object as html fragment""" type=self.xref[0:3] - return BasketBasis.content_html(self,"BasketXRef_%s"%type) + return BasketObject.content_html(self,"BasketXRef_%s"%type) def manage_addBasketXRefForm(self): """form for adding a basket""" @@ -663,7 +697,7 @@ class BasketInternalLink(BasketObject): #security=ClassSecurityInfo() meta_type="BasketInternalLink" - manage_options=BasketBasis.manage_options+( + manage_options=BasketObject.manage_options+( {'label':'manage internal link','action':'changeBasketInternalLinkForm'}, ) @@ -688,7 +722,7 @@ class BasketInternalLink(BasketObject): def content_html(self): """format object as html fragment""" - return BasketBasis.content_html(self,"BasketInternalLink") + return BasketObject.content_html(self,"BasketInternalLink") def linkToObject(self): """link to the object (internalLink)""" @@ -719,9 +753,13 @@ class BasketExternalLink(BasketObject): #security=ClassSecurityInfo() meta_type="BasketExternalLink" - manage_options=BasketBasis.manage_options+( + manage_options=BasketObject.manage_options+( {'label':'manage internal link','action':'changeBasketExternalLinkForm'}, ) + + def getLinkText(self): + """get the link text""" + return unicodify(self.linkText) def changeBasketExternalLinkForm(self): """form for changing the basket""" @@ -744,7 +782,7 @@ class BasketExternalLink(BasketObject): def content_html(self): """format object as html fragment""" - return BasketBasis.content_html(self,"BasketExternalLink") + return BasketObject.content_html(self,"BasketExternalLink") def linkToObject(self): """link to the object (externalLink)""" @@ -787,14 +825,9 @@ def manage_addBasketTextForm(self): def manage_addBasketText(self,id,title,comment,RESPONSE=None): """add a basketXRef object""" - newObj=BasketText(id,title,comment) self._setObject(id,newObj) if RESPONSE is not None: RESPONSE.redirect('manage_main') - - - - \ No newline at end of file