--- ECHO_content/VLPExtension.py 2006/01/20 15:12:57 1.54
+++ ECHO_content/VLPExtension.py 2011/10/13 07:48:27 1.94.2.1
@@ -1,923 +1,38 @@
"""
+DEPRICATED: USED NOW VLPExtension in the Product VLP_extensions
This module contains extensions which where originally made for the VLP.
+definiton here are only for compatibility reasons.
"""
-from OFS.Cache import Cacheable
-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 OFS.Image import File
-try:
- from Products.zogiLib import zogiLib
-except:
- print "Zogilib not installed, VLP_resource will not work"
-
-import xml.dom.minidom
-import urllib
-import xmlrpclib
-import vlp_xmlhelpers
-import sys
-import os
-from stat import *
-from types import *
-from Globals import package_home
-
-
-
-def lemmatize(str):
- """takes a str and addes links the dictionary service"""
- server = xmlrpclib.ServerProxy("http://archimedes.fas.harvard.edu/cgi-bin/donatus-rpc")
- if server:
- splitted=str.split(" ")
- wordlist=["%s"%split for split in splitted].join()
- return wordlist
-
-
-
-
-def makeXML(str):
-
- try:
- dom=xml.dom.minidom.parseString(str)
- return str
- except:
- str=str.replace("& ","& ")
- return """
- %s
- """%str
-
-
-
-def getText(nodelist):
-
- rc = ""
- for node in nodelist:
- if node.nodeType == node.TEXT_NODE:
- rc = rc + node.data
- return rc
-
-class sendMailForm(ZopePageTemplate):
- """sendMailForm"""
- meta_type="sendMailForm"
-
- _default_content_fn = os.path.join(package_home(globals()), 'vlp','sendMail_template.zpt')
-
- manage_options = ZopePageTemplate.manage_options+(
- {'label':'Main Config','action':'main_configForm'},
- )
-
- main_configForm = PageTemplateFile(
- 'vlp/changeSendMailForm', globals())
-
- def main_config(self, toAddrs,mailServer, subjectAdd=None, RESPONSE=None):
- """main_config"""
- self.toAddrs=toAddrs.split("\n")
- self.mailServer=mailServer
- self.subjectAdd=subjectAdd
- if RESPONSE:
- RESPONSE.redirect('manage_main')
-
- def sendForm(self,fromaddr,subject,content,nextPage="index_html",RESPONSE=None):
- """sendform"""
- fromaddr=fromaddr.strip("\r\n\t") # sicherstellen dass keine zusaetzlichen headerzeilen eingefuegt werden
- subject=subject.strip("\r\n\t") # sicherstellen dass keine zusaetzlichen headerzeilen eingefuegt werden
- toaddrs=self.toAddrs
-
- subject="%s %s"%(self.subjectAdd,subject)
-
- msg = ("From: %s\r\nSubject: %s\r\nTo: %s\r\n\r\n"
- % (fromaddr, subject, ", ".join(toaddrs)))
- server = smtplib.SMTP(self.mailServer)
- #server.set_debuglevel(1)
- msg=msg+content
- server.sendmail(fromaddr, toaddrs, msg)
- server.quit()
-
- if RESPONSE:
- RESPONSE.redirect(nextPage)
-
-manage_addSendMailFormForm = PageTemplateFile(
- 'vlp/addSendMailForm', globals(), __name__='manage_addSendMailFormFrom')
-
-from urllib import quote
-
-def manage_addSendMailForm(self, id, toAddrs,mailServer, title=None, text=None, subjectAdd=None,
- REQUEST=None, submit=None):
- "Add a Page Template with optional file content."
- toAddrsList=toAddrs.split("\n")
- id = str(id)
- if REQUEST is None:
- self._setObject(id, sendMailForm(id, text))
- ob = getattr(self, id)
- if title:
- ob.pt_setTitle(title)
- setattr(ob,'toAddrs',toAddrsList)
- setattr(ob,'mailServer',mailServer)
- setattr(ob,'subjectAdd',subjectAdd)
- return ob
- else:
- file = REQUEST.form.get('file')
- headers = getattr(file, 'headers', None)
- if headers is None or not file.filename:
- zpt = sendMailForm(id)
- else:
- zpt = sendMailForm(id, file, headers.get('content_type'))
-
- self._setObject(id, zpt)
-
- try:
- u = self.DestinationURL()
- except AttributeError:
- u = REQUEST['URL1']
-
- if submit == " Add and Edit ":
- u = "%s/%s" % (u, quote(id))
-
- ob = getattr(self, id)
- if title:
- ob.pt_setTitle(title)
-
- setattr(ob,'toAddrs',toAddrsList)
- setattr(ob,'mailServer',mailServer)
- setattr(ob,'subjectAdd',subjectAdd)
- REQUEST.RESPONSE.redirect(u+'/manage_main')
- return ''
-
-
-class VLP_essay(Folder):
- """classe für VLP essays"""
-
- meta_type="VLP_essay"
-
- manage_options = Folder.manage_options+(
- {'label':'Main Config','action':'ConfigVLP_essayForm'},
- {'label':'Generate Essay Template','action':'generateEssayTemplateHTML'},
- )
-
- 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(os.path.join(package_home(globals()),'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(os.path.join(package_home(globals()),'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 index_html(self):
-
- """show the rendered file"""
-
- if hasattr(self,'essayTemplate.html'):
- return getattr(self,'essayTemplate.html')()
-
- pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','essay_template.zpt')).__of__(self)
- pt.content_type="text/html"
- return pt()
-
- def generateEssayTemplateHTML(self,RESPONSE=None):
- """lege standard index.html an"""
-
- if not hasattr(self,'essayTemplate.html'):
- zt=ZopePageTemplate('essayTemplate.html')
- self._setObject('essayTemplate.html',zt)
- default_content_fn = os.path.join(package_home(globals()),
- 'vlp/essay_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 getPage(self,pagenum):
- """gibt essay page mit num aus"""
- def sortFind(x,y):
- return cmp(x[0],y[0])
- pages=[]
- pagestmp=self.ZopeFind(self,obj_metatypes=['DTML Document','File'])
- for page in pagestmp:
- if not (page[1].getId()[0]=="."):
- pages.append(page)
-
- pages.sort(sortFind)
- #print str(pages[int(pagenum)][1]())
-
- if pages[int(pagenum)-1][1].meta_type=='File':
-
- #return makeXML(str(pages[int(pagenum)-1][1]))
- #txt=pages[int(pagenum)-1][1].data.decode('utf-8')
- txt=pages[int(pagenum)-1][1].data
- #print txt.encode('utf-8')
-
- return self.xml2html(makeXML(txt),quote="no")
- else:
-
-
-
- return 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 nextURL(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 retstr
-
- def previousURL(self,pagenum,url):
-
- if int(pagenum)-1 > 0:
- retstr=url+"?p="+str(int(pagenum)-1)
- return retstr
-
-
-def manage_addVLP_essayForm(self):
- """Form for adding"""
- pt=PageTemplateFile(os.path.join(package_home(globals()),'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_encyclopaedia(VLP_essay):
- """essay"""
-
- meta_type="VLP_encyclopaedia"
-
- manage_options = VLP_essay.manage_options+(
- {'label':'Load File','action':'loadNewFileForm'},
- )
-
-
- def loadNewFileForm(self):
- """Neues XML-File einlesen"""
- pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','VLP_newfile.zpt')).__of__(self)
- return pt()
-
- def loadNewFile(self,RESPONSE=None):
- """einlesen des neuen files"""
- fileupload=self.REQUEST['fileupload']
- if fileupload:
- file_name=fileupload.filename
- filedata=fileupload.read()
-
- argv=vlp_xmlhelpers.proj2hash(self,filedata)
- textsStr=string.join(argv['text']).encode('utf-8')
-
- texts=textsStr.split("")
-
- i=0
- for text in texts:
- i+=1
- pageName='page%03d.xml'%i
- pages=self.ZopeFind(self,obj_ids=[pageName])
- if pages:
- pages[0][1].update_data(text)
-
- else:
- zt=File(pageName,pageName,text,content_type="text/plain")
- self._setObject(pageName,zt)
-
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
-
-def manage_addVLP_encycForm(self):
- """Form for adding"""
- pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','AddVLP_encyc.zpt')).__of__(self)
- return pt()
-
-def manage_addVLP_encyc(self, id,title,label,RESPONSE=None):
- """add the copyright"""
-
-
- self._setObject(id, VLP_encyclopaedia(id, title,label))
-
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
-class VLP_subcollection(ECHO_collection):
- """ subcollection of elements"""
-
- meta_type="VLP_subcollection"
-
- def getVLPSubcollectionToc(self,type):
-
- #different ordering depending on the type
- if(type == "(Collection)"):
- sort= "shortreference"
- else:
- sort = "startpages"
-
- #content of journals also displayed if not online
-
- if (type == "(JournalVolume)"):
- online =""
- else:
- online ="AND online = 1"
- sort=self.collectionSort(type)
-
- item = [x for x in self.ZSQLSimpleSearch("""SELECT * FROM vl_literature
- WHERE volumeid = '%s' """%self.getId()
- + """ %s AND not referenceType='%s' """%(online,type)
- + """ORDER BY """ + sort)]
-
- tocItem = [x for x in self.ZSQLSimpleSearch("""SELECT * FROM vl_literature
- WHERE volumeid = '%s' """%self.getId()
- + """AND online = 1 AND referenceType='%s' """%type
- + """ORDER BY """ + sort)]
-
-
-
- return tocItem+item
-
- def checkForFrontMatter(self,item):
- """Teste ob Frontmatter exists"""
- if not item==self.getId():
- return False
-
- if self.ZopeFind(self,obj_ids=[self.getId()]):
- return True
- else:
- return False
-
- def generateSubCollectionFromDB(self):
- """erzeuge subcollection"""
- for item in self.ZSQLSimpleSearch("select * from vl_literature where volumeid like '%s'"%self.id):
- manage_addECHO_link(self,item.reference,item.titlerefdisplay,item.titlerefdisplay)
-
-
- def index_html(self):
- """erzeuge darstellung"""
-
- if hasattr(self,'subCollection_template.html'):
- return getattr(self,'subCollection_template.html')()
-
- pt=zptFile(self, 'vlp/subCollection_template.zpt')
- return pt()
-
-
-def manage_addVLP_subCollection(self,id,title,label,RESPONSE=None):
-
- self._setObject(id,VLP_subcollection(id,title,label))
-
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
-
-class VLP_collection(ECHO_collection):
- """VLP spezifische Erweiterung der Collection"""
-
-
- meta_type="VLP_collection"
- manage_options=ECHO_collection.manage_options+(
- {'label':'Change Path','action':'VLP_path_configForm'},
- {'label':'Update Library','action':'updateCollection'},
- {'label':'Update Metadata','action':'updateCollectionMD'},
- )
-
-
-
- def generateSubCollections(self,errorsTXT=""):
- """erzeuge subcollectionen"""
- founds=self.ZSQLSimpleSearch("select * from vl_literature where referencetype in ('Edited Book'),'(Book)','(Collection)','(JournalVolume)')")
-
- self.REQUEST.RESPONSE.write("Create Subcollections
\n")
- for found in founds:
- try:
- foundCol=self.ZopeFind(self,obj_ids=[found.reference])
- if foundCol:
-
- self.manage_delObjects([foundCol[0][0]])
-
- manage_addVLP_subCollection(self,found.reference,found.titlerefdisplay,found.titlerefdisplay)
- #getattr(self,found.reference).generateSubCollectionFromDB()
- #teste ob es Images auf dem Server gibt mit gleichem Namen (frontmatter)
- if os.path.exists(os.path.join(self.vlp_basis,found.reference)):
-
- obj=getattr(self,found.reference)
- if not self.ZopeFind(obj,obj_ids=[found.reference]):
- metalink=self.REQUEST['URL1']+"/"+found.reference+"/"+found.reference+"/index_meta"
- newObj=VLP_resource(found.reference,'',metalink,found.reference,found.reference,found.reference,'generated','book','','','','','','')
- obj._setObject(found.reference,newObj)
- genObj=getattr(obj,found.reference)
- genObj.createIndexFile()
-
- self.REQUEST.RESPONSE.write("%s
\n"%found.reference)
- except:
- error=sys.exc_info()[0:2]
- RESPONSE.write("(ERROR (%s): %s %s)\n"%(found.reference,error[0],error[1]))
- errorsTXT+="No subcollection of %s "+"(ERROR: %s %s)
"%error
-
- return errorsTXT
-
- def VLP_path_configForm(self):
- """change pt"""
- pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','ChangeVLPPath.zpt')).__of__(self)
- return pt()
-
- def VLP_path_config(self,path,RESPONSE=None):
- """config"""
- self.vlp_basis=path
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
- def updateCollection(self,RESPONSE=None):
- """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner"""
- errorsTXT="Errors
"
- RESPONSE.write("")
- files=os.listdir(self.vlp_basis)
+#from Products.VLP_extensions.vlp_xmlhelpers import *
+#import Products.VLP_extensions
- errorsTXT+="New Ressources
"
- for fileName in files:
-
- if fileName[0:3]=="lit":
-
- metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta"
- try:
- if not hasattr(self,fileName):
- newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','')
- self._setObject(fileName,newObj)
-
- RESPONSE.write("got: %s\n
"%fileName)
- genObj=getattr(self,fileName)
- if hasattr(genObj,'createIndexFile'):
- try:
- genObj.createIndexFile()
- except:
- error=sys.exc_info()[0:2]
- RESPONSE.write("(ERROR (%s): %s %s)
\n"%(fileName,error[0],error[1]))
- errorsTXT+="No indexfile of %s "+"(ERROR: %s %s)
"%error
-
- if genObj.meta_type=="VLP_subcollection":
- genObj.pageSizeSum=getattr(genObj,fileName).getPageSizeSum()
- else:
- genObj.pageSizeSum=genObj.getPageSizeSum()
-
- except:
- error=sys.exc_info()[0:2]
- RESPONSE.write("(ERROR (%s): %s %s)
\n"%(fileName,error[0],error[1]))
- errorsTXT+="File not created:%s "+"(ERROR: %s %s)
"%error
-
- errorsTXT+=self.generateSubCollections()
- errorsTXT+="/n"
- RESPONSE.write(errorsTXT)
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
- def updateCollectionMD(self,RESPONSE=None):
- """updateMD"""
- files=os.listdir(self.vlp_basis)
- for fileName in files:
- if fileName[0:3]=="lit":
- genObj=getattr(self,fileName)
- genObj.copyIndex_meta2echo_resource()
- genObj.generate_title()
-
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
- def copyFullTextsFromDB(self,RESPONSE=None):
- """copy fulltext aus DB"""
-
- ress=self.ZopeFind(self,obj_metatypes=['VLP_resource'])
- ret=""
- for res in ress:
- tmp=res[1].copyTranscriptionFromDB()
- ret+=tmp
-
- if RESPONSE:
- RESPONSE.write(tmp+"\n")
- if not RESPONSE:
- return ret
- else:
- RESPONSE.write("END\n")
-
-
-def manage_addVLP_collectionForm(self):
- """Form for adding a ressource"""
- pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','AddVLP_collectionForm.zpt')).__of__(self)
- return pt()
-
-
-
-def manage_addVLP_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,path,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag="",bgcolour=""):
- """add a echo collection"""
-
-
- newObj=VLP_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag,bgcolour="")
-
- self._setObject(id,newObj)
- setattr(newObj,'path',path)
-
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
-
-
-class VLP_resource(ECHO_resource,Cacheable):
- """VLP spezifische Erweiterung"""
-
- meta_type="VLP_resource"
-
- #vlp_basis="/mpiwg/online/permanent/vlp"
-
-
- referencetypes=[]
-
- manage_options=ECHO_resource.manage_options+Cacheable.manage_options+(
- {'label':'Update Index','action':'createIndexFile'},
- {'label':'Reset MetaLink','action':'resetMetaLink'},
- {'label':'Generate Title','action':'generate_title'},
- {'label':'Generate Library Template','action':'generateLibraryTemplateHTML'},
- )
-
-
- def getImagePath(self):
- """Pfad zu den Images"""
-
- if os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pageimg')):
- return os.path.join(self.vlp_basis,self.resourceID,'pageimg')
- elif os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi')):
- return os.path.join(self.vlp_basis,self.resourceID,'pagesHi')
- else:
- return "no images "
-
-
-
- def transcription(self):
- """show the rendered transcriptiofile"""
-
- if hasattr(self,'libraryTranscriptionTemplate.html'):
- return getattr(self,'libraryTranscriptionTemplate.html')()
-
- pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','library_transcriptionTemplate.zpt')).__of__(self)
- pt.content_type="text/html"
- return pt()
-
-
-
- def copyTranscriptionFromDB(self):
- """checks if transcription exits in DB"""
- founds=self.ZSQLSimpleSearch('select * from vl_transcript where source=\''+self.resourceID+'\' order by id')
-
-
- ret="""
- """
-
- if founds:
-
- for found in founds:
-
- text=found.transcript
- if not text: text=""
- ret+=""+text+""
-
- ret+=""
- re2=ret[0:]
- re3=re2.decode('latin-1').encode('utf-8')
- #re3=re2
- ft=self.ZopeFind(self,obj_metatypes=['ECHO_fullText'])
-
- if ft:
-
- ft[0][1].pt_edit(re3,'text/xml')
-
- else:
-
- self._setObject('fulltext',ECHO_fullText(id,''))
-
- try:
- getattr(self,'fulltext').pt_edit(re3.encode('utf-8','ignore'),'text/xml')
- except:
- getattr(self,'fulltext').pt_edit(re3.encode('latin-1').decode('utf-8'),'text/xml')
-
- return "FT: %s"%self.getId()
- else:
- return "no: %s"%self.getId()
-
- 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":
- self.metalink=self.absolute_url()+"/index_meta"
- else:
- splitted=self.metalink.split("/")
- if (len(splitted)>1) and (splitted[len(splitted)-1]=="index_meta") and (splitted[len(splitted)-2]==self.getId()): # heuristic nur generische Metadatafiles andern
- self.metalink=self.absolute_url()+"/index_meta"
-
- if RESPONSE:
- return "done"
-
- def show(self):
- """show the rendered file"""
-
- if self.REQUEST.get('p',None):
- #self.REQUEST.set('pn',self.file2page(self.REQUEST.get('p',None)))
- self.REQUEST.RESPONSE.redirect(self.REQUEST['URL']+"?pn="+self.file2page(self.REQUEST.get('p',None)))
-
-
- if hasattr(self,'libraryTemplate.html'):
- return getattr(self,'libraryTemplate.html')()
-
- pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','library_template.zpt')).__of__(self)
- pt.content_type="text/html"
- return pt()
-
- def index_html(self):
- """index_html"""
- #return self.REQUEST
- if not self.REQUEST.has_key("ws"):
- self.REQUEST.form["ws"]="1.5"
-
- return self.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(os.path.join(package_home(globals()),'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(ECHO_helpers.urlopen(getattr(self,'index.xml').absolute_url()))
-
- for page in dom.getElementsByTagName('page'):
- # pageummer mit lo oder hi sind aequivalent
- if (page.getAttribute('file')==p) or ("%slo"%page.getAttribute('file')==p) or ("%shi"%page.getAttribute('file')==p):
- return page.getAttribute('nr')
-
- return 0
-
- def getPageSizeSum(self):
- """generate average page size"""
-
- #size of hi resolution
- files=[]
- try:
- pathHi=os.path.join(self.vlp_basis,self.resourceID,'pagesHi')
- files=os.listdir(pathHi)
- hi=0
- for f in files:
- hi+=os.stat(os.path.join(pathHi,f))[ST_SIZE]
-
- except:
- hi=0
-
- #size of hi resolution
- try:
- pathHi=os.path.join(self.vlp_basis,self.resourceID,'pagesLo')
- files=os.listdir(pathHi)
- lo=0
- for f in files:
- lo+=os.stat(os.path.join(pathHi,f))[ST_SIZE]
-
- except:
- lo=0
-
-
- return (hi,lo,len(files))
-
-
- def getPageWeights(self):
- """average Page sizes in kBytes"""
-
- res=getattr(self,'pageSizeSum',(0,0,1))
- return (res[0]/(1024*res[2]),res[1]/(1024*res[2]))
-
-
-
- def dir2index(self):
- """dir to index"""
-
- excludeNames=['Icon']
-
-
- def calculateName(str):
- name=os.path.splitext(str[1:])[0]
- ret="%s: %s"%(str[0],name)
- return ret
-
- try:
- ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pageimg'))
- self.imagePath='pageimg'
- except:
- ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi'))
- self.imagePath='pagesHi'
- temp=[]
- ret.sort()
- for x in ret:
- if (not (x[0]==".")) and (not x[0:4] in excludeNames):
-
- temp.append((calculateName(x),os.path.splitext(x)[0]))
- return temp
+try:
+ from Products.VLP_extensions.vlp_xmlhelpers import *
+ import Products.VLP_extensions
- def firstPage(self,url=None):
- """showlink to the first image"""
- if self.REQUEST.get('pn','1')=="1": #erste seinte dann kein a tag
- return """![first](../../images/first.gif)
first"""
-
- else:
- ws=self.REQUEST.get('ws','1')
- return """
- ![first](../../images/first.gif)
first
-
- """%(self.REQUEST['URL']+"?pn=1&ws=%s"%ws)
-
- def lastPage(self,url=None):
- """showlink to the first image"""
- pages=self.readIndexFile(url)
- if pages:
- ln=len(pages)
-
- if (self.REQUEST.get('pn')==str(ln)) or (ln==1): #letzte seite dann kein a tag oder nur eine Seite
- return """![last](../../images/last.gif)
last"""
-
- else:
- ws=self.REQUEST.get('ws','1')
- return """
- ![last](../../images/last.gif)
last
-
- """%(self.REQUEST['URL']+"?pn="+str(ln)+"&ws="+ws)
-
- def prevPage(self,url=None):
- """showlink to the first image"""
-
-
- nn = int(self.REQUEST.get('pn','1'))-1
- if nn < 1: #letzte seite dann kein a tag
- return """![prev](../../images/lisePrev.gif)
prev"""
-
- else:
- ws=self.REQUEST.get('ws','1')
- return """
- ![prev](../../images/lisePrev.gif)
prev
-
- """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)
-
- def nextPage(self,url=None):
- """showlink to the first image"""
- pages=self.readIndexFile(url)
- if pages:
- ln=len(pages)
-
- nn = int(self.REQUEST.get('pn','1'))+1
- if (nn>int(ln)) or (ln==1): #letzte seite dann kein a tag
- return """![next](../../images/liseNext.gif)
next"""
-
- else:
- ws=self.REQUEST.get('ws','1')
- return """
- ![next](../../images/liseNext.gif)
next
-
- """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)
+ class sendMailForm(Products.VLP_extensions.VLPExtension.sendMailForm):
+ pass
+
+ class VLP_collectionFolder(Products.VLP_extensions.VLPExtension.VLP_collectionFolder):
+ pass
+
+ class VLP_essay(Products.VLP_extensions.VLPExtension.VLP_essay):
+ pass
+
+ class VLP_encyclopaedia(Products.VLP_extensions.VLPExtension.VLP_encyclopaedia):
+ pass
+
+ class VLP_subcollection(Products.VLP_extensions.VLPExtension.VLP_subcollection):
+ pass
+ class VLP_collection(Products.VLP_extensions.VLPExtension.VLP_collection):
+ pass
- def readIndexFile(self,url=None):
- """reads the indexfile. presently url not None isn't implemented. In the future url can be defined."""
- if not url:
- urlTmp=self.absolute_url()+"/index.xml"
-
- if self.ZCacheable_isCachingEnabled():
-
- result = self.ZCacheable_get(view_name=urlTmp)
- if result is not None:
- # Got a cached value.
- return result
-
- pagelist=[]
-
- if not url:
-
- xmlTxt=getattr(self,'index.xml')()
- dom=xml.dom.minidom.parseString(xmlTxt)
- else:
- fh=ECHO_helpers.urlopen(urlTmp)
- dom=xml.dom.minidom.parse(fh)
-
-
- for page in dom.getElementsByTagName('page'):
- text=getText(page.childNodes)
- pageNum=page.getAttribute('nr')
- fileName=page.getAttribute('file')
- pagelist.append((pageNum,text,fileName))
-
- self.ZCacheable_set(pagelist,view_name=urlTmp)
- return pagelist
-
- def getFileName(self):
- """getNameOfCurrentFile"""
- try:
- pn=int(self.REQUEST.get('pn','1'))
- except:
- pn=1
- pageinfo=self.readIndexFile()[pn-1]
- return pageinfo[2]
-
- def createIndexFile(self,RESPONSE=None):
- """create index file"""
-
-
- pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_template.zpt')).__of__(self)()
-
-
-
- if not hasattr(self,'index.xml'):
- zt=ZopePageTemplate('index.xml')
- self._setObject('index.xml',zt)
- else:
- zt=getattr(self,'index.xml')
-
-
- zt.pt_edit(pt, 'text/xml')
-
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
-
-def manage_addVLP_resourceForm(self):
- """Form for adding a ressource"""
- pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','AddVLP_resourceForm.zpt')).__of__(self)
- return pt()
-
-
-
-def manage_addVLP_resource(self,id,title,label,description,responsible,link,metalink,weight,resourceID=None,contentType=None,renderingType=None,credits=None,coords=None,RESPONSE=None):
- """addaresource"""
-
+ class VLP_resource(Products.VLP_extensions.VLPExtension.VLP_resource):
+ pass
- if metalink=='':
- metalink=self.absolute_url()+"/"+id+"/index_meta"
-
- newObj=VLP_resource(id,link,metalink,resourceID,title,label,description,contentType,renderingType,responsible,credits,weight,coords)
-
- self._setObject(id,newObj)
+except:
+ print "NO VLP extensions"
- if RESPONSE is not None:
- RESPONSE.redirect('manage_main')
-
+
\ No newline at end of file