--- ECHO_content/VLPExtension.py 2004/06/04 10:04:16 1.5 +++ ECHO_content/VLPExtension.py 2004/08/05 13:51:32 1.15 @@ -1,10 +1,25 @@ -from ECHO_collection import * +from Products.ECHO_content.ECHO_collection import * from Products.PageTemplates.PageTemplateFile import PageTemplateFile from Products.PageTemplates.PageTemplate import PageTemplate from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate -from Products.zogiLib import zogiLib - +try: + from Products.zogiLib import zogiLib +except: + print "Zogilib not installed, VLP_resource will not work" + +import xml.dom.minidom +import urllib + +def makeXML(str): + try: + dom=xml.dom.minidom.parseString(str) + return str + except: + return """ + %s + """%str + def getText(nodelist): rc = "" @@ -13,6 +28,94 @@ def getText(nodelist): rc = rc + node.data return rc +class VLP_essay(Folder): + """classe für VLP essays""" + + meta_type="VLP_essay" + + manage_options = Folder.manage_options+( + {'label':'Main Config','action':'ConfigVLP_essayForm'}, + ) + + def content_html(self,type='collection'): + """template fuer content""" + #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"]) + # + #if templates: + # return templates[0][1]() + + if hasattr(self,type+"_template"): + obj=getattr(self,type+"_template") + return obj() + else: + pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_%s_template_standard.zpt'%type).__of__(self) + pt.content_type="text/html" + return pt() + + def ConfigVLP_essayForm(self): + """Form for adding""" + pt=PageTemplateFile('Products/ECHO_content/vlp/ChangeVLP_essay.zpt').__of__(self) + return pt() + + def ChangeVLP_essay(self,title,label,description,RESPONSE=None): + """Change vlp_essay""" + self.title=title + self.label=label + self.description=description + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + def __init__(self,id,title,label): + """init""" + self.id=id + self.title=title + self.label=label + + + def getPage(self,pagenum): + """gibt essay page mit num aus""" + def sortFind(x,y): + return cmp(x[0],y[0]) + + pages=self.ZopeFind(self,obj_metatypes=['DTML Document','File']) + + pages.sort(sortFind) + #print str(pages[int(pagenum)][1]()) + if pages[int(pagenum)-1][1].meta_type=='File': + return self.xml2html(makeXML(str(pages[int(pagenum)-1][1])),quote="no") + else: + return str(self.xml2html(makeXML(pages[int(pagenum)-1][1]()),quote="no")) + + def nextPage(self,pagenum,url): + pages=len(self.ZopeFind(self,obj_metatypes=['DTML Document','File'])) # teste ob performance ok, sonst in variable + if int(pagenum)+1 <= pages: + retstr=url+"?p="+str(int(pagenum)+1) + return """next"""%retstr + + def previousPage(self,pagenum,url): + + if int(pagenum)-1 > 0: + retstr=url+"?p="+str(int(pagenum)-1) + return """previous"""%retstr + + +def manage_addVLP_essayForm(self): + """Form for adding""" + pt=PageTemplateFile('Products/ECHO_content/vlp/AddVLP_essay.zpt').__of__(self) + return pt() + +def manage_addVLP_essay(self, id,title,label,RESPONSE=None): + """add the copyright""" + + + self._setObject(id, VLP_essay(id, title,label)) + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + + class VLP_collection(ECHO_collection): """VLP spezifische Erweiterung der Collection""" @@ -100,20 +203,9 @@ class VLP_resource(ECHO_resource): {'label':'Update Index','action':'createIndexFile'}, {'label':'Reset MetaLink','action':'resetMetaLink'}, {'label':'Generate Title','action':'generate_title'}, + {'label':'Generate Library Template','action':'generateLibraryTemplateHTML'}, ) - - def printDict(self): - """dict""" - return self.__dict__ - - ## def __init__(self,id,link,metalink,resourceID,title,label,description,contentType,renderingType,responsible,credits,weight,coords): -## """angepasstes init""" - - -## return ECHO_resource(id,link,metalink,resourceID,title,label,description,contentType,renderingType,responsible,credits,weight,coords) - - def resetMetaLink(self,all="no",RESPONSE=None): """resets metalink to standard resp. in case of server change it sets to the new server url""" if all=="yes": @@ -128,19 +220,54 @@ class VLP_resource(ECHO_resource): def show(self): """show the rendered file""" + + if self.REQUEST.get('p',None): + self.REQUEST.set('pn',self.file2page(self.REQUEST.get('p',None))) + + if hasattr(self,'libraryTemplate.html'): + return getattr(self,'libraryTemplate.html')() + pt=PageTemplateFile('Products/ECHO_content/vlp/library_template.zpt').__of__(self) pt.content_type="text/html" return pt() index_html=show - + + def generateLibraryTemplateHTML(self,RESPONSE=None): + """lege standard index.html an""" + + if not hasattr(self,'libraryTemplate.html'): + zt=ZopePageTemplate('libraryTemplate.html') + self._setObject('libraryTemplate.html',zt) + default_content_fn = os.path.join(package_home(globals()), + 'vlp/library_template.zpt') + text = open(default_content_fn).read() + zt.pt_edit(text, 'text/html') + + else: + return "already exists!" + + if RESPONSE is not None: + RESPONSE.redirect('manage_main') + + def index_meta(self): """index_meta""" + pt=PageTemplateFile('Products/ECHO_content/vlp/index_meta.zpt').__of__(self) pt.content_type="text/html" return pt() - + def file2page(self,p): + """converts filename to pagenumber""" + dom=xml.dom.minidom.parse(urllib.urlopen(getattr(self,'index.xml').absolute_url())) + + for page in dom.getElementsByTagName('page'): + if page.getAttribute('file')==p: + return page.getAttribute('nr') + + return 0 + def dir2index(self): """dir to index""" @@ -158,9 +285,10 @@ class VLP_resource(ECHO_resource): for x in ret: if not (x[0]=="."): - temp.append(calculateName(x)) + temp.append((calculateName(x),os.path.splitext(x)[0])) return temp + def firstPage(self,url=None): """showlink to the first image""" if self.REQUEST.get('pn')=="1": #erste seinte dann kein a tag