1: """New version of the product started February, 8th. Without scientific classification, use content-type for further classification."""
2: """Echo collection provides the classes for the ECHO content web-site.
3:
4: class ECHO_collection is the basis class for an ECHO collection.
5:
6: class ECHO_resource contains information on ECHO resources (e.g. an Display environment for Metadata
7:
8: class ECHO_externalLink contains information on externalLinks
9:
10:
11: """
12: import string
13: import re
14: import os
15: import OFS.Image
16: from types import *
17: from OFS.Image import Image
18: from Globals import DTMLFile
19: from OFS.Folder import Folder
20: from OFS.SimpleItem import SimpleItem
21: from AccessControl import ClassSecurityInfo
22: from Globals import InitializeClass
23: from Globals import DTMLFile
24: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
25: from Products.PageTemplates.PageTemplate import PageTemplate
26: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
27: from Globals import Persistent, package_home
28: from Acquisition import Implicit
29: from ECHO_helpers import displayTypes
30: try:
31: from psycopg import libpq
32: except:
33: try:
34: from pyPgSQL import libpq
35: except:
36: print "ECHO_collection: Warning - No libpq imported!"
37:
38: import xml.dom.minidom
39:
40: import urllib
41: import xml.dom.minidom
42: from ECHO_graphicalOverview import javaHandler,javaScriptMain
43: import ECHO_helpers
44:
45: #List of different types for the graphical linking viewer
46: viewClassificationListMaster=['view point','area']
47:
48: def content_html(self,type):
49: """template fuer content"""
50: #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"])
51: #
52: #if templates:
53: # return templates[0][1]()
54:
55: try:
56: obj=getattr(self,type+"_template")
57: return obj()
58: except:
59: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_%s_template_standard.zpt'%type).__of__(self)
60: pt.content_type="text/html"
61: return pt()
62:
63: def toList(field):
64: """Einzelfeld in Liste umwandeln"""
65: if type(field)==StringType:
66: return [field]
67: else:
68: return field
69:
70: def getText(nodelist):
71:
72: rc = ""
73: for node in nodelist:
74: if node.nodeType == node.TEXT_NODE:
75: rc = rc + node.data
76: return rc
77:
78:
79: def sendFile(self, filename, type):
80: """sends an object or a local file (in the product) as response"""
81: paths = filename.split('/')
82: object = self
83: # look for an object called filename
84: for path in paths:
85: if hasattr(object, path):
86: object = getattr(object, path)
87: else:
88: object = None
89: break
90: if object:
91: # if the object exists then send it
92: object()
93: else:
94: # send a local file with the given content-type
95: fn = os.path.join(package_home(globals()), filename)
96: self.REQUEST.RESPONSE.setHeader("Content-Type", type)
97: self.REQUEST.RESPONSE.write(file(fn).read())
98: return
99:
100:
101: def readMetadata(url):
102: """Methoden zum Auslesen der Metadateninformation zu einer Resource
103: Vorerst noch Typ bib"""
104:
105: metadict={}
106: try:
107: geturl=""
108: for line in urllib.urlopen(url).readlines():
109: geturl=geturl+line
110:
111:
112: except:
113: return (None,"Cannot open: "+url)
114:
115: try:
116: dom=xml.dom.minidom.parseString(geturl)
117: except:
118: return (None,"Cannot parse: "+url+"<br>"+geturl)
119:
120: metanode=dom.getElementsByTagName('bib')
121: metadict['bib_type']='Book'
122: if len(metanode)==0:
123: metanode=dom.getElementsByTagName('archimedes')
124: metadict['bib_type']='Archimedes'
125: #print "HELLO"
126:
127: if not len(metanode)==0:
128: metacontent=metanode[0].childNodes
129:
130: try:
131: metadict['bib_type']=getText(dom.getElementsByTagName('bib')[0].attributes['type'].childNodes)
132: except:
133: """nothing"""
134:
135: for node in metacontent:
136: try:
137: metadict[node.tagName.lower()]=getText(node.childNodes)
138: except:
139: """nothing"""
140:
141: #print metadict
142: return metadict,""
143:
144:
145: def setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordstrs,viewClassification=""):
146:
147: """Allegemeine Informationen zu einer ECHO Collection"""
148:
149: self.viewClassification=viewClassification
150:
151: self.label = label
152: self.title=title
153: self.description=description
154: self.contentType=contentType
155: self.responsible=responsible
156: self.credits=toList(credits)
157: self.weight=weight
158:
159: coords=[]
160: #coordinates of for rectangles
161:
162: #print "cs", coordstrs
163: if coordstrs:
164: for coordstr in coordstrs:
165: #print "cs", coordstr
166: try:
167: temco=coordstr.split(",")
168: except:
169: temco=[]
170: #temco.append(angle)
171: coords.append(temco)
172:
173:
174: self.coords=coords[0:]
175:
176:
177: class scientificClassification(SimpleItem,Persistent,Implicit):
178: """outdated will be deleeted in the next versions: subclass"""
179: security=ClassSecurityInfo()
180:
181: def __init__(self,context,science,practice):
182: self.context=context
183: self.science=science
184: self.practice=practice
185: self.id="scientific_Classification"
186:
187: security.declarePublic('get_context')
188: def get_context(self):
189: return self.context
190:
191: security.declarePublic('get_science')
192: def get_science(self):
193: return self.science
194:
195: security.declarePublic('get_practice')
196: def get_practice(self):
197: return self.practice
198:
199:
200: class scientificInformation(Folder,Persistent,Implicit):
201: """outdated will be deleted in the next versions: subclass scientificInformation"""
202: security=ClassSecurityInfo()
203:
204:
205:
206: def __init__(self,source_type,period):
207:
208: self.id="scientific_Information"
209: self.source_type=source_type
210: self.period=period
211:
212:
213:
214: security.declarePublic('get_source_type')
215: def get_source_type(self):
216: return self.source_type
217:
218: security.declarePublic('get_period')
219: def get_period(self):
220: return self.period
221:
222: class ECHO_layoutTemplate(ZopePageTemplate):
223: """Create a layout Template for different purposes"""
224:
225: meta_type="ECHO_layoutTemplate"
226:
227: def __init__(self, id, text=None, content_type=None,EchoType=None):
228: self.id = str(id)
229:
230:
231:
232: self.ZBindings_edit(self._default_bindings)
233: if text is None:
234: self._default_content_fn = os.path.join(package_home(globals()),
235: 'zpt/ECHO_%s_template_standard.zpt'%EchoType)
236: text = open(self._default_content_fn).read()
237: self.pt_edit(text, content_type)
238:
239:
240: """change form"""
241:
242:
243: def manage_addECHO_layoutTemplateForm(self):
244: """Form for adding"""
245: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_layoutTemplate.zpt').__of__(self)
246: return pt()
247:
248: from urllib import quote
249:
250:
251: def manage_addECHO_layoutTemplate(self, EchoType,title=None,REQUEST=None):
252: "Add a Page Template with optional file content."
253: if type(EchoType)==StringType:
254: EchoTypes=[EchoType]
255: else:
256: EchoTypes=EchoType
257:
258: for singleType in EchoTypes:
259:
260: id = str(singleType)+"_template"
261: if REQUEST is None:
262: self._setObject(id, ECHO_layoutTemplate(id, text,EchoType=singleType))
263: ob = getattr(self, id)
264:
265: if title:
266: ob.pt_setTitle(title)
267: return ob
268: else:
269: file = REQUEST.form.get('file')
270: headers = getattr(file, 'headers', None)
271: if headers is None or not file.filename:
272: zpt = ECHO_layoutTemplate(id,EchoType=singleType)
273: else:
274: zpt = ECHO_layoutTemplate(id, file, headers.get('content_type'))
275:
276: self._setObject(id, zpt)
277: ob = getattr(self, id)
278: if title:
279: ob.pt_setTitle(title)
280:
281: try:
282: u = self.DestinationURL()
283: except AttributeError:
284: u = REQUEST['URL1']
285:
286:
287: REQUEST.RESPONSE.redirect(u+'/manage_main')
288: return ''
289:
290: class ECHO_resource(Folder):
291: """ECHO Ressource"""
292: meta_type='ECHO_resource'
293:
294: viewClassificationList=viewClassificationListMaster
295:
296: getSubCols = ECHO_helpers.getSubCols
297: def getTitle(self):
298: """title"""
299: return self.title.encode('utf-8')
300:
301: def getLabel(self):
302: """title"""
303: return self.label.encode('utf-8')
304:
305: def content_html(self):
306: """template fuer content"""
307: return content_html(self,'resource')
308:
309: def getViewClassification(self):
310: if hasattr(self,'viewClassification'):
311: return self.viewClassification
312: else:
313: return ""
314:
315: def getCredits(self):
316: """Ausgabe der credits"""
317: if self.credits:
318: return self.credits
319: else:
320: return []
321:
322: def __init__(self,id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords):
323:
324: self.id = id
325: """Festlegen der ID"""
326:
327: self.label = label
328: self.link= link
329: self.metalink=metalink
330: self.title=title
331: self.weight=weight
332: self.credits=toList(credits)
333: self.description=description
334: self.contentType=contentType
335: self.responsible=responsible
336:
337: if coords:
338: coordsnew=[ string.split(x,",") for x in coords]
339: else:
340: coordsnew=[]
341:
342: self.coords=coordsnew
343:
344:
345: def getCoords(self):
346: try:
347: return [string.join(x,",") for x in self.coords]
348: except:
349: return []
350:
351: def getContentType(self):
352: try:
353: return self.contentType
354: except:
355: return ""
356:
357: def ECHO_resource_config(self):
358: """Main configuration"""
359:
360: if not hasattr(self,'weight'):
361: self.weight=""
362: if not hasattr(self,'coords'):
363: self.coords=[]
364:
365: print "vorher",self.coords
366: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource.zpt').__of__(self)
367: return pt()
368:
369:
370: def changeECHO_resource(self,metalink,link,title,label,description,contentType,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None):
371: """Änderung der Properties"""
372:
373: try:
374: coordsnew=[ string.split(x,",") for x in coords]
375: except:
376: coordsnew=[]
377:
378: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
379: self.viewClassification=viewClassification
380: self.coords=coordsnew[0:]
381: self.link=link
382: self.metalink=metalink
383:
384: if RESPONSE is not None:
385: RESPONSE.redirect('manage_main')
386:
387:
388: manage_options = Folder.manage_options+(
389: {'label':'Main Config','action':'ECHO_resource_config'},
390: {'label':'Metadata','action':'ECHO_getResourceMD'},
391: {'label':'Graphics','action':'ECHO_graphicEntry'},
392: )
393:
394: def getOverview(self):
395: """overview graphics"""
396:
397: return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
398:
399: def ECHO_graphicEntry(self):
400: """DO nothing"""
401: overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
402: if overview:
403: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
404: return pt()
405: else:
406: return "NO OVERVIEW GRAPHICS"
407:
408: def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
409: """Enter coords"""
410: coords=self.coords
411: temco=coordstr.split(",")
412: temco.append(angle)
413: coords.append(temco)
414:
415: self.coords=coords[0:]
416:
417: if RESPONSE is not None:
418: RESPONSE.redirect('ECHO_graphicEntry')
419:
420: def ECHO_getResourceMD(self,template="yes"):
421: """Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource"""
422: (metadict, error)=readMetadata(self.metalink)
423:
424:
425:
426: if not error=="": #Fehler beim Auslesen des Metafiles
427: return "ERROR:",error
428: for key in metadict.keys():#Hinzufügen der Felder
429:
430: setattr(self,key,metadict[key].encode('ascii','replace'))
431:
432:
433: self.metadata=metadict.keys()
434:
435: self.label=self.generate_label()
436:
437: if template=="yes":
438: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_resourceMD.zpt').__of__(self)
439: return pt()
440:
441: def ECHO_getMD(self,item):
442: """Ausgabe der MD"""
443: return getattr(self,item)
444:
445: def index_html(self):
446: """standard page"""
447:
448: return self.REQUEST.RESPONSE.redirect(self.link)
449:
450: def generate_label(self):
451: """Erzeugt_standard_Label aus Template"""
452: pt=getattr(self,"label_template_"+self.bib_type)
453:
454: return pt()
455:
456: def manage_addECHO_resourceForm(self):
457: """Form for adding a ressource"""
458: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_resourceForm.zpt').__of__(self)
459: return pt()
460:
461:
462:
463: def manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
464: """addaresource"""
465:
466: newObj=ECHO_resource(id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords)
467:
468: self._setObject(id,newObj)
469:
470: if RESPONSE is not None:
471: RESPONSE.redirect('manage_main')
472:
473:
474: class ECHO_externalLink(Folder):
475: """Link zu einer externen Ressource"""
476: security=ClassSecurityInfo()
477: meta_type='ECHO_externalLink'
478:
479: def getTitle(self):
480: """title"""
481: return self.title.encode('utf-8')
482:
483: def getLabel(self):
484: """title"""
485: return self.label.encode('utf-8')
486:
487: def content_html(self):
488: """template fuer content"""
489: return content_html(self,'externalLink')
490:
491: def __init__(self,id,link,title,label,description,contentType,responsible,credits,weight,coords):
492:
493: self.id = id
494: """Festlegen der ID"""
495:
496: self.credits=toList(credits)
497: self.label = label
498: self.link= link
499: self.title=title
500: self.weight=weight
501: self.description=description
502: self.contentType=contentType
503: self.responsible=responsible
504: coordsnew=[ string.split(x,",") for x in coords]
505: self.coords=coordsnew
506:
507: def ECHO_externalLink_config(self):
508: """Main configuration"""
509:
510: if not hasattr(self,'weight'):
511: self.weight=""
512: if not hasattr(self,'coords'):
513:
514: self.coords=['']
515: #print "G",self.coords
516:
517: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_externalLink.zpt').__of__(self)
518: return pt()
519:
520:
521: def changeECHO_externalLink(self,link,title,label,description,contentType,responsible,weight,coords=None,credits=None,RESPONSE=None):
522:
523: """Änderung der Properties"""
524: try:
525: coordsnew=[ string.split(x,",") for x in coords]
526: except:
527: coordsnew=[]
528:
529: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coords)
530:
531: self.coords=coordsnew[0:]
532: self.link=link
533: if RESPONSE is not None:
534: RESPONSE.redirect('manage_main')
535:
536:
537: manage_options = Folder.manage_options+(
538: {'label':'Main Config','action':'ECHO_externalLink_config'},
539: )
540:
541: def getCredits(self):
542: """Ausgabe der credits"""
543: if self.credits:
544: return self.credits
545: else:
546: return []
547:
548: def index_html(self):
549: """standard page"""
550:
551: return self.REQUEST.RESPONSE.redirect(self.link)
552:
553: def manage_addECHO_externalLinkForm(self):
554: """Form for external Links"""
555: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
556: return pt()
557:
558:
559: def manage_addECHO_externalLink(self,id,title,label,description,contentType,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
560: """Add an external Link"""
561:
562: newObj=ECHO_externalLink(id,link,title,label,description,contentType,responsible,credits,weight,coords)
563:
564: self._setObject(id,newObj)
565:
566: if RESPONSE is not None:
567: RESPONSE.redirect('manage_main')
568:
569:
570: class ECHO_link(ECHO_externalLink):
571: """external_link"""
572:
573: meta_type="ECHO_link"
574:
575:
576: def content_html(self):
577: """template fuer content"""
578: return content_html(self,'link')
579:
580: def manage_addECHO_linkForm(self):
581: """Form for external Links"""
582: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_linkForm.zpt').__of__(self)
583: return pt()
584:
585:
586: def manage_addECHO_link(self,id,title,label,description,contentType,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
587: """Add an external Link"""
588:
589: newObj=ECHO_link(id,link,title,label,description,contentType,responsible,credits,weight,coords)
590:
591: self._setObject(id,newObj)
592:
593: if RESPONSE is not None:
594: RESPONSE.redirect('manage_main')
595:
596:
597: class ECHO_collection(Folder, Persistent, Implicit):
598: """ECHO Collection"""
599: security=ClassSecurityInfo()
600: meta_type='ECHO_collection'
601: viewClassificationList=viewClassificationListMaster
602: displayTypes=displayTypes
603:
604: def getViewClassification(self):
605: if hasattr(self,'viewClassification'):
606: return self.viewClassification
607: else:
608: return ""
609:
610: def getTitle(self):
611: """title"""
612: return self.title.encode('utf-8')
613:
614: def getLabel(self):
615: """title"""
616: return self.label.encode('utf-8')
617:
618: def createRessourcesFromXMLForm(self):
619: """form"""
620: pt=PageTemplateFile('Products/ECHO_content/zpt/createRessourcesFromXMLForm.zpt').__of__(self)
621: return pt()
622: def createRessourcesFromXML(self,fileupload):
623: """read an XML file for generating resources"""
624: dom=xml.dom.minidom.parse(fileupload)
625: ret="<h2>Added</h2>"
626: for resource in dom.getElementsByTagName('resource'):
627: link=getText(resource.getElementsByTagName('link')[0].childNodes)
628: label=getText(resource.getElementsByTagName('label')[0].childNodes)
629: #splitted=link.split("?")[0].split("/")
630: #id=splitted[len(splitted)-1].encode('ascii')
631: id=re.sub(" ","_",label).encode('ascii')
632:
633: ret+="<p>"+label+"</p>"
634: manage_addECHO_resource(self,id,label.encode('ascii'),label.encode('ascii'),"","","",link.encode('ascii'),"","")
635: return ret
636: def getImageTag(self):
637: """GetTag"""
638: try:
639: return self.imageTag
640: except:
641: return ""
642:
643: def addResource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
644: """SSS"""
645: try:
646: manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None)
647: return "done"
648: except:
649: return None
650:
651: def getSecondaryLink(self):
652: """secondary link"""
653: try:
654: return self.secondaryLink
655: except:
656: return ""
657:
658: def getSecondaryLinkTitle(self):
659: """secondary link"""
660: try:
661: return self.secondaryLinkTitle
662: except:
663: return ""
664:
665: def getCollectionTreeXML(self):
666: """Tree as XML"""
667:
668: def getCollection(object,depth=0):
669: depth+=1
670: collections=""
671: for entry in object.__dict__.keys():
672: element=getattr(object,entry)
673: try:
674: if element.meta_type in ["ECHO_collection","ECHO_group"]:
675: collections+="<element name=\""+quote(element.title)+"\" url=\""+element.absolute_url()+"\">"
676: collections+=getCollection(element,depth)+"</element>\n"
677: except:
678: """nothing"""
679: return collections
680:
681: ret="""<?xml version="1.0" encoding="utf-8" ?>"""
682: return ret+"<collection>"+getCollection(self)+"</collection>"
683:
684: def createJavaScript(self):
685: """CreateJava"""
686: #ret=javaScriptMain
687: ret=""
688:
689: dynamical="\n"
690: for ob in self.getGraphicCoords():
691: if ob[4][4] == "":
692: #dynamical+="""Coords.push(new Coord('%s', Img, %s));\n"""%(ob[1],ob[0])
693: dynamical+="""addArea('%s', 'overview', %s, 'area');\n"""%(ob[1],ob[0])
694: else:
695: dynamical+="""addArea('%s', 'overview', %s, 'arrow');\n"""%(ob[1],ob[0])
696: #dynamical+="""Coords.push(new Coord('%s', Img, %s));//%s\n"""%(ob[1],ob[0],ob[4][4])
697: #dynamical+="ShowArrow(new getObj('i.%s'),Img,%s);\n"%(ob[1],ob[0])
698: #ret+=javaHandler%dynamical
699: ret+=dynamical
700: return ret
701:
702: security.declarePublic('getCreditObject')
703: def getCreditObject(self,name):
704: """credit id to credititem"""
705: try:
706: return getattr(self.partners,name)
707: except:
708: return ""
709:
710: security.declarePublic('ECHO_generateNavBar')
711: def ECHO_generateNavBar(self):
712: """Erzeuge Navigationsbar"""
713: link=""
714: object="self"
715: ret=[]
716: path=self.getPhysicalPath()
717: for element in path:
718:
719:
720: if not element=="":
721: object+="."+element
722:
723: label=eval(object).label
724: link+="/"+element
725: if not label=="":
726: ret.append((label,link))
727: return ret
728:
729: security.declarePublic('ECHO_rerenderLinksMD')
730: def ECHO_rerenderLinksMD(self,obj=None):
731: """Rerender all Links"""
732: if not obj:
733: obj = self
734:
735: entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
736:
737: for entry in entries:
738: if entry[1].meta_type == 'ECHO_resource':
739: entry[1].ECHO_getResourceMD(template="no")
740: print "rerender",entry[1].getId()
741: else:
742: self.ECHO_rerenderLinksMD(entry[1])
743:
744:
745:
746: return "Rerenderd all links to resources in: "+self.title
747:
748: security.declarePublic('ECHO_newViewerLink')
749:
750:
751: def getCoords(self):
752: try:
753:
754: x= [string.join(x,",") for x in self.coords]
755: return x
756:
757: except:
758:
759: return []
760:
761: def __init__(self,id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle,secondaryLink,imageTag="",bgcolour=""):
762: #print "CO",coords
763:
764: self.id = id
765: """Festlegen der ID"""
766: self.credits=toList(credits)
767: self.label = label
768: self.title=title
769: self.description=description
770: self.contentType=contentType
771: self.responsible=responsible
772: self.imageTag=imageTag
773: self.weight=weight
774: self.sortfield=sortfield
775: coordsnew=[ string.split(x,",") for x in coords]
776: self.coords=coordsnew
777: self.secondaryLinkTitle=secondaryLinkTitle
778: self.secondaryLink=secondaryLink
779: self.bgcolour=bgcolour
780:
781:
782: manage_options = Folder.manage_options+(
783: {'label':'Main Config','action':'ECHO_collection_config'},
784: {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
785: {'label':'Graphics','action':'ECHO_graphicEntry'},
786: {'label':'create resources from XML','action':'createRessourcesFromXMLForm'},
787:
788: )
789:
790: def getOverview(self):
791: """overview graphics"""
792:
793: return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
794:
795:
796: def ECHO_graphicEntry(self):
797: """DO nothing"""
798: overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
799:
800:
801: if overview:
802: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
803: return pt()
804: else:
805: return "NO OVERVIEW GRAPHICS"
806:
807: def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
808: """Enter coords"""
809: coords=self.coords
810: temco=coordstr.split(",")
811: temco.append(angle)
812: coords.append(temco)
813: self.coords=coords[0:]
814:
815: if RESPONSE is not None:
816: RESPONSE.redirect('ECHO_graphicEntry')
817:
818:
819: security.declarePublic('ECHO_collection_config')
820: def ECHO_collection_config(self):
821: """Main configuration"""
822:
823: if not hasattr(self,'weight'):
824: self.weight=""
825:
826: if not hasattr(self,'sortfield'):
827: self.sortfield="weight"
828:
829: if not hasattr(self,'coords'):
830: self.coords=[]
831:
832: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
833: return pt()
834:
835:
836: security.declarePublic('changeECHO_collection')
837:
838:
839: def getBgcolour(self):
840: """colour"""
841: if hasattr(self,'bgcolour') and not (self.bgcolour==""):
842: return self.bgcolour
843: else:
844: return "#dddddd"
845:
846: def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag="",bgcolour="",viewClassification=None):
847: """Änderung der Properties"""
848:
849: self.secondaryLink=secondaryLink
850: self.secondaryLinkTitle=secondaryLinkTitle
851: self.imageTag=imageTag
852: self.bgcolour=bgcolour
853: self.viewClassification=viewClassification
854:
855: if coords:
856: coordsnew=[ string.split(x,",") for x in coords]
857: self.coords=coordsnew[0:]
858: else:
859: coordsnew=None
860: self.coords=None
861:
862: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
863: try:
864: self.coords=coordsnew[0:] # HACK fehler in setECHO_collection
865: except:
866: """none"""
867:
868: self.sortfield=sortfield
869:
870: if RESPONSE is not None:
871: RESPONSE.redirect('manage_main')
872:
873: security.declarePublic('index_html')
874:
875:
876: def showOverview(self):
877: """overview"""
878: if 'ECHO_overview.html' in self.__dict__.keys():
879: return getattr(self,'ECHO_overview.html')()
880: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_overview.zpt').__of__(self)
881: return pt()
882:
883:
884: def index_html(self):
885: """standard page"""
886:
887: if 'index.html' in self.__dict__.keys():
888: return getattr(self,'index.html')()
889:
890: elif 'overview' in self.__dict__.keys():
891: return self.showOverview()
892: elif hasattr(self,'collection_index_template'):
893: return self.collection_index_template()
894: elif hasattr(self,'main_index_template'):
895: return self.main_index_template()
896:
897: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_main_index_template_standard.zpt').__of__(self)
898: pt.content_type="text/html"
899: return pt()
900:
901: def content_html(self):
902: """template fuer content"""
903: return content_html(self,'collection')
904:
905: def getCredits(self):
906: """Ausgabe der credits"""
907: if self.credits:
908: return self.credits
909: else:
910: return []
911:
912: def area_img(self):
913: """area image"""
914: sendFile(self, 'images/red.gif', 'image/gif')
915: return
916:
917: def hl_lib_js(self):
918: """javascript"""
919: sendFile(self, 'js/hl_lib.js', 'text/plain')
920: return
921:
922: def js_lib_js(self):
923: """javascript"""
924: sendFile(self, 'js/js_lib.js', 'text/plain')
925: return
926:
927:
928: def getGraphicCoords(self):
929: """Give list of coordinates"""
930: subColTypes=['ECHO_collection','ECHO_resource']
931: ids=[]
932: for entrySearch in self.ZopeFind(self,obj_metatypes=subColTypes):
933: object=entrySearch[1]
934: if hasattr(object,'coords'):
935: for coordtemp in object.coords:
936: if len(coordtemp)>3:
937: coord=coordtemp[0:4]
938: label=""
939: if hasattr(object,'label') and not object.label=="":
940: label=object.label
941: elif hasattr(object,'title') and not object.title=="":
942: label=object.title
943: else:
944: label=object.getId()
945: ids.append([string.join(coord,", "),object.getId(),label,object,coordtemp,object.viewClassification])
946: return ids
947:
948:
949:
950:
951: getSubCols = ECHO_helpers.getSubCols
952:
953:
954:
955:
956: def manage_addECHO_collectionForm(self):
957: """Add collection form"""
958: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
959: return pt()
960:
961:
962: def manage_addECHO_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag="",bgcolour=""):
963: """add a echo collection"""
964:
965:
966: newObj=ECHO_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag,bgcolour="")
967:
968: self._setObject(id,newObj)
969:
970: if RESPONSE is not None:
971: RESPONSE.redirect('manage_main')
972:
973: class ECHO_group(ECHO_collection):
974: """ECHO Gruppe"""
975: meta_type="ECHO_group"
976:
977: manage_options = Folder.manage_options+(
978: {'label':'Main Config','action':'ECHO_group_config'},
979: {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
980: {'label':'Graphics','action':'ECHO_graphicEntry'},
981: )
982:
983: def index_html(self):
984: """standard page"""
985: displayedObjects=self.ZopeFind(self,obj_metatypes=displayTypes)
986: #if (len(displayedObjects)==1) and (displayedObjects[0][1].meta_type=="ECHO_collection"): # nur ein Object dann redirect auf dieses Object
987: # return self.REQUEST.RESPONSE.redirect(displayedObjects[0][1].absolute_url())
988:
989: if 'index.html' in self.__dict__.keys():
990: return getattr(self,'index.html')()
991:
992: elif 'overview' in self.__dict__.keys():
993: return self.showOverview()
994: elif hasattr(self,'group_index_template'):
995: return self.group_index_template()
996: elif hasattr(self,'collection_index_template'):
997: return self.collection_index_template()
998: elif hasattr(self,'main_index_template'):
999: return self.main_index_template()
1000:
1001: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_main_index_template_standard.zpt').__of__(self)
1002: pt.content_type="text/html"
1003: return pt()
1004:
1005: def ECHO_group_config(self):
1006: """Main configuration"""
1007:
1008: if not hasattr(self,'weight'):
1009: self.weight=""
1010:
1011: if not hasattr(self,'sortfield'):
1012: self.sortfield="weight"
1013:
1014: if not hasattr(self,'coords'):
1015: self.coords=[]
1016:
1017: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_group.zpt').__of__(self)
1018: return pt()
1019:
1020: def changeECHO_group(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag="",bgcolour="",logo=""):
1021: """Änderung der Properties"""
1022:
1023: self.secondaryLink=secondaryLink
1024: self.secondaryLinkTitle=secondaryLinkTitle
1025: self.imageTag=imageTag
1026: self.bgcolour=bgcolour
1027: self.logo=logo
1028:
1029: if coords:
1030: coordsnew=[ string.split(x,",") for x in coords]
1031: self.coords=coordsnew[0:]
1032: else:
1033: coordsnew=None
1034: self.coords=None
1035:
1036: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
1037:
1038:
1039:
1040: self.sortfield=sortfield
1041:
1042: if RESPONSE is not None:
1043: RESPONSE.redirect('manage_main')
1044:
1045: def getLogo(self):
1046: """logo ausgeben"""
1047: try:
1048: return self.logo
1049: except:
1050: return "ECHO_groups"
1051:
1052: def content_html(self):
1053: """template fuer content"""
1054: return content_html(self,'group')
1055:
1056:
1057:
1058: def manage_addECHO_groupForm(self):
1059: """Add group form"""
1060: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_groupForm.zpt').__of__(self)
1061: return pt()
1062:
1063:
1064: def manage_addECHO_group(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag="",bgcolour="",logo=""):
1065: """add a echo group"""
1066:
1067:
1068: newObj=ECHO_group(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag,bgcolour="")
1069:
1070: setattr(newObj,'logo',logo)
1071: self._setObject(id,newObj)
1072:
1073: if RESPONSE is not None:
1074: RESPONSE.redirect('manage_main')
1075:
1076:
1077:
1078: class ECHO_root(Folder,Persistent,Implicit):
1079: """ECHO Root Folder"""
1080: meta_type="ECHO_root"
1081:
1082:
1083: def getImageTag(self):
1084: """needed by main_template"""
1085: return ""
1086: secondaryLink="" #needed by main_template
1087: secondaryLinkTitle="" #needed by main_template
1088:
1089: def getBgcolour(self):
1090: """hack"""
1091: return "#dddddd"
1092:
1093: def contentTypeSelector_HTML(self,selected=None):
1094: """give type selector"""
1095: if not selected:
1096: retStr="<option selected>\n"
1097: else:
1098: retStr="<option>\n"
1099:
1100: try: # erste version contentTypes exists
1101: for contentType in self.ZopeFind(self.contentTypes,obj_metatypes=["ECHO_contentType"]):
1102: if selected and (contentType[0]==selected):
1103: retStr+="""<option selected value="%s">%s\n"""%(contentType[0],contentType[0])
1104: else:
1105: retStr+="""<option value="%s">%s\n"""%(contentType[0],contentType[0])
1106: except:
1107: try:
1108: for contentType in self.ZopeFind(self.standardMD,obj_metatypes=["OSAS_MetadataMapping"]):
1109: if selected and (contentType[0]==selected):
1110: retStr+="""<option selected value="%s">%s\n"""%(contentType[0],contentType[0])
1111: else:
1112: retStr+="""<option value="%s">%s\n"""%(contentType[0],contentType[0])
1113: except:
1114: """nothing"""
1115:
1116: return retStr
1117:
1118: def patchContentType(self,obj=None):
1119: """austauschen content_type with contentType (patch bei umstieg von alter Version)"""
1120:
1121:
1122: if not obj:
1123: obj = self
1124:
1125: entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection','ECHO_externalLink','ECHO_pageTemplate'])
1126:
1127: for entry in entries:
1128: setattr(entry[1],'contentType',entry[1].content_type)
1129: #entry[1].contentType == entry[1].content_type
1130:
1131: if entry[1].meta_type == 'ECHO_collection':
1132: entry[1].patchContentType(entry[1])
1133:
1134:
1135: return "changed all contenttypes in: "+self.title
1136:
1137:
1138: def patchViewClassification(self,obj=None):
1139: """setze viewClassification heuristisch"""
1140:
1141: def checkIfArrow(obj):
1142: if hasattr(obj,'coords'):
1143: for coordtemp in obj.coords:
1144: print obj.title,len(coordtemp)
1145: if (len(coordtemp)>4) and not (coordtemp[4]==''):
1146: return 4
1147: return None
1148: return None
1149:
1150: if not obj:
1151: obj = self
1152:
1153: entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection','ECHO_group'])
1154:
1155: for entry in entries:
1156:
1157: if checkIfArrow(entry[1]):
1158: print "VP"
1159: setattr(entry[1],'viewClassification','view point')
1160: else:
1161: print "area"
1162: setattr(entry[1],'viewClassification','area')
1163:
1164: #entry[1].contentType == entry[1].content_type
1165:
1166: if entry[1].meta_type in ['ECHO_collection','ECHO_group']:
1167: entry[1].patchViewClassification(entry[1])
1168:
1169:
1170: return "changed all contenttypes in: "+self.title
1171:
1172: def ECHO_newViewerLink(self,obj=None):
1173: """change links (:86 faellt weg)"""
1174:
1175: if not obj:
1176: obj = self
1177:
1178: entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
1179:
1180: for entry in entries:
1181:
1182: if entry[1].meta_type == 'ECHO_resource':
1183:
1184: entry[1].link=re.sub('\:86','',entry[1].link)
1185:
1186: else:
1187:
1188: entry[1].ECHO_newViewerLink(entry[1])
1189:
1190: return "Rerenderd all links to resources in: "+self.title
1191:
1192: def __init__(self,id,title):
1193: """init"""
1194: self.id = id
1195: self.title=title
1196:
1197: def deleteSpace(self,str):
1198: """delete space at the end of a line"""
1199: if str[len(str)-1]==" ":
1200: return str[0:len(str)-1]
1201: else:
1202: return str
1203:
1204:
1205:
1206: # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
1207:
1208: def formatAscii(self,str,url=None):
1209: """ersetze ascii umbrueche durch <br>"""
1210: #url=None
1211: if url:
1212:
1213: retStr=""
1214: words=str.split("\n")
1215:
1216: for word in words:
1217: strUrl=url%word
1218: print "str",strUrl
1219: retStr+="""<a href="%s">%s</a><br/>"""%(strUrl,word)
1220: str=retStr
1221: if str:
1222: return re.sub(r"[\n]","<br/>",str)
1223: else:
1224: return ""
1225:
1226: def link2html(self,str):
1227: """link2html fuer VLP muss hier noch raus"""
1228: if str:
1229: print str
1230: str=re.sub("\&","&",str)
1231: dom=xml.dom.minidom.parseString("<?xml version='1.0' ?><txt>"+str+"</txt>")
1232: links=dom.getElementsByTagName("link")
1233:
1234: print "link",links
1235: for link in links:
1236: link.tagName="a"
1237: ref=link.getAttribute("ref")
1238: if self.checkRef(ref):
1239: link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
1240:
1241: return dom.toxml('utf-8')
1242: return ""
1243:
1244:
1245: def checkRef(self,ref):
1246: dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
1247: res=None
1248: for db in dbs.keys():
1249: #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
1250:
1251: res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
1252: return res
1253:
1254: #Ende Methode fuer vlp
1255:
1256: def PgQuoteString(self,string):
1257: """Quote string"""
1258: #print "PG",string
1259: return libpq.PgQuoteString(string)
1260:
1261: def getPartners(self):
1262: """Get list of Partners. Presently only from a subfolder partners"""
1263:
1264: return [ item[1] for item in self.partners.ZopeFind(self.partners,obj_metatypes=['ECHO_partner'])]
1265:
1266:
1267:
1268:
1269:
1270: def getPartnersXML(self):
1271: """partner liste als xml"""
1272: partners=self.getPartners()
1273: ret="""<?xml version="1.0" encoding="utf-8" ?>
1274: <partners>"""
1275:
1276: for partner in partners:
1277: ret+="""<partner id="%s" title="%s"/>\n"""%(partner.getId(),unicode(partner.title,'utf-8','replace'))
1278:
1279: return ret+"\n</partners>"
1280:
1281: def getCollectionTree(self):
1282: """get the collection tree (list of triples (parent,child, depth)"""
1283:
1284: def getCollection(object,depth=0):
1285: depth+=1
1286: collections=[]
1287: for entry in object.__dict__.keys():
1288: element=getattr(object,entry)
1289: try:
1290: if element.meta_type=="ECHO_collection":
1291: collections.append((object,element,depth))
1292: collections+=getCollection(element,depth)
1293: except:
1294: """nothing"""
1295: return collections
1296:
1297:
1298: return getCollection(self)
1299:
1300: def getCollectionTreeIds(self):
1301: """Show the IDs of the Tree"""
1302: ret=[]
1303: for collection in self.getCollectionTree():
1304: ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
1305: return ret
1306:
1307:
1308:
1309: def manage_addECHO_root(self,id,title,RESPONSE=None):
1310: """Add an ECHO_root"""
1311: self._setObject(id,ECHO_root(id,title))
1312:
1313: if RESPONSE is not None:
1314: RESPONSE.redirect('manage_main')
1315:
1316: def manage_addECHO_rootForm(self):
1317: """Nothing yet"""
1318: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
1319: return pt()
1320:
1321: class ECHO_partner(Image,Persistent):
1322: """ECHO Partner"""
1323:
1324: meta_type="ECHO_partner"
1325:
1326: def __init__(self, id, title,url, file, content_type='', precondition=''):
1327: self.__name__=id
1328: self.title=title
1329: self.url=url
1330: self.precondition=precondition
1331:
1332: data, size = self._read_data(file)
1333: content_type=self._get_content_type(file, data, id, content_type)
1334: self.update_data(data, content_type, size)
1335:
1336: manage_options = Image.manage_options+(
1337: {'label':'Partner Information','action':'ECHO_partner_config'},
1338: )
1339:
1340: def changeECHO_partner(self,url,RESPONSE=None):
1341: """Change main information"""
1342: self.url=url
1343: if RESPONSE is not None:
1344: RESPONSE.redirect('manage_main')
1345:
1346:
1347:
1348: def ECHO_partner_config(self):
1349: """Main configuration"""
1350: if not hasattr(self,'url'):
1351: self.url=""
1352: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
1353: return pt()
1354:
1355:
1356: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
1357: Kind='ECHO_partner',kind='ECHO_partner')
1358:
1359:
1360:
1361: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
1362: REQUEST=None):
1363: """
1364: Add a new ECHO_partner object.
1365:
1366: Creates a new ECHO_partner object 'id' with the contents of 'file'.
1367: Based on Image.manage_addImage
1368: """
1369:
1370: id=str(id)
1371: title=str(title)
1372: content_type=str(content_type)
1373: precondition=str(precondition)
1374:
1375: id, title = OFS.Image.cookId(id, title, file)
1376:
1377: self=self.this()
1378:
1379: # First, we create the image without data:
1380: self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
1381:
1382: # Now we "upload" the data. By doing this in two steps, we
1383: # can use a database trick to make the upload more efficient.
1384: if file:
1385: self._getOb(id).manage_upload(file)
1386: if content_type:
1387: self._getOb(id).content_type=content_type
1388:
1389: if REQUEST is not None:
1390: try: url=self.DestinationURL()
1391: except: url=REQUEST['URL1']
1392: REQUEST.RESPONSE.redirect('%s/manage_main' % url)
1393: return id
1394:
1395:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>