Diff for /ECHO_content/VLPExtension.py between versions 1.26 and 1.33

version 1.26, 2004/10/05 07:31:09 version 1.33, 2004/11/18 12:35:48
Line 1 Line 1
   """
   This module contains extensions which where originally made for the VLP.
   """
   from OFS.Cache import Cacheable
 from Products.ECHO_content.ECHO_collection import *  from Products.ECHO_content.ECHO_collection import *
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile  from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 from Products.PageTemplates.PageTemplate import PageTemplate  from Products.PageTemplates.PageTemplate import PageTemplate
Line 13  import urllib Line 17  import urllib
 import xmlrpclib  import xmlrpclib
 import vlp_xmlhelpers  import vlp_xmlhelpers
 from types import *  from types import *
   from Globals import package_home
   
   
   
Line 48  def getText(nodelist): Line 53  def getText(nodelist):
            rc = rc + node.data             rc = rc + node.data
     return rc      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):  class VLP_essay(Folder):
     """classe für VLP essays"""      """classe für VLP essays"""
   
Line 69  class VLP_essay(Folder): Line 162  class VLP_essay(Folder):
             obj=getattr(self,type+"_template")              obj=getattr(self,type+"_template")
             return obj()              return obj()
         else:          else:
             pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_%s_template_standard.zpt'%type).__of__(self)              pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','ECHO_%s_template_standard.zpt'%type)).__of__(self)
             pt.content_type="text/html"              pt.content_type="text/html"
             return pt()              return pt()
   
     def ConfigVLP_essayForm(self):      def ConfigVLP_essayForm(self):
         """Form for adding"""          """Form for adding"""
         pt=PageTemplateFile('Products/ECHO_content/vlp/ChangeVLP_essay.zpt').__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','ChangeVLP_essay.zpt')).__of__(self)
         return pt()          return pt()
   
     def ChangeVLP_essay(self,title,label,description,RESPONSE=None):      def ChangeVLP_essay(self,title,label,description,RESPONSE=None):
Line 100  class VLP_essay(Folder): Line 193  class VLP_essay(Folder):
         if hasattr(self,'essayTemplate.html'):          if hasattr(self,'essayTemplate.html'):
             return getattr(self,'essayTemplate.html')()              return getattr(self,'essayTemplate.html')()
   
         pt=PageTemplateFile('Products/ECHO_content/vlp/essay_template.zpt').__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','essay_template.zpt')).__of__(self)
         pt.content_type="text/html"          pt.content_type="text/html"
         return pt()          return pt()
   
Line 144  class VLP_essay(Folder): Line 237  class VLP_essay(Folder):
         return self.xml2html(makeXML(txt),quote="no")          return self.xml2html(makeXML(txt),quote="no")
         else:          else:
                   
         #return makeXML(str(pages[int(pagenum)-1][1]))          
                   
         return self.xml2html(makeXML(pages[int(pagenum)-1][1]()),quote="no")          return self.xml2html(makeXML(pages[int(pagenum)-1][1]()),quote="no")
                   
Line 175  class VLP_essay(Folder): Line 268  class VLP_essay(Folder):
                   
 def manage_addVLP_essayForm(self):  def manage_addVLP_essayForm(self):
     """Form for adding"""      """Form for adding"""
     pt=PageTemplateFile('Products/ECHO_content/vlp/AddVLP_essay.zpt').__of__(self)      pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','AddVLP_essay.zpt')).__of__(self)
     return pt()      return pt()
   
 def manage_addVLP_essay(self, id,title,label,RESPONSE=None):  def manage_addVLP_essay(self, id,title,label,RESPONSE=None):
Line 200  class VLP_encyclopaedia(VLP_essay): Line 293  class VLP_encyclopaedia(VLP_essay):
           
     def loadNewFileForm(self):      def loadNewFileForm(self):
         """Neues XML-File einlesen"""          """Neues XML-File einlesen"""
         pt=PageTemplateFile('Products/ECHO_content/vlp/VLP_newfile.zpt').__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','VLP_newfile.zpt')).__of__(self)
         return pt()          return pt()
   
     def loadNewFile(self,RESPONSE=None):      def loadNewFile(self,RESPONSE=None):
Line 233  class VLP_encyclopaedia(VLP_essay): Line 326  class VLP_encyclopaedia(VLP_essay):
           
 def manage_addVLP_encycForm(self):  def manage_addVLP_encycForm(self):
     """Form for adding"""      """Form for adding"""
     pt=PageTemplateFile('Products/ECHO_content/vlp/AddVLP_encyc.zpt').__of__(self)      pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','AddVLP_encyc.zpt')).__of__(self)
     return pt()      return pt()
   
 def manage_addVLP_encyc(self, id,title,label,RESPONSE=None):  def manage_addVLP_encyc(self, id,title,label,RESPONSE=None):
Line 258  class VLP_collection(ECHO_collection): Line 351  class VLP_collection(ECHO_collection):
   
     def VLP_path_configForm(self):      def VLP_path_configForm(self):
         """change pt"""          """change pt"""
         path=PageTemplateFile('Products/ECHO_content/vlp/ChangeVLPPath.zpt').__of__(self)          path=PageTemplateFile(os.path.join(package_home(globals()),'vlp','ChangeVLPPath.zpt')).__of__(self)
         return pt()          return pt()
   
     def VLP_path_config(self,path,RESPONSE=None):      def VLP_path_config(self,path,RESPONSE=None):
Line 275  class VLP_collection(ECHO_collection): Line 368  class VLP_collection(ECHO_collection):
             if fileName[0:3]=="lit":              if fileName[0:3]=="lit":
                                   
                 metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta"                  metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta"
           if not hasattr(self,fileName):
                 newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','')                  newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','')
                 self._setObject(fileName,newObj)                  self._setObject(fileName,newObj)
                                   
Line 316  class VLP_collection(ECHO_collection): Line 410  class VLP_collection(ECHO_collection):
                   
 def manage_addVLP_collectionForm(self):  def manage_addVLP_collectionForm(self):
         """Form for adding a ressource"""          """Form for adding a ressource"""
         pt=PageTemplateFile('Products/ECHO_content/vlp/AddVLP_collectionForm.zpt').__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','AddVLP_collectionForm.zpt')).__of__(self)
         return pt()          return pt()
   
   
Line 335  def manage_addVLP_collection(self,id,tit Line 429  def manage_addVLP_collection(self,id,tit
   
   
   
 class VLP_resource(ECHO_resource):  class VLP_resource(ECHO_resource,Cacheable):
     """VLP spezifische Erweiterung"""      """VLP spezifische Erweiterung"""
   
     meta_type="VLP_resource"      meta_type="VLP_resource"
Line 359  class VLP_resource(ECHO_resource): Line 453  class VLP_resource(ECHO_resource):
         if hasattr(self,'libraryTranscriptionTemplate.html'):          if hasattr(self,'libraryTranscriptionTemplate.html'):
             return getattr(self,'libraryTranscriptionTemplate.html')()              return getattr(self,'libraryTranscriptionTemplate.html')()
   
         pt=PageTemplateFile('Products/ECHO_content/vlp/library_transcriptionTemplate.zpt').__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','library_transcriptionTemplate.zpt')).__of__(self)
         pt.content_type="text/html"          pt.content_type="text/html"
         return pt()          return pt()
   
Line 413  class VLP_resource(ECHO_resource): Line 507  class VLP_resource(ECHO_resource):
         """show the rendered file"""          """show the rendered file"""
   
         if self.REQUEST.get('p',None):          if self.REQUEST.get('p',None):
             self.REQUEST.set('pn',self.file2page(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'):      if hasattr(self,'libraryTemplate.html'):
         return getattr(self,'libraryTemplate.html')()          return getattr(self,'libraryTemplate.html')()
           
         pt=PageTemplateFile('Products/ECHO_content/vlp/library_template.zpt').__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','library_template.zpt')).__of__(self)
         pt.content_type="text/html"          pt.content_type="text/html"
         return pt()          return pt()
           
Line 445  class VLP_resource(ECHO_resource): Line 541  class VLP_resource(ECHO_resource):
     def index_meta(self):      def index_meta(self):
         """index_meta"""          """index_meta"""
                   
         pt=PageTemplateFile('Products/ECHO_content/vlp/index_meta.zpt').__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_meta.zpt')).__of__(self)
         pt.content_type="text/html"          pt.content_type="text/html"
         return pt()          return pt()
   
Line 464  class VLP_resource(ECHO_resource): Line 560  class VLP_resource(ECHO_resource):
         """dir to index"""          """dir to index"""
   
         def calculateName(str):          def calculateName(str):
             ret="%s: %s"%(str[0],str[1:5])          name=os.path.splitext(str[1:])[0]
               ret="%s: %s"%(str[0],name)
             return ret              return ret
   
         try:          try:
Line 474  class VLP_resource(ECHO_resource): Line 571  class VLP_resource(ECHO_resource):
             ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi'))              ret=os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi'))
             self.imagePath='pagesHi'              self.imagePath='pagesHi'
         temp=[]          temp=[]
       ret.sort()
         for x in ret:          for x in ret:
             if not (x[0]=="."):              if not (x[0]=="."):
                                   
Line 487  class VLP_resource(ECHO_resource): Line 585  class VLP_resource(ECHO_resource):
             return """<img src="../../images/first.gif" alt="first" width="14" height="14" border="0"><br>first"""              return """<img src="../../images/first.gif" alt="first" width="14" height="14" border="0"><br>first"""
   
         else:          else:
           ws=self.REQUEST.get('ws','1')
             return """<a href=%s>              return """<a href=%s>
                          <img src="../../images/first.gif" alt="first" width="14" height="14" border="0"><br>first                           <img src="../../images/first.gif" alt="first" width="14" height="14" border="0"><br>first
                          </a>                           </a>
                          """%(self.REQUEST['URL']+"?pn=1")                           """%(self.REQUEST['URL']+"?pn=1&ws=%s"%ws)
   
     def lastPage(self,url=None):      def lastPage(self,url=None):
         """showlink to the first image"""          """showlink to the first image"""
Line 502  class VLP_resource(ECHO_resource): Line 601  class VLP_resource(ECHO_resource):
             return """<img src="../../images/last.gif" alt="last" width="14" height="14" border="0"><br>last"""              return """<img src="../../images/last.gif" alt="last" width="14" height="14" border="0"><br>last"""
   
         else:          else:
           ws=self.REQUEST.get('ws','1')
             return """<a href=%s>              return """<a href=%s>
                          <img src="../../images/last.gif" alt="last" width="14" height="14" border="0"><br>last                           <img src="../../images/last.gif" alt="last" width="14" height="14" border="0"><br>last
                          </a>                           </a>
                          """%(self.REQUEST['URL']+"?pn="+str(ln))                           """%(self.REQUEST['URL']+"?pn="+str(ln)+"&ws="+ws)
                           
     def prevPage(self,url=None):      def prevPage(self,url=None):
         """showlink to the first image"""          """showlink to the first image"""
Line 516  class VLP_resource(ECHO_resource): Line 616  class VLP_resource(ECHO_resource):
             return """<img src="../../images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev"""              return """<img src="../../images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev"""
   
         else:          else:
           ws=self.REQUEST.get('ws','1')
             return """<a href=%s>              return """<a href=%s>
                          <img src="../../images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev                           <img src="../../images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev
                          </a>                           </a>
                          """%(self.REQUEST['URL']+"?pn="+str(nn))                           """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)
   
     def nextPage(self,url=None):      def nextPage(self,url=None):
         """showlink to the first image"""          """showlink to the first image"""
Line 532  class VLP_resource(ECHO_resource): Line 633  class VLP_resource(ECHO_resource):
             return """<img src="../../images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next"""              return """<img src="../../images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next"""
   
         else:          else:
           ws=self.REQUEST.get('ws','1')
             return """<a href=%s>              return """<a href=%s>
                          <img src="../../images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next                           <img src="../../images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next
                          </a>                           </a>
                          """%(self.REQUEST['URL']+"?pn="+str(nn))                           """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)
                   
           
     def readIndexFile(self,url=None):      def readIndexFile(self,url=None):
         """reads the indexfile. presently url not None isn't implemented. In the future url can be defined."""          """reads the indexfile. presently url not None isn't implemented. In the future url can be defined."""
         pagelist=[]  
         if not url:          if not url:
             url=self.absolute_url()+"/index.xml"              url=self.absolute_url()+"/index.xml"
   
       if self.ZCacheable_isCachingEnabled():
               
               result = self.ZCacheable_get(view_name=url)
               if result is not None:
                   # Got a cached value.
           print "CACHEXX"
                   return result
   
           pagelist=[]
      
         fh=ECHO_helpers.urlopen(url)          fh=ECHO_helpers.urlopen(url)
         dom=xml.dom.minidom.parse(fh)          dom=xml.dom.minidom.parse(fh)
                   
Line 554  class VLP_resource(ECHO_resource): Line 665  class VLP_resource(ECHO_resource):
         fileName=page.getAttribute('file')          fileName=page.getAttribute('file')
             pagelist.append((pageNum,text,fileName))              pagelist.append((pageNum,text,fileName))
   
       self.ZCacheable_set(pagelist,view_name=url)
         return pagelist          return pagelist
   
     def getFileName(self):      def getFileName(self):
Line 569  class VLP_resource(ECHO_resource): Line 681  class VLP_resource(ECHO_resource):
         """create index file"""          """create index file"""
   
                   
         pt=PageTemplateFile('Products/ECHO_content/vlp/index_template.zpt').__of__(self)()          pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','index_template.zpt')).__of__(self)()
   
   
                   
Line 588  class VLP_resource(ECHO_resource): Line 700  class VLP_resource(ECHO_resource):
                   
 def manage_addVLP_resourceForm(self):  def manage_addVLP_resourceForm(self):
         """Form for adding a ressource"""          """Form for adding a ressource"""
         pt=PageTemplateFile('Products/ECHO_content/vlp/AddVLP_resourceForm.zpt').__of__(self)          pt=PageTemplateFile(os.path.join(package_home(globals()),'vlp','AddVLP_resourceForm.zpt')).__of__(self)
         return pt()          return pt()
   
   

Removed from v.1.26  
changed lines
  Added in v.1.33


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>