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:
30: #from psycopg import libpq
31: #from pyPgSQL import libpq
32: import xml.dom.minidom
33:
34: import urllib
35: import xml.dom.minidom
36: from ECHO_graphicalOverview import javaHandler,javaScriptMain
37:
38: #List of different types for the graphical linking viewer
39: viewClassificationListMaster=['view point','area']
40:
41: def content_html(self,type):
42: """template fuer content"""
43: #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"])
44: #
45: #if templates:
46: # return templates[0][1]()
47:
48: try:
49: obj=getattr(self,type+"_template")
50: return obj()
51: except:
52: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_%s_template_standard.zpt'%type).__of__(self)
53: pt.content_type="text/html"
54: return pt()
55:
56: def toList(field):
57: """Einzelfeld in Liste umwandeln"""
58: if type(field)==StringType:
59: return [field]
60: else:
61: return field
62:
63: def getText(nodelist):
64:
65: rc = ""
66: for node in nodelist:
67: if node.nodeType == node.TEXT_NODE:
68: rc = rc + node.data
69: return rc
70:
71:
72: def readMetadata(url):
73: """Methoden zum Auslesen der Metadateninformation zu einer Resource
74: Vorerst noch Typ bib"""
75:
76: metadict={}
77: try:
78: geturl=""
79: for line in urllib.urlopen(url).readlines():
80: geturl=geturl+line
81:
82:
83: except:
84: return (None,"Cannot open: "+url)
85:
86: try:
87: dom=xml.dom.minidom.parseString(geturl)
88: except:
89: return (None,"Cannot parse: "+url+"<br>"+geturl)
90:
91: metanode=dom.getElementsByTagName('bib')
92: metadict['bib_type']='Book'
93: if len(metanode)==0:
94: metanode=dom.getElementsByTagName('archimedes')
95: metadict['bib_type']='Archimedes'
96: #print "HELLO"
97:
98: if not len(metanode)==0:
99: metacontent=metanode[0].childNodes
100:
101: try:
102: metadict['bib_type']=getText(dom.getElementsByTagName('bib')[0].attributes['type'].childNodes)
103: except:
104: """nothing"""
105:
106: for node in metacontent:
107: try:
108: metadict[node.tagName.lower()]=getText(node.childNodes)
109: except:
110: """nothing"""
111:
112: #print metadict
113: return metadict,""
114:
115:
116: def setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordstrs,viewClassification=""):
117:
118: """Allegemeine Informationen zu einer ECHO Collection"""
119:
120: self.viewClassification=viewClassification
121:
122: self.label = label
123: self.title=title
124: self.description=description
125: self.contentType=contentType
126: self.responsible=responsible
127: self.credits=toList(credits)
128: self.weight=weight
129:
130: coords=[]
131: #coordinates of for rectangles
132:
133: #print "cs", coordstrs
134: if coordstrs:
135: for coordstr in coordstrs:
136: #print "cs", coordstr
137: try:
138: temco=coordstr.split(",")
139: except:
140: temco=[]
141: #temco.append(angle)
142: coords.append(temco)
143:
144:
145: self.coords=coords[0:]
146:
147:
148: class scientificClassification(SimpleItem,Persistent,Implicit):
149: """outdated will be deleeted in the next versions: subclass"""
150: security=ClassSecurityInfo()
151:
152: def __init__(self,context,science,practice):
153: self.context=context
154: self.science=science
155: self.practice=practice
156: self.id="scientific_Classification"
157:
158: security.declarePublic('get_context')
159: def get_context(self):
160: return self.context
161:
162: security.declarePublic('get_science')
163: def get_science(self):
164: return self.science
165:
166: security.declarePublic('get_practice')
167: def get_practice(self):
168: return self.practice
169:
170:
171: class scientificInformation(Folder,Persistent,Implicit):
172: """outdated will be deleted in the next versions: subclass scientificInformation"""
173: security=ClassSecurityInfo()
174:
175:
176:
177: def __init__(self,source_type,period):
178:
179: self.id="scientific_Information"
180: self.source_type=source_type
181: self.period=period
182:
183:
184:
185: security.declarePublic('get_source_type')
186: def get_source_type(self):
187: return self.source_type
188:
189: security.declarePublic('get_period')
190: def get_period(self):
191: return self.period
192:
193: class ECHO_layoutTemplate(ZopePageTemplate):
194: """Create a layout Template for different purposes"""
195:
196: meta_type="ECHO_layoutTemplate"
197:
198: #manage_options=ZopePageTemplate.manage_options+(
199: # {'label':'Set back to Standard','action':'changeECHO_layoutTemplateToStandardForm'},
200: # )
201:
202:
203: def __init__(self, id, text=None, content_type=None,EchoType=None):
204: self.id = str(id)
205:
206:
207:
208: self.ZBindings_edit(self._default_bindings)
209: if text is None:
210: self._default_content_fn = os.path.join(package_home(globals()),
211: 'zpt/ECHO_%s_template_standard.zpt'%EchoType)
212: text = open(self._default_content_fn).read()
213: self.pt_edit(text, content_type)
214:
215: ## def changeECHO_layoutTemplateToStandardForm(self):
216: ## """change form"""
217: ## pt=PageTemplateFile('Products/ECHO_content/zpt/changeECHO_pageTemplateWeightForm.zpt').__of__(self)
218: ## return pt()
219:
220:
221: """change form"""
222:
223:
224: def manage_addECHO_layoutTemplateForm(self):
225: """Form for adding"""
226: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_layoutTemplate.zpt').__of__(self)
227: return pt()
228:
229: from urllib import quote
230:
231:
232: def manage_addECHO_layoutTemplate(self, EchoType,title=None,REQUEST=None):
233: "Add a Page Template with optional file content."
234: if type(EchoType)==StringType:
235: EchoTypes=[EchoType]
236: else:
237: EchoTypes=EchoType
238:
239: for singleType in EchoTypes:
240:
241: id = str(singleType)+"_template"
242: if REQUEST is None:
243: self._setObject(id, ECHO_layoutTemplate(id, text,EchoType=singleType))
244: ob = getattr(self, id)
245:
246: if title:
247: ob.pt_setTitle(title)
248: return ob
249: else:
250: file = REQUEST.form.get('file')
251: headers = getattr(file, 'headers', None)
252: if headers is None or not file.filename:
253: zpt = ECHO_layoutTemplate(id,EchoType=singleType)
254: else:
255: zpt = ECHO_layoutTemplate(id, file, headers.get('content_type'))
256:
257: self._setObject(id, zpt)
258: ob = getattr(self, id)
259: if title:
260: ob.pt_setTitle(title)
261:
262: try:
263: u = self.DestinationURL()
264: except AttributeError:
265: u = REQUEST['URL1']
266:
267:
268: REQUEST.RESPONSE.redirect(u+'/manage_main')
269: return ''
270:
271: class ECHO_resource(Folder):
272: """ECHO Ressource"""
273: meta_type='ECHO_resource'
274:
275: viewClassificationList=viewClassificationListMaster
276:
277: def content_html(self):
278: """template fuer content"""
279: return content_html(self,'resource')
280:
281: def getViewClassification(self):
282: if hasattr(self,'viewClassification'):
283: return self.viewClassification
284: else:
285: return ""
286:
287: def getCredits(self):
288: """Ausgabe der credits"""
289: if self.credits:
290: return self.credits
291: else:
292: return []
293:
294: def __init__(self,id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords):
295:
296: self.id = id
297: """Festlegen der ID"""
298:
299: self.label = label
300: self.link= link
301: self.metalink=metalink
302: self.title=title
303: self.weight=weight
304: self.credits=toList(credits)
305: self.description=description
306: self.contentType=contentType
307: self.responsible=responsible
308:
309: if coords:
310: coordsnew=[ string.split(x,",") for x in coords]
311: else:
312: coordsnew=[]
313:
314: self.coords=coordsnew
315:
316:
317: def getCoords(self):
318: try:
319: return [string.join(x,",") for x in self.coords]
320: except:
321: return []
322:
323:
324: def ECHO_resource_config(self):
325: """Main configuration"""
326:
327: if not hasattr(self,'weight'):
328: self.weight=""
329: if not hasattr(self,'coords'):
330: self.coords=[]
331:
332: print "vorher",self.coords
333: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource.zpt').__of__(self)
334: return pt()
335:
336:
337: def changeECHO_resource(self,metalink,link,title,label,description,contentType,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None):
338: """Änderung der Properties"""
339:
340: try:
341: coordsnew=[ string.split(x,",") for x in coords]
342: except:
343: coordsnew=[]
344:
345: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
346:
347: self.coords=coordsnew[0:]
348: self.link=link
349: self.metalink=metalink
350:
351: if RESPONSE is not None:
352: RESPONSE.redirect('manage_main')
353:
354:
355: manage_options = Folder.manage_options+(
356: {'label':'Main Config','action':'ECHO_resource_config'},
357: {'label':'Metadata','action':'ECHO_getResourceMD'},
358: {'label':'Graphics','action':'ECHO_graphicEntry'},
359: )
360:
361: def getOverview(self):
362: """overview graphics"""
363:
364: return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
365:
366: def ECHO_graphicEntry(self):
367: """DO nothing"""
368: overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
369: if overview:
370: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
371: return pt()
372: else:
373: return "NO OVERVIEW GRAPHICS"
374:
375: def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
376: """Enter coords"""
377: coords=self.coords
378: temco=coordstr.split(",")
379: temco.append(angle)
380: coords.append(temco)
381:
382: self.coords=coords[0:]
383:
384: if RESPONSE is not None:
385: RESPONSE.redirect('ECHO_graphicEntry')
386:
387: def ECHO_getResourceMD(self,template="yes"):
388: """Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource"""
389: (metadict, error)=readMetadata(self.metalink)
390:
391:
392:
393: if not error=="": #Fehler beim Auslesen des Metafiles
394: return "ERROR:",error
395: for key in metadict.keys():#Hinzufügen der Felder
396:
397: setattr(self,key,metadict[key].encode('ascii','replace'))
398:
399:
400: self.metadata=metadict.keys()
401:
402: self.label=self.generate_label()
403:
404: if template=="yes":
405: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_resourceMD.zpt').__of__(self)
406: return pt()
407:
408: def ECHO_getMD(self,item):
409: """Ausgabe der MD"""
410: return getattr(self,item)
411:
412: def index_html(self):
413: """standard page"""
414:
415: return self.REQUEST.RESPONSE.redirect(self.link)
416:
417: def generate_label(self):
418: """Erzeugt_standard_Label aus Template"""
419: pt=getattr(self,"label_template_"+self.bib_type)
420:
421: return pt()
422:
423: def manage_addECHO_resourceForm(self):
424: """Form for adding a ressource"""
425: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_resourceForm.zpt').__of__(self)
426: return pt()
427:
428:
429:
430: def manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
431: """addaresource"""
432:
433: newObj=ECHO_resource(id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords)
434:
435: self._setObject(id,newObj)
436:
437: if RESPONSE is not None:
438: RESPONSE.redirect('manage_main')
439:
440:
441: class ECHO_externalLink(Folder):
442: """Link zu einer externen Ressource"""
443: security=ClassSecurityInfo()
444: meta_type='ECHO_externalLink'
445:
446: def content_html(self):
447: """template fuer content"""
448: return content_html(self,'externalLink')
449:
450: def __init__(self,id,link,title,label,description,contentType,responsible,credits,weight,coords):
451:
452: self.id = id
453: """Festlegen der ID"""
454:
455: self.credits=toList(credits)
456: self.label = label
457: self.link= link
458: self.title=title
459: self.weight=weight
460: self.description=description
461: self.contentType=contentType
462: self.responsible=responsible
463: coordsnew=[ string.split(x,",") for x in coords]
464: self.coords=coordsnew
465:
466: def ECHO_externalLink_config(self):
467: """Main configuration"""
468:
469: if not hasattr(self,'weight'):
470: self.weight=""
471: if not hasattr(self,'coords'):
472:
473: self.coords=['']
474: #print "G",self.coords
475:
476: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_externalLink.zpt').__of__(self)
477: return pt()
478:
479:
480: def changeECHO_externalLink(self,link,title,label,description,contentType,responsible,weight,coords=None,credits=None,RESPONSE=None):
481:
482: """Änderung der Properties"""
483: coordsnew=[ string.split(x,",") for x in coords]
484:
485: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coords)
486:
487: self.coords=coordsnew[0:]
488: self.link=link
489: if RESPONSE is not None:
490: RESPONSE.redirect('manage_main')
491:
492:
493: manage_options = Folder.manage_options+(
494: {'label':'Main Config','action':'ECHO_externalLink_config'},
495: )
496:
497: def getCredits(self):
498: """Ausgabe der credits"""
499: if self.credits:
500: return self.credits
501: else:
502: return []
503:
504: def index_html(self):
505: """standard page"""
506:
507: return self.REQUEST.RESPONSE.redirect(self.link)
508:
509: def manage_addECHO_externalLinkForm(self):
510: """Form for external Links"""
511: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
512: return pt()
513:
514:
515: def manage_addECHO_externalLink(self,id,title,label,description,contentType,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
516: """Add an external Link"""
517:
518: newObj=ECHO_externalLink(id,link,title,label,description,contentType,responsible,credits,weight,coords)
519:
520: self._setObject(id,newObj)
521:
522: if RESPONSE is not None:
523: RESPONSE.redirect('manage_main')
524:
525:
526:
527: class ECHO_collection(Folder, Persistent, Implicit):
528: """ECHO Collection"""
529: security=ClassSecurityInfo()
530: meta_type='ECHO_collection'
531:
532: def getImageTag(self):
533: """GetTag"""
534: try:
535: return self.imageTag
536: except:
537: return ""
538:
539: def addResource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
540: """SSS"""
541: try:
542: manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None)
543: return "done"
544: except:
545: return None
546:
547: def getSecondaryLink(self):
548: """secondary link"""
549: try:
550: return self.secondaryLink
551: except:
552: return ""
553:
554: def getSecondaryLinkTitle(self):
555: """secondary link"""
556: try:
557: return self.secondaryLinkTitle
558: except:
559: return ""
560:
561: def getCollectionTreeXML(self):
562: """Tree as XML"""
563:
564: def getCollection(object,depth=0):
565: depth+=1
566: collections=""
567: for entry in object.__dict__.keys():
568: element=getattr(object,entry)
569: try:
570: if element.meta_type=="ECHO_collection":
571: collections+="<element name=\""+element.title+"\" url=\""+element.absolute_url()+"\">"
572: collections+=getCollection(element,depth)+"</element>\n"
573: except:
574: """nothing"""
575: return collections
576:
577:
578: return "<collection>"+getCollection(self)+"</collection>"
579:
580: def createJavaScript(self):
581: """CreateJava"""
582: ret=javaScriptMain
583:
584: dynamical=""
585: for ob in self.getGraphicCoords():
586: dynamical+="""Coords.push(new Coord('%s', Img, %s));\n"""%(ob[1],ob[0])
587: ret+=javaHandler%dynamical
588: return ret
589:
590: security.declarePublic('getCreditObject')
591: def getCreditObject(self,name):
592: """credit id to credititem"""
593: try:
594: return getattr(self.partners,name)
595: except:
596: return ""
597:
598: security.declarePublic('ECHO_generateNavBar')
599: def ECHO_generateNavBar(self):
600: """Erzeuge Navigationsbar"""
601: link=""
602: object="self"
603: ret=[]
604: path=self.getPhysicalPath()
605: for element in path:
606:
607:
608: if not element=="":
609: object+="."+element
610:
611: label=eval(object).label
612: link+="/"+element
613: if not label=="":
614: ret.append((label,link))
615: return ret
616:
617: security.declarePublic('ECHO_rerenderLinksMD')
618: def ECHO_rerenderLinksMD(self):
619: """Rerender all Links"""
620:
621: for entry in self.__dict__.keys():
622: object=getattr(self,entry)
623:
624:
625: try:
626:
627: if object.meta_type == 'ECHO_resource':
628:
629: object.ECHO_getResourceMD(template="no")
630:
631: except:
632: """nothing"""
633:
634: return "Rerenderd all links to resources in: "+self.title
635:
636: security.declarePublic('ECHO_newViewerLink')
637:
638:
639: def getCoords(self):
640: try:
641:
642: x= [string.join(x,",") for x in self.coords]
643: return x
644:
645: except:
646:
647: return []
648:
649: def __init__(self,id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle,secondaryLink,imageTag=""):
650: #print "CO",coords
651:
652: self.id = id
653: """Festlegen der ID"""
654: self.credits=toList(credits)
655: self.label = label
656: self.title=title
657: self.description=description
658: self.contentType=contentType
659: self.responsible=responsible
660: self.imageTag=imageTag
661: self.weight=weight
662: self.sortfield=sortfield
663: coordsnew=[ string.split(x,",") for x in coords]
664: self.coords=coordsnew
665: self.secondaryLinkTitle=secondaryLinkTitle
666: self.secondaryLink=secondaryLink
667:
668:
669: manage_options = Folder.manage_options+(
670: {'label':'Main Config','action':'ECHO_collection_config'},
671: {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
672: {'label':'Graphics','action':'ECHO_graphicEntry'},
673:
674: )
675:
676: def getOverview(self):
677: """overview graphics"""
678:
679: return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
680:
681:
682: def ECHO_graphicEntry(self):
683: """DO nothing"""
684: overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
685:
686:
687: if overview:
688: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
689: return pt()
690: else:
691: return "NO OVERVIEW GRAPHICS"
692:
693: def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
694: """Enter coords"""
695: coords=self.coords
696: temco=coordstr.split(",")
697: temco.append(angle)
698: coords.append(temco)
699: self.coords=coords[0:]
700:
701: if RESPONSE is not None:
702: RESPONSE.redirect('ECHO_graphicEntry')
703:
704:
705: security.declarePublic('ECHO_collection_config')
706: def ECHO_collection_config(self):
707: """Main configuration"""
708:
709: if not hasattr(self,'weight'):
710: self.weight=""
711:
712: if not hasattr(self,'sortfield'):
713: self.sortfield="weight"
714:
715: if not hasattr(self,'coords'):
716: self.coords=[]
717:
718: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
719: return pt()
720:
721:
722: security.declarePublic('changeECHO_collection')
723:
724:
725: def changeECHO_collection(self,title,label,description,contentType,responsible,weight,secondaryLink,secondaryLinkTitle,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag=""):
726: """Änderung der Properties"""
727:
728: self.secondaryLink=secondaryLink
729: self.secondaryLinkTitle=secondaryLinkTitle
730: self.imageTag=imageTag
731: if coords:
732: coordsnew=[ string.split(x,",") for x in coords]
733: self.coords=coordsnew[0:]
734: else:
735: coordsnew=None
736: self.coords=None
737:
738: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
739:
740:
741:
742: self.sortfield=sortfield
743:
744: if RESPONSE is not None:
745: RESPONSE.redirect('manage_main')
746:
747: security.declarePublic('index_html')
748:
749:
750: def showOverview(self):
751: """overview"""
752: if 'ECHO_overview.html' in self.__dict__.keys():
753: return getattr(self,'ECHO_overview.html')()
754: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_overview.zpt').__of__(self)
755: return pt()
756:
757:
758: def index_html(self):
759: """standard page"""
760:
761: if 'index.html' in self.__dict__.keys():
762: return getattr(self,'index.html')()
763:
764: elif 'overview' in self.__dict__.keys():
765: return self.showOverview()
766: elif hasattr(self,'collection_index_template'):
767: return self.collection_index_template()
768:
769: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self)
770: pt.content_type="text/html"
771: return pt()
772:
773: def content_html(self):
774: """template fuer content"""
775: return content_html(self,'collection')
776:
777: def getCredits(self):
778: """Ausgabe der credits"""
779: if self.credits:
780: return self.credits
781: else:
782: return []
783:
784:
785:
786: def getGraphicCoords(self):
787: """Give list of coordinates"""
788: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
789: ids=[]
790: for entry in self.__dict__.keys():
791: object=getattr(self,entry)
792: try:
793: if object.meta_type in subColTypes:
794: for coordtemp in object.coords:
795: if len(coordtemp)>3:
796: coord=coordtemp[0:4]
797: if hasattr(object,'label') and not object.label=="":
798: ids.append([string.join(coord,", "),object.getId(),object.label,object])
799: elif hasattr(object,'title'):
800: if not object.title=="":
801: ids.append([string.join(coord,", "),object.getId(),object.title,object])
802: else:
803: ids.append([string.join(coord,", "),object.getId(),object.getId(),object])
804: else:
805: ids.append([string.join(coord,", "),object.getId(),object.getId(),object])
806:
807: except:
808: """nothing"""
809:
810: return ids
811:
812: def getSubCols(self,sortfield="weight"):
813:
814: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
815: ids=[]
816: for entry in self.__dict__.keys():
817: object=getattr(self,entry)
818: try:
819: if object.meta_type in subColTypes:
820: ids.append(object)
821:
822: except:
823: """nothing"""
824: try:
825: sortfield=self.sortfield
826: except:
827: """nothing"""
828:
829: tmplist=[]
830: for x in ids:
831: if hasattr(x,sortfield):
832: try:
833: x=int(x)
834: except:
835: """nothing"""
836: tmp=getattr(x,sortfield)
837: else:
838: tmp=10000000
839: tmplist.append((tmp,x))
840: tmplist.sort()
841: return [x for (key,x) in tmplist]
842:
843:
844:
845:
846:
847:
848: def manage_addECHO_collectionForm(self):
849: """Add collection form"""
850: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
851: return pt()
852:
853:
854: def manage_addECHO_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",secondaryLinkTitle="",secondaryLink="",credits=None,RESPONSE=None,imageTag=""):
855: """add a echo collection"""
856:
857:
858: newObj=ECHO_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,secondaryLinkTitle=secondaryLinkTitle,secondaryLink=secondaryLink,imageTag=imageTag)
859:
860: self._setObject(id,newObj)
861:
862: if RESPONSE is not None:
863: RESPONSE.redirect('manage_main')
864:
865: class ECHO_root(Folder,Persistent,Implicit):
866: """ECHO Root Folder"""
867: meta_type="ECHO_root"
868:
869:
870: def contentTypeSelector_HTML(self,selected=None):
871: """give type selector"""
872: if not selected:
873: retStr="<option selected>\n"
874: else:
875: retStr="<option>\n"
876:
877: try:
878: for contentType in self.ZopeFind(self.contentTypes,obj_metatypes="ECHO_contentType"):
879: if selected and (contentType[0]==selected):
880: retStr+="""<option selected value="%s">%s\n"""%(contentType[0],contentType[0])
881: else:
882: retStr+="""<option value="%s">%s\n"""%(contentType[0],contentType[0])
883: except:
884: """nothing"""
885: return retStr
886:
887: def patchContentType(self,obj=None):
888: """austauschen content_type with contentType (patch bei umstieg von alter Version)"""
889:
890:
891: if not obj:
892: obj = self
893:
894: entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection','ECHO_externalLink','ECHO_pageTemplate'])
895:
896: for entry in entries:
897: setattr(entry[1],'contentType',entry[1].content_type)
898: #entry[1].contentType == entry[1].content_type
899:
900: if entry[1].meta_type == 'ECHO_collection':
901: entry[1].patchContentType(entry[1])
902:
903:
904: return "Rerenderd all links to resources in: "+self.title
905:
906: def ECHO_newViewerLink(self,obj=None):
907: """change links (:86 faellt weg)"""
908:
909: if not obj:
910: obj = self
911:
912: entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
913:
914: for entry in entries:
915:
916: if entry[1].meta_type == 'ECHO_resource':
917:
918: entry[1].link=re.sub('\:86','',entry[1].link)
919:
920: else:
921:
922: entry[1].ECHO_newViewerLink(entry[1])
923:
924: return "Rerenderd all links to resources in: "+self.title
925:
926: def __init__(self,id,title):
927: """init"""
928: self.id = id
929: self.title=title
930:
931: def deleteSpace(self,str):
932: """delete space at the end of a line"""
933: if str[len(str)-1]==" ":
934: return str[0:len(str)-1]
935: else:
936: return str
937:
938:
939:
940: # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
941:
942: def formatAscii(self,str,url=None):
943: """ersetze ascii umbrueche durch <br>"""
944: #url=None
945: if url:
946:
947: retStr=""
948: words=str.split("\n")
949:
950: for word in words:
951: strUrl=url%word
952: print "str",strUrl
953: retStr+="""<a href="%s">%s</a><br/>"""%(strUrl,word)
954: str=retStr
955: if str:
956: return re.sub(r"[\n]","<br/>",str)
957: else:
958: return ""
959:
960: def link2html(self,str):
961: """link2html fuer VLP muss hier noch raus"""
962: if str:
963: print str
964: str=re.sub("\&","&",str)
965: dom=xml.dom.minidom.parseString("<?xml version='1.0' ?><txt>"+str+"</txt>")
966: links=dom.getElementsByTagName("link")
967:
968: print "link",links
969: for link in links:
970: link.tagName="a"
971: ref=link.getAttribute("ref")
972: if self.checkRef(ref):
973: link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
974:
975: return dom.toxml('utf-8')
976: return ""
977:
978:
979: def checkRef(self,ref):
980: dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
981: res=None
982: for db in dbs.keys():
983: #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
984:
985: res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
986: return res
987:
988: #Ende Methode fuer vlp
989:
990: def PgQuoteString(self,string):
991: """Quote string"""
992: #print "PG",string
993: return libpq.PgQuoteString(string)
994:
995: def getPartners(self):
996: """Get list of Partners. Presently only from a subfolder partners"""
997:
998: return [ item[1] for item in self.partners.ZopeFind(self.partners,obj_metatypes=['ECHO_partner'])]
999:
1000:
1001:
1002:
1003:
1004: def getPartnersXML(self):
1005: """partner liste als xml"""
1006: partners=self.getPartners()
1007: ret="<partners>"
1008: for partner in partners:
1009: ret+="""<partner id="%s" title="%s"/>\n"""%(partner.getId(),partner.title)
1010:
1011: return ret+"\n</partners>"
1012:
1013: def getCollectionTree(self):
1014: """get the collection tree (list of triples (parent,child, depth)"""
1015:
1016: def getCollection(object,depth=0):
1017: depth+=1
1018: collections=[]
1019: for entry in object.__dict__.keys():
1020: element=getattr(object,entry)
1021: try:
1022: if element.meta_type=="ECHO_collection":
1023: collections.append((object,element,depth))
1024: collections+=getCollection(element,depth)
1025: except:
1026: """nothing"""
1027: return collections
1028:
1029:
1030: return getCollection(self)
1031:
1032: def getCollectionTreeIds(self):
1033: """Show the IDs of the Tree"""
1034: ret=[]
1035: for collection in self.getCollectionTree():
1036: ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
1037: return ret
1038:
1039:
1040:
1041: def manage_addECHO_root(self,id,title,RESPONSE=None):
1042: """Add an ECHO_root"""
1043: self._setObject(id,ECHO_root(id,title))
1044:
1045: if RESPONSE is not None:
1046: RESPONSE.redirect('manage_main')
1047:
1048: def manage_addECHO_rootForm(self):
1049: """Nothing yet"""
1050: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
1051: return pt()
1052:
1053: class ECHO_partner(Image,Persistent):
1054: """ECHO Partner"""
1055:
1056: meta_type="ECHO_partner"
1057:
1058: def __init__(self, id, title,url, file, content_type='', precondition=''):
1059: self.__name__=id
1060: self.title=title
1061: self.url=url
1062: self.precondition=precondition
1063:
1064: data, size = self._read_data(file)
1065: content_type=self._get_content_type(file, data, id, content_type)
1066: self.update_data(data, content_type, size)
1067:
1068: manage_options = Image.manage_options+(
1069: {'label':'Partner Information','action':'ECHO_partner_config'},
1070: )
1071:
1072: def changeECHO_partner(self,url,RESPONSE=None):
1073: """Change main information"""
1074: self.url=url
1075: if RESPONSE is not None:
1076: RESPONSE.redirect('manage_main')
1077:
1078:
1079:
1080: def ECHO_partner_config(self):
1081: """Main configuration"""
1082: if not hasattr(self,'url'):
1083: self.url=""
1084: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
1085: return pt()
1086:
1087:
1088: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
1089: Kind='ECHO_partner',kind='ECHO_partner')
1090:
1091:
1092:
1093: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
1094: REQUEST=None):
1095: """
1096: Add a new ECHO_partner object.
1097:
1098: Creates a new ECHO_partner object 'id' with the contents of 'file'.
1099: Based on Image.manage_addImage
1100: """
1101:
1102: id=str(id)
1103: title=str(title)
1104: content_type=str(content_type)
1105: precondition=str(precondition)
1106:
1107: id, title = OFS.Image.cookId(id, title, file)
1108:
1109: self=self.this()
1110:
1111: # First, we create the image without data:
1112: self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
1113:
1114: # Now we "upload" the data. By doing this in two steps, we
1115: # can use a database trick to make the upload more efficient.
1116: if file:
1117: self._getOb(id).manage_upload(file)
1118: if content_type:
1119: self._getOb(id).content_type=content_type
1120:
1121: if REQUEST is not None:
1122: try: url=self.DestinationURL()
1123: except: url=REQUEST['URL1']
1124: REQUEST.RESPONSE.redirect('%s/manage_main' % url)
1125: return id
1126:
1127:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>