annotate VLPExtension.py @ 0:88009fd07d31

VLP specific additions to ECHO_content product. First checkin.
author casties
date Wed, 17 Apr 2013 14:54:21 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1 """
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
2 This module contains extensions which where originally made for the VLP.
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
3 """
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
4 from OFS.Cache import Cacheable
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
5 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
6 from Products.PageTemplates.PageTemplate import PageTemplate
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
7 from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
8 from OFS.Image import File
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
9 import xml.dom.minidom
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
10 import urllib
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
11 import xmlrpclib
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
12 import vlp_xmlhelpers
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
13 import sys
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
14 import os
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
15 from stat import *
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
16 from types import *
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
17 from Globals import package_home
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
18 import transaction
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
19 import Acquisition
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
20 import re
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
21 import logging
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
22
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
23 from Products.ECHO_content.ECHO_collection import *
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
24 from vlp_xmlhelpers import *
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
25 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
26 from Products.zogiLib import zogiLib
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
27 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
28 print "Zogilib not installed, VLP_resource will not work"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
29
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
30
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
31 def lemmatize(str):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
32 """takes a str and addes links the dictionary service"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
33 server = xmlrpclib.ServerProxy("http://archimedes.fas.harvard.edu/cgi-bin/donatus-rpc")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
34 if server:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
35 splitted=str.split(" ")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
36 wordlist=["<w>%s</w>"%split for split in splitted].join()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
37 return wordlist
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
38
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
39
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
40
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
41
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
42 def makeXML(str):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
43
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
44 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
45 dom=xml.dom.minidom.parseString(str)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
46 return str
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
47 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
48 str=str.replace("& ","&amp; ")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
49 return """<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><page>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
50 %s
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
51 </page>"""%str
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
52
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
53
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
54 def checkXMLfrag(str):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
55 """checks and returns str as XML fragment"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
56
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
57 xmltempl = """<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
58 <txt>%s</txt>"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
59
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
60 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
61 dom=xml.dom.minidom.parseString(xmltempl%utf8ify(str))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
62 return str
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
63 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
64 str=str.replace("& ","&amp; ")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
65
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
66 dom=xml.dom.minidom.parseString(xmltempl%utf8ify(str))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
67 return str
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
68
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
69
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
70
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
71 def getText(nodelist):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
72
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
73 rc = ""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
74 for node in nodelist:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
75 if node.nodeType == node.TEXT_NODE:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
76 rc = rc + node.data
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
77 return rc
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
78
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
79 class sendMailForm(ZopePageTemplate):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
80 """sendMailForm"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
81 meta_type="sendMailForm"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
82
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
83 _default_content_fn = os.path.join(package_home(globals()), 'zpt','sendMail_template.zpt')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
84
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
85 manage_options = ZopePageTemplate.manage_options+(
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
86 {'label':'Main Config','action':'main_configForm'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
87 )
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
88
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
89 main_configForm = PageTemplateFile(
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
90 'zpt/changeSendMailForm', globals())
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
91
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
92 def main_config(self, toAddrs,mailServer, subjectAdd=None, RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
93 """main_config"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
94 self.toAddrs=toAddrs.split("\n")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
95 self.mailServer=mailServer
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
96 self.subjectAdd=subjectAdd
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
97 if RESPONSE:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
98 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
99
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
100 def sendForm(self,fromaddr,subject,content,nextPage="index_html",RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
101 """sendform"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
102 fromaddr=fromaddr.strip("\r\n\t") # sicherstellen dass keine zusaetzlichen headerzeilen eingefuegt werden
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
103 subject=subject.strip("\r\n\t") # sicherstellen dass keine zusaetzlichen headerzeilen eingefuegt werden
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
104 toaddrs=self.toAddrs
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
105
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
106 subject="%s %s"%(self.subjectAdd,subject)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
107
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
108 msg = ("From: %s\r\nSubject: %s\r\nTo: %s\r\n\r\n"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
109 % (fromaddr, subject, ", ".join(toaddrs)))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
110 server = smtplib.SMTP(self.mailServer)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
111 #server.set_debuglevel(1)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
112 msg=msg+content
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
113 server.sendmail(fromaddr, toaddrs, msg)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
114 server.quit()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
115
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
116 if RESPONSE:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
117 RESPONSE.redirect(nextPage)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
118
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
119 manage_addSendMailFormForm = PageTemplateFile(
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
120 'zpt/addSendMailForm', globals(), __name__='manage_addSendMailFormFrom')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
121
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
122 from urllib import quote
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
123
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
124 def manage_addSendMailForm(self, id, toAddrs,mailServer, title=None, text=None, subjectAdd=None,
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
125 REQUEST=None, submit=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
126 "Add a Page Template with optional file content."
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
127 toAddrsList=toAddrs.split("\n")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
128 id = str(id)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
129 if REQUEST is None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
130 self._setObject(id, sendMailForm(id, text))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
131 ob = getattr(self, id)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
132 if title:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
133 ob.pt_setTitle(title)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
134 setattr(ob,'toAddrs',toAddrsList)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
135 setattr(ob,'mailServer',mailServer)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
136 setattr(ob,'subjectAdd',subjectAdd)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
137 return ob
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
138 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
139 file = REQUEST.form.get('file')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
140 headers = getattr(file, 'headers', None)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
141 if headers is None or not file.filename:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
142 zpt = sendMailForm(id)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
143 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
144 zpt = sendMailForm(id, file, headers.get('content_type'))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
145
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
146 self._setObject(id, zpt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
147
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
148 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
149 u = self.DestinationURL()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
150 except AttributeError:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
151 u = REQUEST['URL1']
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
152
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
153 if submit == " Add and Edit ":
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
154 u = "%s/%s" % (u, quote(id))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
155
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
156 ob = getattr(self, id)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
157 if title:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
158 ob.pt_setTitle(title)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
159
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
160 setattr(ob,'toAddrs',toAddrsList)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
161 setattr(ob,'mailServer',mailServer)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
162 setattr(ob,'subjectAdd',subjectAdd)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
163 REQUEST.RESPONSE.redirect(u+'/manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
164 return ''
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
165
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
166
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
167 class VLP_collectionFolder(Folder):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
168 """klasse fuer folder innerhalb der collection"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
169 meta_type="VLP_collectionFolder"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
170
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
171 class VLP_essay(Folder):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
172 """classe fr VLP essays"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
173
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
174 meta_type="VLP_essay"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
175
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
176 manage_options = Folder.manage_options+(
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
177 {'label':'Main Config','action':'ConfigVLP_essayForm'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
178 {'label':'Generate Essay Template','action':'generateEssayTemplateHTML'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
179 )
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
180
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
181 def content_html(self,type='collection'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
182 """template fuer content"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
183 #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
184 #
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
185 #if templates:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
186 # return templates[0][1]()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
187
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
188 if hasattr(self,type+"_template"):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
189 obj=getattr(self,type+"_template")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
190 return obj()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
191 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
192 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','ECHO_%s_template_standard.zpt'%type)).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
193 pt.content_type="text/html"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
194 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
195
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
196 def ConfigVLP_essayForm(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
197 """Form for adding"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
198 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','ChangeVLP_essay.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
199 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
200
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
201 def ChangeVLP_essay(self,title,label,description,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
202 """Change vlp_essay"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
203 self.title=title
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
204 self.label=label
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
205 self.description=description
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
206
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
207 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
208 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
209
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
210 def __init__(self,id,title,label):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
211 """init"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
212 self.id=id
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
213 self.title=title
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
214 self.label=label
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
215
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
216 def index_html(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
217
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
218 """show the rendered file"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
219
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
220 if hasattr(self,'essayTemplate.html'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
221 return getattr(self,'essayTemplate.html')()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
222
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
223 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','essay_template.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
224 pt.content_type="text/html"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
225 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
226
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
227 def generateEssayTemplateHTML(self,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
228 """lege standard index.html an"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
229
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
230 if not hasattr(self,'essayTemplate.html'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
231 zt=ZopePageTemplate('essayTemplate.html')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
232 self._setObject('essayTemplate.html',zt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
233 default_content_fn = os.path.join(package_home(globals()),
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
234 'zpt/essay_template.zpt')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
235 text = open(default_content_fn).read()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
236 zt.pt_edit(text, 'text/html')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
237
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
238 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
239 return "already exists!"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
240
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
241 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
242 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
243
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
244 def getPageList(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
245 """returns sorted list of (id,object) of page objects"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
246
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
247 def sortFind(x,y):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
248 return cmp(x[0],y[0])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
249
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
250 # pages=[]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
251 # pagestmp=self.ZopeFind(self,obj_metatypes=['DTML Document','File'])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
252 # for page in pagestmp:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
253 # if not (page[1].getId()[0]=="."):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
254 # pages.append(page)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
255
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
256 pages = self.objectItems(['DTML Document','File'])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
257 pages.sort(sortFind)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
258 #logging.debug("pageList=%s"%repr(pages))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
259 return pages
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
260
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
261
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
262 def getPageXMLfrag(self, pageNum=None, pageId=None, pageObj=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
263 """returns XML fragment of page with id"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
264 xml = None
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
265
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
266 if pageNum is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
267 pl = self.getPageList()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
268 pageObj = pl[int(pageNum)-1][1]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
269
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
270 if pageId is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
271 pageObj = getattr(self, pageId, None)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
272
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
273 if pageObj is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
274 txt = ""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
275 if pageObj.meta_type == 'File':
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
276 data = pageObj.data
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
277 #logging.debug("data=%s txt=%s"%(repr(data),txt))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
278 while data is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
279 if isinstance(data, str):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
280 txt += data
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
281 data = None
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
282 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
283 txt += data.data
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
284 data = data.next
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
285
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
286 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
287 # not a File object... perhaps its executable
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
288 txt += pageObj()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
289
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
290 xml = checkXMLfrag(txt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
291
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
292 return unicodify(xml)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
293
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
294 # TODO: Fix this
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
295 xml2html = xml2html
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
296 # TODO: especially this
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
297 link2html = link2html
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
298 checkRef = checkRef
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
299
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
300 def getPage(self,pagenum):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
301 """gibt essay page mit num aus"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
302 def sortFind(x,y):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
303 return cmp(x[0],y[0])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
304 pages=[]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
305 pagestmp=self.ZopeFind(self,obj_metatypes=['DTML Document','File'])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
306 for page in pagestmp:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
307 if not (page[1].getId()[0]=="."):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
308 pages.append(page)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
309
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
310 pages.sort(sortFind)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
311 #print str(pages[int(pagenum)][1]())
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
312
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
313 if pages[int(pagenum)-1][1].meta_type=='File':
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
314 #return makeXML(str(pages[int(pagenum)-1][1]))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
315 #txt=pages[int(pagenum)-1][1].data.decode('utf-8')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
316 txt=pages[int(pagenum)-1][1].data
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
317 #print txt.encode('utf-8')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
318 tmp =makeXML(txt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
319 logging.debug(txt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
320 return self.xml2html(tmp,quote="no")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
321 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
322 return self.xml2html(makeXML(pages[int(pagenum)-1][1]()),quote="no")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
323
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
324 def nextPage(self,pagenum,url):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
325 pages=len(self.ZopeFind(self,obj_metatypes=['DTML Document','File'])) # teste ob performance ok, sonst in variable
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
326 if int(pagenum)+1 <= pages:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
327 retstr=url+"?p="+str(int(pagenum)+1)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
328 return """<td align="right" <a href="%s">next</a></td>"""%retstr
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
329
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
330 def previousPage(self,pagenum,url):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
331
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
332 if int(pagenum)-1 > 0:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
333 retstr=url+"?p="+str(int(pagenum)-1)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
334 return """<td align="left" <a href="%s">previous</a></td>"""%retstr
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
335
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
336 def nextURL(self,pagenum,url):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
337 pages=len(self.ZopeFind(self,obj_metatypes=['DTML Document','File'])) # teste ob performance ok, sonst in variable
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
338 if int(pagenum)+1 <= pages:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
339 retstr=url+"?p="+str(int(pagenum)+1)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
340 return retstr
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
341
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
342 def lastURL(self,pagenum,url):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
343 # teste ob performance ok, sonst in variable
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
344 pages=len(self.ZopeFind(self,obj_metatypes=['DTML Document','File']))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
345
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
346 return url+"?p="+str(pages)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
347
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
348 def previousURL(self,pagenum,url):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
349
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
350 if int(pagenum)-1 > 0:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
351 retstr=url+"?p="+str(int(pagenum)-1)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
352 return retstr
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
353
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
354
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
355 def manage_addVLP_essayForm(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
356 """Form for adding"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
357 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','AddVLP_essay.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
358 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
359
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
360 def manage_addVLP_essay(self, id,title,label,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
361 """add the copyright"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
362
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
363
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
364 self._setObject(id, VLP_essay(id, title,label))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
365
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
366 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
367 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
368
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
369
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
370 class VLP_encyclopaedia(VLP_essay):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
371 """essay"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
372
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
373 meta_type="VLP_encyclopaedia"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
374
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
375 manage_options = VLP_essay.manage_options+(
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
376 {'label':'Load File','action':'loadNewFileForm'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
377 )
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
378
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
379
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
380 def loadNewFileForm(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
381 """Neues XML-File einlesen"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
382 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','VLP_newfile.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
383 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
384
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
385 def loadNewFile(self,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
386 """einlesen des neuen files"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
387 fileupload=self.REQUEST['fileupload']
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
388 if fileupload:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
389 file_name=fileupload.filename
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
390 filedata=fileupload.read()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
391
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
392 argv=vlp_xmlhelpers.proj2hash(self,filedata)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
393 textsStr=string.join(argv['text']).encode('utf-8')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
394
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
395 texts=textsStr.split("<pb/>")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
396
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
397 i=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
398 for text in texts:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
399 i+=1
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
400 pageName='page%03d.xml'%i
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
401 pages=self.ZopeFind(self,obj_ids=[pageName])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
402 if pages:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
403 pages[0][1].update_data(text)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
404
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
405 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
406 zt=File(pageName,pageName,text,content_type="text/plain")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
407 self._setObject(pageName,zt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
408
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
409 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
410 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
411
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
412
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
413 def manage_addVLP_encycForm(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
414 """Form for adding"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
415 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','AddVLP_encyc.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
416 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
417
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
418 def manage_addVLP_encyc(self, id,title,label,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
419 """add the copyright"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
420
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
421
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
422 self._setObject(id, VLP_encyclopaedia(id, title,label))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
423
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
424 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
425 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
426
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
427 class VLP_subcollection(ECHO_collection):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
428 """ subcollection of elements"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
429
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
430 meta_type="VLP_subcollection"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
431
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
432 def getVLPSubcollectionToc(self,type):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
433
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
434 #different ordering depending on the type
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
435 if(type == "(Collection)"):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
436 sort= "shortreference"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
437 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
438 sort = "startpages"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
439
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
440 #content of journals also displayed if not online
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
441
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
442 if (type == "(JournalVolume)"):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
443 online =""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
444 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
445 online ="AND online = 1"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
446 sort=self.collectionSort(type)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
447
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
448 item = [x for x in self.ZSQLSimpleSearch("""SELECT * FROM vl_literature
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
449 WHERE volumeid ~ '%s\\\\M' """%self.getId()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
450 + """ %s AND not referenceType='%s' """%(online,type)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
451 + """ORDER BY """ + sort)]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
452
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
453 tocItem = [x for x in self.ZSQLSimpleSearch("""SELECT * FROM vl_literature
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
454 WHERE reference = '%s' """%self.getId()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
455 + """AND online = 1 AND referenceType='%s' """%type
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
456 + """ORDER BY """ + sort)]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
457
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
458
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
459
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
460 return tocItem+item
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
461
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
462 def checkForFrontMatter(self,item):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
463 """Teste ob Frontmatter exists"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
464 if not item==self.getId():
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
465 return False
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
466
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
467 if self.ZopeFind(self,obj_ids=[self.getId()]):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
468 return True
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
469 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
470 return False
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
471
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
472 def generateSubCollectionFromDB(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
473 """erzeuge subcollection"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
474 for item in self.ZSQLSimpleSearch("select * from vl_literature where volumeid like '%s'"%self.id):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
475 manage_addECHO_link(self,item.reference,item.titlerefdisplay,item.titlerefdisplay)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
476
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
477
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
478 def index_html(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
479 """erzeuge darstellung"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
480
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
481 if hasattr(self,'subCollection_template.html'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
482 return getattr(self,'subCollection_template.html')()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
483
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
484 pt=zptFile(self, 'zpt/subCollection_template.zpt')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
485 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
486
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
487
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
488 def manage_addVLP_subCollection(self,id,title,label,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
489
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
490 self._setObject(id,VLP_subcollection(id,title,label))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
491
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
492 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
493 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
494
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
495 from zope.publisher.interfaces import IPublishTraverse
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
496 from zope.interface import implements
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
497 from zope.publisher.interfaces import NotFound
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
498 #from zope.app import zapi
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
499 from zope.component import queryMultiAdapter
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
500 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
501 from ZPublisher.BaseRequest import DefaultPublishTraverse
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
502 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
503 pass
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
504
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
505 class VLP_collection(ECHO_collection,Acquisition.Explicit):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
506 """VLP spezifische Erweiterung der Collection"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
507
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
508
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
509
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
510 implements(IPublishTraverse)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
511
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
512
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
513 def foxridgePath2vlp(self,url,mk,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
514 """convertiert einen pfad zu einer url in vlp"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
515 litRe = re.match(r".*lit([0-9]*)",url)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
516 logging.debug("foxridgePath2vlp URL:"+repr(url))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
517 lit = "lit"+litRe.group(1)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
518 splitted=url.split("/")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
519 path=splitted[-1].split(".")[0]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
520 newUrl=lit+"?p=%s&mk=%s"%(path,mk)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
521
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
522 if RESPONSE:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
523 RESPONSE.redirect(newUrl)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
524 return
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
525
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
526 return newUrl
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
527
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
528 def findObjFromLitName(self,fileName):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
529 if not fileName[0:3]=="lit":
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
530 logging.error("getOrCreateFolder wrong filename: %s"%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
531 return None
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
532
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
533
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
534 restName="%08d"%int(fileName[3:])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
535
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
536 fs=(restName[0:2],restName[0:4],restName[0:6])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
537
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
538 current =self
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
539 for f in fs:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
540 obj = getattr(current,f,None)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
541 if not obj: #subfolder existiert nicht
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
542 return None
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
543 current=obj
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
544
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
545 return getattr(current,fileName,None)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
546
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
547 def publishTraverse(self,request,name):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
548 """change the traversal if literature object"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
549
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
550 actual_url=request['ACTUAL_URL']
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
551 lastActual=actual_url.split("/")[-1]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
552 logging.debug("pub_trav:"+actual_url)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
553
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
554 if name.startswith("lit"): #umleitung wenn lit aufgerufen wirk
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
555 # umleitung auf den eigentlichen folder nur wenn direkt der Folder litXXX oder dessen index_html methode aufgerufen wird
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
556 if lastActual.startswith("lit") or (lastActual=="index_html") or (lastActual=="index_meta") or (lastActual=="getTitle") or (lastActual=="getMetaDataLink") or (lastActual=="hasTranscription") or (lastActual=="transcription"):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
557 #obj=self. ZopeFind(self,obj_ids=[name],search_sub=1)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
558 ob=self.findObjFromLitName(name)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
559 if not ob:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
560 return "LIt not found"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
561 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
562
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
563 logging.debug("request:"+repr(ob))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
564 request.response.setStatus(200)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
565 #if (lastActual=="index_meta"):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
566 # logging.debug("index_meta requested")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
567 # return ob.index_meta
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
568 return ob
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
569
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
570 else: ## andern falls transversiere zum parent.
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
571 obj = self.aq_parent
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
572 return obj
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
573 else: # mache gar nichts falls nicht lit aufgerufen wird
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
574
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
575
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
576 tr=DefaultPublishTraverse(self, request)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
577 ob= tr.publishTraverse(request, name)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
578
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
579 return ob
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
580 #raise NotFound(self.context, name, request)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
581 #return repr(request)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
582
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
583 meta_type="VLP_collection"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
584 manage_options=ECHO_collection.manage_options+(
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
585 {'label':'Change Path','action':'VLP_path_configForm'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
586 {'label':'Update Library','action':'updateCollection'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
587 {'label':'Update Metadata','action':'updateCollectionMD'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
588 )
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
589 def getAllRessources(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
590 """getallressources"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
591 res=self.ZopeFind(self,obj_metatypes=['VLP_resource'],search_sub=1)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
592 ret=[]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
593 for r in res:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
594 ret.append([r[0],r[1].absolute_url()])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
595
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
596 return ret
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
597
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
598 def generateSubCollections(self,errorsTXT="",forceUpdate=False,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
599 """erzeuge subcollectionen"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
600 logging.debug("generateSubCollections")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
601 founds=self.ZSQLSimpleSearch("select * from vl_literature where referencetype in ('(Edited Book)','(Book)','(Collection)','(JournalVolume)','(Generic Container)')")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
602
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
603 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
604 RESPONSE.setHeader('Content-Type','text/html')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
605 self.REQUEST.RESPONSE.write("<h2>Create Subcollections</h2>\n")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
606 for found in founds:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
607 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
608 litid = str(found.reference)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
609 foundCol=self.findObjFromLitName(litid)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
610 #foundCol=self.ZopeFind(self,obj_ids=[litid])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
611 if foundCol:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
612 col = foundCol
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
613 logging.debug("generateSubCollections: subcollection %s exists (%s)"%(repr(col),found.reference))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
614 logging.debug(repr([col.title,found.titlerefdisplay,col.label,found.titlerefdisplay]))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
615 if (unicodify(col.title) != unicodify(found.titlerefdisplay)) or (unicodify(col.label) != unicodify(found.titlerefdisplay)):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
616 # subcollection seems to have changed
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
617 logging.debug("generateSubCollections: subcollection has changed, recreating!")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
618 col.aq_parent.manage_delObjects([col.getId()])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
619 manage_addVLP_subCollection(self.getOrCreateFolderForFile(litid),litid,found.titlerefdisplay,found.titlerefdisplay)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
620 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
621 logging.debug("generateSubCollections: creating new subcollection %s"%found.reference)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
622 manage_addVLP_subCollection(self.getOrCreateFolderForFile(litid),litid,found.titlerefdisplay,found.titlerefdisplay)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
623
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
624 #teste ob es Images auf dem Server gibt mit gleichem Namen (frontmatter)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
625 if os.path.exists(os.path.join(self.vlp_basis,litid)):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
626 logging.debug("generateSubCollections: found frontmatter in %s"%litid)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
627 obj=self.findObjFromLitName(litid)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
628 if not self.ZopeFind(obj,obj_ids=[litid]):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
629 metalink=self.REQUEST['URL1']+"/"+litid+"/"+litid+"/index_meta"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
630 newObj=VLP_resource(litid,'',metalink,litid,litid,litid,'generated','book','','','','','','')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
631 obj._setObject(litid,newObj)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
632
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
633 genObj=getattr(obj,litid)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
634 genObj.createIndexFile(forceUpdate=forceUpdate)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
635
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
636 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
637 self.REQUEST.RESPONSE.write("<p>%s</p>\n"%litid)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
638 logging.debug("<p>%s</p>\n"%litid)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
639
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
640 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
641 error=sys.exc_info()[0:2]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
642 logging.error("generateSubCollections: ERROR in %s"%litid)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
643 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
644 RESPONSE.write("<p>(ERROR updateII(%s): %s %s TXT: %s)\n</p>"%(litid,error[0],error[1],sys.exc_info()[2]))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
645 RESPONSE.write("<p>(ERROR (%s): %s %s)</p>\n"%(litid,error[0],error[1]))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
646 logging.error("generateSubCollections: %s %s"%error)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
647 self.REQUEST.RESPONSE.write("(ERROR (%s): %s %s)\n"%(litid,repr(error[0]),repr(error[1])))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
648 errorsTXT+="<p>ERROR: No subcollection of %s (ERROR: %s %s)</p>\n"%(litid,error[0],error[1])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
649 errorsTXT+="<p>No subcollection of %s "%litid+"(ERROR: %s %s)</p>"%error
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
650
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
651 return errorsTXT
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
652
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
653 def VLP_path_configForm(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
654 """change pt"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
655 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','ChangeVLPPath.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
656 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
657
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
658 def VLP_path_config(self,path,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
659 """config"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
660 self.vlp_basis=path
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
661 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
662 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
663
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
664
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
665 def getOrCreateFolderForFile(self,fileName):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
666
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
667 if not fileName[0:3]=="lit":
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
668 logging.error("getOrCreateFolder wrong filename: %s"%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
669 return None
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
670
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
671 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
672 restName="%08d"%int(fileName[3:])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
673 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
674 logging.error("getOrCreateFolder wrong filename: %s"%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
675 return None
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
676
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
677 fs=(restName[0:2],restName[0:4],restName[0:6])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
678
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
679 current =self
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
680 for f in fs:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
681 obj = getattr(current,f,None)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
682 if not obj:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
683 newObj=VLP_collectionFolder(f)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
684 current._setObject(f,newObj)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
685 obj = getattr(current,f)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
686 current=obj
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
687
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
688 return current
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
689
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
690 def changeOrAddResources(self,forceUpdate=False,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
691 """changes ord updates all resources found in the file system"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
692
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
693 errorsTXT="<h2>Errors</h2>"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
694 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
695 RESPONSE.setHeader('Content-Type','text/html')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
696 RESPONSE.write("<html><body>")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
697
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
698 files=os.listdir(self.vlp_basis)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
699 i=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
700 for fileName in files:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
701 if i<100:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
702 i+=1
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
703 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
704 i=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
705 j=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
706 while j<5:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
707 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
708 transaction.get().commit()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
709 j=6
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
710 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
711 logging.error("Commit: %s"%j)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
712 j+=1
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
713
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
714 RESPONSE.write("<p>committed</p>")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
715 if fileName[0:3]=="lit":
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
716 metalink=self.REQUEST['URL1']+"/"+fileName+"/index_meta"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
717
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
718 folder=self.getOrCreateFolderForFile(fileName) #get the folder where fileName lives or should live
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
719 if not folder: #folder gave an error
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
720 continue
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
721 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
722 if not hasattr(folder,fileName):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
723 # create new resource
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
724 logging.debug("updateCollection: new %s"%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
725 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
726 RESPONSE.write("<p>new: %s</p>\n"%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
727 logging.debug("new: %s \n"%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
728 newObj=VLP_resource(fileName,'',metalink,fileName,fileName,fileName,'generated','book','','','','','','')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
729
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
730 folder._setObject(fileName,newObj)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
731
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
732 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
733 RESPONSE.write("<p>got: %s "%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
734
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
735 genObj=getattr(folder,fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
736 logging.debug("got: %s "%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
737
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
738 logging.debug("updateCollection: inspecting %s"%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
739 # create index
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
740 if hasattr(genObj,'createIndexFile'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
741 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
742 logging.debug("updateCollection: creating index for %s"%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
743 msg = genObj.createIndexFile(forceUpdate=forceUpdate)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
744 if msg and RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
745 RESPONSE.write(msg)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
746 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
747 error=sys.exc_info()[0:2]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
748 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
749 RESPONSE.write("(ERROR Update(%s): %s %s %s) "%(fileName,error[0],error[1],sys.exc_info()[2]))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
750 errorsTXT+="<p>ERROR creating index for %s "%fileName+"(ERROR: %s %s)</p>\n"%error
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
751
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
752 # update pageSizeSum for subcollections
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
753 if genObj.meta_type=="VLP_subcollection":
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
754 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
755 RESPONSE.write(" is subcollection")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
756 logging.debug("updateCollection: %s is subcollection"%fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
757 genObj.pageSizeSum=getattr(genObj,fileName).getPageSizeSum()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
758 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
759 genObj.pageSizeSum=genObj.getPageSizeSum()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
760
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
761 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
762 RESPONSE.write("</p>\n")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
763
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
764 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
765 error=sys.exc_info()[0:2]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
766 logging.error("updateCollection: ERROR in %s (%s %s)"%(fileName,error[0],error[1]))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
767 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
768 RESPONSE.write("(ERROR updateII(%s): %s %s %s) "%(fileName,error[0],error[1],sys.exc_info()[2]))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
769 errorsTXT+="<p>File not created:%s (ERROR: %s %s)</p>\n"%(fileName,error[0],error[1])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
770 return errorsTXT
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
771
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
772 def updateCollection(self,forceUpdate=True,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
773 """liest verzeichnisse aus dem pfad und legt sie dann als objekte in den ordner"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
774
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
775 # update subcollections
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
776 errorsTXT=""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
777 errorsTXT+=self.changeOrAddResources(forceUpdate, RESPONSE);
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
778 errorsTXT+=self.generateSubCollections(forceUpdate=forceUpdate,RESPONSE=RESPONSE)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
779 errorsTXT+="\n"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
780 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
781 RESPONSE.write(errorsTXT)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
782 RESPONSE.write("</body></html>")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
783
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
784 def updateCollectionMD(self,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
785 """updateMD"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
786 files=os.listdir(self.vlp_basis)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
787 for fileName in files:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
788 if fileName[0:3]=="lit":
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
789 genObj=getattr(self,fileName)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
790 genObj.copyIndex_meta2echo_resource()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
791 genObj.generate_title()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
792
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
793 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
794 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
795
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
796 def copyFullTextsFromDB(self,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
797 """copy fulltext aus DB"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
798
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
799 ress=self.ZopeFind(self,obj_metatypes=['VLP_resource'])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
800 ret=""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
801 for res in ress:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
802 tmp=res[1].copyTranscriptionFromDB()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
803 ret+=tmp
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
804
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
805 if RESPONSE:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
806 RESPONSE.write(tmp+"\n")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
807 if not RESPONSE:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
808 return ret
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
809 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
810 RESPONSE.write("END\n")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
811
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
812
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
813 def manage_addVLP_collectionForm(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
814 """Form for adding a ressource"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
815 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','AddVLP_collectionForm.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
816 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
817
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
818
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
819
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
820 def manage_addVLP_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,path,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag="",bgcolour=""):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
821 """add a echo collection"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
822
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
823
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
824 newObj=VLP_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag,bgcolour="")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
825
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
826 self._setObject(id,newObj)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
827 setattr(newObj,'path',path)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
828
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
829 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
830 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
831
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
832
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
833
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
834 class VLP_resource(ECHO_resource,Cacheable):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
835 """VLP spezifische Erweiterung"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
836
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
837 meta_type="VLP_resource"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
838
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
839 def _p_resolveConflict(self,oldstate,savedstate,newstate):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
840 logging.debug("updateCollection: Have to resolve conflict!")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
841 return newstate
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
842
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
843 #vlp_basis="/mpiwg/online/permanent/vlp"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
844
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
845
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
846
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
847 referencetypes=[]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
848
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
849 manage_options=ECHO_resource.manage_options+Cacheable.manage_options+(
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
850 {'label':'Update Index','action':'createIndexFile'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
851 {'label':'Reset MetaLink','action':'resetMetaLink'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
852 {'label':'Generate Title','action':'generate_title'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
853 {'label':'Generate Library Template','action':'generateLibraryTemplateHTML'},
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
854 )
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
855
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
856 def getMetaDataLink(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
857 """link auf die metatdaten"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
858 return self.absolute_url()+"/index_meta"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
859
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
860
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
861 def getTitle(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
862 """Title der Ressource"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
863 title= self.ZSQLSimpleSearch("""select title from vl_literature where reference= \'%s\' """ %self.getId())[0].title
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
864 logging.debug(title)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
865 return title
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
866
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
867
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
868
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
869 def getImagePath(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
870 """Pfad zu den Images"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
871 path=None
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
872
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
873 if os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pageimg')):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
874 path= os.path.join(self.vlp_basis,self.resourceID,'pageimg')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
875 elif os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pages')):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
876 path = os.path.join(self.vlp_basis,self.resourceID,'pages')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
877 # workaround in some cases there seem to be no pictures in pages
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
878
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
879 if os.path.isdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi')):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
880
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
881
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
882 pagesHi = os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi'))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
883 if path is None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
884 return os.path.join(self.vlp_basis,self.resourceID,'pagesHi')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
885
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
886 pages = os.listdir(path)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
887
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
888 if len (pagesHi) > len(pages):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
889
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
890 countHi=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
891 for p in pagesHi:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
892 dat,ext = os.path.splitext(p)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
893 if ext.lower() in [".tiff",".tif",".jpg"]:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
894 countHi+=1
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
895 count=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
896 for p in pages:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
897 dat,ext = os.path.splitext(p)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
898 if ext.lower() in [".tiff",".tif",".jpg"]:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
899 count+=1
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
900
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
901 if countHi > count:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
902 path=os.path.join(self.vlp_basis,self.resourceID,'pagesHi')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
903
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
904 logging.error("pages < pagesHi: %s"%self.resourceID)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
905 if path is None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
906
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
907
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
908 if len (os.listdir(os.path.join(self.vlp_basis,self.resourceID,'pagesHi'))) > len(os.listdir(path)):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
909
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
910
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
911
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
912 path=os.path.join(self.vlp_basis,self.resourceID,'pagesHi')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
913 logging.error("pages < pagesHi: %s"%self.resourceID)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
914 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
915
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
916 logging.error("no images: %s"%self.resourceID)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
917 return None
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
918
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
919 return path
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
920
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
921
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
922 def transcription(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
923 """show the rendered transcriptiofile"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
924
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
925 if hasattr(self,'libraryTranscriptionTemplate.html'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
926 return getattr(self,'libraryTranscriptionTemplate.html')()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
927
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
928 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','library_transcriptionTemplate.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
929 pt.content_type="text/html"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
930 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
931
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
932
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
933
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
934 def identifyMediaType(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
935 """identifiziert den Medientype aus der VLP Datenbank"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
936 founds=self.ZSQLSimpleSearch('select * from vl_literature where reference=\''+self.resourceID+'\' order by id')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
937 if (not founds) or (len(founds)==0):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
938 self.mediaType="generic" # steht nicht in der Datenbank, dann nimm generisch an
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
939 return self.mediaType
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
940
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
941
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
942 if founds[0].referencetype =="Audio":
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
943 self.mediaType ="audio"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
944 elif founds[0].referencetype =="Film":
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
945 self.mediaType ="video"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
946 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
947 self.mediaType ="image" # nimm an, dass alle anderen Eintrage in der Datenbank auf images verweisen (Buecher oder Fotografien).
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
948
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
949 return self.mediaType
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
950
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
951 def getMediaType(self,cached=False):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
952 """give the Media-type back, if chached False, then get it from the database"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
953
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
954 if (not hasattr(self,'mediaType')) or (self.mediaType=="") or (not cached):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
955 self.identifyMediaType()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
956
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
957 return self.mediaType
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
958
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
959
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
960
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
961
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
962 def copyTranscriptionFromDB(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
963 """checks if transcription exits in DB"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
964 founds=self.ZSQLSimpleSearch('select * from vl_transcript where source=\''+self.resourceID+'\' order by id')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
965
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
966
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
967 ret="""<?xml version="1.0" encoding="utf-8"?>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
968 <text>"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
969
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
970 if founds:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
971
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
972 for found in founds:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
973
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
974 text=found.transcript
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
975 if not text: text=""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
976 ret+="<page><pb/>"+text+"</page>"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
977
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
978 ret+="</text>"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
979 re2=ret[0:]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
980 re3=self.unicodify(re2)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
981 #re3=re2
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
982 ft=self.ZopeFind(self,obj_metatypes=['ECHO_fullText'])
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
983
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
984 if ft:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
985
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
986 ft[0][1].pt_edit(re3,'text/xml')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
987
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
988 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
989
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
990 self._setObject('fulltext',ECHO_fullText(id,''))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
991
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
992 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
993 getattr(self,'fulltext').pt_edit(re3.encode('utf-8','ignore'),'text/xml')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
994 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
995 getattr(self,'fulltext').pt_edit(re3.encode('latin-1').decode('utf-8'),'text/xml')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
996
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
997 return "FT: %s"%self.getId()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
998 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
999 return "no: %s"%self.getId()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1000
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1001 def hasTranscription(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1002 """transcription"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1003
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1004 if not hasattr(self,'fulltext'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1005 self.copyTranscriptionFromDB()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1006 if not hasattr(self,'fulltext'): #still not
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1007 return False
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1008
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1009 return True
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1010
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1011 def resetMetaLink(self,all="no",RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1012 """resets metalink to standard resp. in case of server change it sets to the new server url"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1013 if all=="yes":
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1014 self.metalink=self.absolute_url()+"/index_meta"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1015 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1016 splitted=self.metalink.split("/")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1017 if (len(splitted)>1) and (splitted[len(splitted)-1]=="index_meta") and (splitted[len(splitted)-2]==self.getId()): # heuristic nur generische Metadatafiles andern
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1018 self.metalink=self.absolute_url()+"/index_meta"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1019
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1020 if RESPONSE:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1021 return "done"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1022
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1023 def show(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1024 """show the rendered file"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1025
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1026 mt = self.getMediaType()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1027
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1028 if (mt in ['video','audio']):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1029 pt = self.getVLPTemplate('libraryMovieTemplate')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1030 else: #zur zeit werden alle anderen type auf das libraryTemplate abgebildet.
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1031
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1032 if self.REQUEST.get('p',None): #make sure that parameter p exists
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1033 #self.REQUEST.set('pn',self.file2page(self.REQUEST.get('p',None)))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1034 params = "pn=%s"%self.file2page(self.REQUEST.get('p',None))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1035 mk = self.REQUEST.get('mk',None)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1036 if mk:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1037 params += "&mk=%s"%mk
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1038 self.REQUEST.RESPONSE.redirect(self.REQUEST['URL']+'?'+params)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1039
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1040 pt = self.getVLPTemplate('libraryTemplate')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1041
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1042 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1043
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1044 def getVLPTemplate(self,name):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1045 html=name+".html"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1046 if hasattr(self,html):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1047 return getattr(self,html)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1048
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1049 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt',name+'.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1050 pt.content_type="text/html"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1051 return pt
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1052
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1053 def index_html(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1054 """index_html"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1055 #return self.REQUEST
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1056 if not self.REQUEST.has_key("ws"):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1057 self.REQUEST.form["ws"]="1.5"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1058
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1059 return self.show()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1060
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1061 def generateLibraryTemplateHTML(self,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1062 """lege standard index.html an"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1063
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1064 if not hasattr(self,'libraryTemplate.html'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1065 zt=ZopePageTemplate('libraryTemplate.html')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1066 self._setObject('libraryTemplate.html',zt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1067 default_content_fn = os.path.join(package_home(globals()),
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1068 'zpt/library_template.zpt')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1069 text = open(default_content_fn).read()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1070 zt.pt_edit(text, 'text/html')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1071
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1072 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1073 return "already exists!"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1074
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1075 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1076 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1077
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1078
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1079 def index_meta(self,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1080 """index_meta"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1081
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1082 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','index_meta.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1083 pt.content_type="text/xml"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1084 x= pt.pt_render()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1085 #logging.debug("index_meta 4:"+x)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1086 if RESPONSE:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1087 RESPONSE.setHeader("Content-Type","text/xml")
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1088 return x
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1089 def file2page(self,p):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1090 """converts filename to pagenumber"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1091
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1092 #dom=xml.dom.minidom.parse(ECHO_helpers.urlopen(getattr(self,'index.xml').absolute_url()))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1093 index=getattr(self,'index.xml')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1094
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1095 txt=index.pt_render()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1096 dom=xml.dom.minidom.parseString(txt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1097
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1098 for page in dom.getElementsByTagName('page'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1099 # pageummer mit lo oder hi sind aequivalent
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1100 if (page.getAttribute('file')==p) or ("%slo"%page.getAttribute('file')==p) or ("%shi"%page.getAttribute('file')==p):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1101 nr=page.getAttribute('nr')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1102
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1103 return nr
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1104
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1105 return 0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1106
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1107 def getPageSizeSum(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1108 """generate average page size"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1109
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1110 #size of hi resolution
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1111 files=[]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1112 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1113 pathHi=os.path.join(self.vlp_basis,self.resourceID,'pages')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1114 files=os.listdir(pathHi)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1115 hi=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1116 for f in files:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1117 hi+=os.stat(os.path.join(pathHi,f))[ST_SIZE]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1118
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1119 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1120 hi=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1121
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1122 #size of hi resolution
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1123 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1124 pathHi=os.path.join(self.vlp_basis,self.resourceID,'pagesLo')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1125 files=os.listdir(pathHi)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1126 lo=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1127 for f in files:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1128 lo+=os.stat(os.path.join(pathHi,f))[ST_SIZE]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1129
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1130 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1131 lo=0
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1132
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1133
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1134 return (hi,lo,len(files))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1135
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1136
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1137 def getPageWeights(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1138 """average Page sizes in kBytes"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1139
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1140 res=getattr(self,'pageSizeSum',(0,0,1))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1141 return (res[0]/(1024*res[2]),res[1]/(1024*res[2]))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1142
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1143
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1144
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1145 def dir2index(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1146 """dir to index"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1147
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1148 excludeNames=['Icon']
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1149
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1150
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1151 def calculateName(str):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1152 name=os.path.splitext(str[1:])[0]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1153 ret="%s: %s"%(str[0],name)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1154 return ret
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1155
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1156 self.imagePathFull=self.getImagePath();
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1157 self.imagePath=self.imagePathFull.split("/")[-1]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1158 if (self.imagePath is None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1159 return None
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1160
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1161 temp=[]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1162 ret = os.listdir(self.imagePathFull)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1163
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1164 ret.sort()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1165 for x in ret:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1166 if (not (x[0] in ('.',':'))) and (not x[0:4] in excludeNames):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1167 temp.append((calculateName(x),os.path.splitext(x)[0]))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1168 return temp
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1169
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1170
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1171 def firstPage(self,url=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1172 """showlink to the first image"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1173 if self.REQUEST.get('pn','1')=="1": #erste seinte dann kein a tag
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1174 return """<img src="/images/first.gif" alt="first" width="14" height="14" border="0"><br>first"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1175
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1176 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1177 ws=self.REQUEST.get('ws','1')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1178 return """<a href=%s>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1179 <img src="/images/first.gif" alt="first" width="14" height="14" border="0"><br>first
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1180 </a>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1181 """%(self.REQUEST['URL']+"?pn=1&ws=%s"%ws)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1182
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1183 def lastPage(self,url=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1184 """showlink to the first image"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1185 pages=self.readIndexFile(url)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1186 if pages:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1187 ln=len(pages)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1188
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1189 if (self.REQUEST.get('pn')==str(ln)) or (ln==1): #letzte seite dann kein a tag oder nur eine Seite
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1190 return """<img src="/images/last.gif" alt="last" width="14" height="14" border="0"><br>last"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1191
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1192 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1193 ws=self.REQUEST.get('ws','1')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1194 return """<a href=%s>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1195 <img src="/images/last.gif" alt="last" width="14" height="14" border="0"><br>last
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1196 </a>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1197 """%(self.REQUEST['URL']+"?pn="+str(ln)+"&ws="+ws)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1198
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1199 def prevPage(self,url=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1200 """showlink to the first image"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1201
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1202
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1203 nn = int(self.REQUEST.get('pn','1'))-1
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1204 if nn < 1: #letzte seite dann kein a tag
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1205 return """<img src="/images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1206
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1207 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1208 ws=self.REQUEST.get('ws','1')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1209 return """<a href=%s>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1210 <img src="/images/lisePrev.gif" alt="prev" width="14" height="14" border="0"><br>prev
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1211 </a>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1212 """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1213
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1214 def nextPage(self,url=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1215 """showlink to the first image"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1216 pages=self.readIndexFile(url)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1217 if pages:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1218 ln=len(pages)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1219
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1220 nn = int(self.REQUEST.get('pn','1'))+1
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1221 if (nn>int(ln)) or (ln==1): #letzte seite dann kein a tag
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1222 return """<img src="/images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1223
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1224 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1225 ws=self.REQUEST.get('ws','1')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1226 return """<a href=%s>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1227 <img src="/images/liseNext.gif" alt="next" width="14" height="14" border="0"><br>next
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1228 </a>
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1229 """%(self.REQUEST['URL']+"?pn="+str(nn)+"&ws="+ws)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1230
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1231
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1232 def readIndexFile(self,url=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1233 """reads the indexfile. presently url not None isn't implemented. In the future url can be defined."""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1234 if not url:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1235 urlTmp=self.absolute_url()+"/index.xml"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1236
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1237 if self.ZCacheable_isCachingEnabled():
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1238
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1239 result = self.ZCacheable_get(view_name=urlTmp)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1240 if result is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1241 # Got a cached value.
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1242 return result
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1243
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1244 pagelist=[]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1245
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1246 if not url:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1247
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1248 xmlTxt=getattr(self,'index.xml')()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1249 dom=xml.dom.minidom.parseString(xmlTxt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1250 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1251 fh=ECHO_helpers.urlopen(urlTmp)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1252 dom=xml.dom.minidom.parse(fh)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1253
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1254
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1255 for page in dom.getElementsByTagName('page'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1256 text=getText(page.childNodes)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1257 pageNum=page.getAttribute('nr')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1258 fileName=page.getAttribute('file')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1259 pagelist.append((pageNum,text,fileName))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1260
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1261 self.ZCacheable_set(pagelist,view_name=urlTmp)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1262 return pagelist
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1263
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1264 def getFileName(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1265 """getNameOfCurrentFile"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1266 try:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1267 pn=int(self.REQUEST.get('pn','1'))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1268 except:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1269 pn=1
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1270 pageinfo=self.readIndexFile()[pn-1]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1271 return pageinfo[2]
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1272
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1273 def createIndexFile(self,forceUpdate=False,RESPONSE=None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1274 """create index file"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1275 logging.debug("createindexfile of %s"%self.id)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1276
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1277 if hasattr(self,'index.xml'):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1278 # index exists
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1279 zt=getattr(self,'index.xml')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1280 if not forceUpdate:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1281 # check if directory is newer (self.imagePath sould be set by now)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1282 path = self.getImagePath()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1283 if (path is None):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1284 return "CREATE INDEX FILE NOT POSSIBLE"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1285 imgdir = os.path.join(path)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1286 dirtime = os.path.getmtime(imgdir)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1287 zttime = zt.bobobase_modification_time()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1288 logging.debug("createindexfile: dir %s of %s index of %s"%(imgdir,dirtime,zttime))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1289 if dirtime < zttime:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1290 # nothing to do
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1291 logging.debug("createindexfile: dir %s older than index"%(imgdir))
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1292 return "index is up to date"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1293
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1294 else:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1295 # create new index template
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1296 zt=ZopePageTemplate('index.xml')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1297 self._setObject('index.xml',zt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1298
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1299 # fill index template
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1300 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','index_template.zpt')).__of__(self)()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1301 #logging.debug("createindexfile uses %s"%pt)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1302 zt.pt_edit(pt, 'text/xml')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1303 transaction.get().commit()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1304
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1305 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1306 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1307
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1308
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1309 def manage_addVLP_resourceForm(self):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1310 """Form for adding a ressource"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1311 pt=PageTemplateFile(os.path.join(package_home(globals()),'zpt','AddVLP_resourceForm.zpt')).__of__(self)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1312 return pt()
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1313
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1314
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1315
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1316 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):
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1317 """addaresource"""
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1318
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1319
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1320 if metalink=='':
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1321 metalink=self.absolute_url()+"/"+id+"/index_meta"
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1322
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1323 newObj=VLP_resource(id,link,metalink,resourceID,title,label,description,contentType,renderingType,responsible,credits,weight,coords)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1324
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1325 self._setObject(id,newObj)
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1326
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1327 if RESPONSE is not None:
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1328 RESPONSE.redirect('manage_main')
88009fd07d31 VLP specific additions to ECHO_content product. First checkin.
casties
parents:
diff changeset
1329