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: def changeECHO_pageTemplateWeight(self,templateKind):
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: id = str(singleType)+"_template"
241: if REQUEST is None:
242: self._setObject(id, ECHO_layoutTemplate(id, text,EchoType=singleType))
243: ob = getattr(self, id)
244:
245: if title:
246: ob.pt_setTitle(title)
247: return ob
248: else:
249: file = REQUEST.form.get('file')
250: headers = getattr(file, 'headers', None)
251: if headers is None or not file.filename:
252: zpt = ECHO_layoutTemplate(id,EchoType=singleType)
253: else:
254: zpt = ECHO_layoutTemplate(id, file, headers.get('content_type'))
255:
256: self._setObject(id, zpt)
257: ob = getattr(self, id)
258: if title:
259: ob.pt_setTitle(title)
260:
261: try:
262: u = self.DestinationURL()
263: except AttributeError:
264: u = REQUEST['URL1']
265:
266:
267: REQUEST.RESPONSE.redirect(u+'/manage_main')
268: return ''
269:
270: class ECHO_resource(Folder):
271: """ECHO Ressource"""
272: meta_type='ECHO_resource'
273:
274: viewClassificationList=viewClassificationListMaster
275:
276: def content_html(self):
277: """template fuer content"""
278: return content_html(self,'resource')
279:
280: def getViewClassification(self):
281: if hasattr(self,'viewClassification'):
282: return self.viewClassification
283: else:
284: return ""
285:
286: def getCredits(self):
287: """Ausgabe der credits"""
288: if self.credits:
289: return self.credits
290: else:
291: return []
292:
293: def __init__(self,id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords):
294:
295: self.id = id
296: """Festlegen der ID"""
297:
298: self.label = label
299: self.link= link
300: self.metalink=metalink
301: self.title=title
302: self.weight=weight
303: self.credits=toList(credits)
304: self.description=description
305: self.contentType=contentType
306: self.responsible=responsible
307:
308: if coords:
309: coordsnew=[ string.split(x,",") for x in coords]
310: else:
311: coordsnew=[]
312:
313: self.coords=coordsnew
314:
315:
316: def getCoords(self):
317: try:
318: return [string.join(x,",") for x in self.coords]
319: except:
320: return []
321:
322:
323: def ECHO_resource_config(self):
324: """Main configuration"""
325:
326: if not hasattr(self,'weight'):
327: self.weight=""
328: if not hasattr(self,'coords'):
329: self.coords=[]
330:
331: print "vorher",self.coords
332: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource.zpt').__of__(self)
333: return pt()
334:
335:
336: def changeECHO_resource(self,metalink,link,title,label,description,contentType,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None):
337: """Änderung der Properties"""
338:
339:
340: coordsnew=[ string.split(x,",") for x in coords]
341:
342:
343: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
344:
345: self.coords=coordsnew[0:]
346: self.link=link
347: self.metalink=metalink
348:
349: if RESPONSE is not None:
350: RESPONSE.redirect('manage_main')
351:
352:
353: manage_options = Folder.manage_options+(
354: {'label':'Main Config','action':'ECHO_resource_config'},
355: {'label':'Metadata','action':'ECHO_getResourceMD'},
356: {'label':'Graphics','action':'ECHO_graphicEntry'},
357: )
358:
359: def getOverview(self):
360: """overview graphics"""
361:
362: return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
363:
364: def ECHO_graphicEntry(self):
365: """DO nothing"""
366: overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
367: if overview:
368: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
369: return pt()
370: else:
371: return "NO OVERVIEW GRAPHICS"
372:
373: def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
374: """Enter coords"""
375: coords=self.coords
376: temco=coordstr.split(",")
377: temco.append(angle)
378: coords.append(temco)
379:
380: self.coords=coords[0:]
381:
382: if RESPONSE is not None:
383: RESPONSE.redirect('ECHO_graphicEntry')
384:
385: def ECHO_getResourceMD(self,template="yes"):
386: """Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource"""
387: (metadict, error)=readMetadata(self.metalink)
388:
389:
390:
391: if not error=="": #Fehler beim Auslesen des Metafiles
392: return "ERROR:",error
393: for key in metadict.keys():#Hinzufügen der Felder
394:
395: setattr(self,key,metadict[key].encode('ascii','replace'))
396:
397:
398: self.metadata=metadict.keys()
399:
400: self.label=self.generate_label()
401:
402: if template=="yes":
403: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_resourceMD.zpt').__of__(self)
404: return pt()
405:
406: def ECHO_getMD(self,item):
407: """Ausgabe der MD"""
408: return getattr(self,item)
409:
410: def index_html(self):
411: """standard page"""
412:
413: return self.REQUEST.RESPONSE.redirect(self.link)
414:
415: def generate_label(self):
416: """Erzeugt_standard_Label aus Template"""
417: pt=getattr(self,"label_template_"+self.bib_type)
418:
419: return pt()
420:
421: def manage_addECHO_resourceForm(self):
422: """Form for adding a ressource"""
423: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_resourceForm.zpt').__of__(self)
424: return pt()
425:
426:
427:
428: def manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
429: """addaresource"""
430:
431: newObj=ECHO_resource(id,link,metalink,title,label,description,contentType,responsible,credits,weight,coords)
432:
433: self._setObject(id,newObj)
434:
435: if RESPONSE is not None:
436: RESPONSE.redirect('manage_main')
437:
438:
439: class ECHO_externalLink(Folder):
440: """Link zu einer externen Ressource"""
441: security=ClassSecurityInfo()
442: meta_type='ECHO_externalLink'
443:
444: def content_html(self):
445: """template fuer content"""
446: return content_html(self,'externalLink')
447:
448: def __init__(self,id,link,title,label,description,contentType,responsible,credits,weight,coords):
449:
450: self.id = id
451: """Festlegen der ID"""
452:
453: self.credits=toList(credits)
454: self.label = label
455: self.link= link
456: self.title=title
457: self.weight=weight
458: self.description=description
459: self.contentType=contentType
460: self.responsible=responsible
461: coordsnew=[ string.split(x,",") for x in coords]
462: self.coords=coordsnew
463:
464: def ECHO_externalLink_config(self):
465: """Main configuration"""
466:
467: if not hasattr(self,'weight'):
468: self.weight=""
469: if not hasattr(self,'coords'):
470:
471: self.coords=['']
472: #print "G",self.coords
473:
474: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_externalLink.zpt').__of__(self)
475: return pt()
476:
477:
478: def changeECHO_externalLink(self,link,title,label,description,contentType,responsible,weight,coords=None,credits=None,RESPONSE=None):
479:
480: """Änderung der Properties"""
481: coordsnew=[ string.split(x,",") for x in coords]
482:
483: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coords)
484:
485: self.coords=coordsnew[0:]
486: self.link=link
487: if RESPONSE is not None:
488: RESPONSE.redirect('manage_main')
489:
490:
491: manage_options = Folder.manage_options+(
492: {'label':'Main Config','action':'ECHO_externalLink_config'},
493: )
494:
495: def getCredits(self):
496: """Ausgabe der credits"""
497: if self.credits:
498: return self.credits
499: else:
500: return []
501:
502: def index_html(self):
503: """standard page"""
504:
505: return self.REQUEST.RESPONSE.redirect(self.link)
506:
507: def manage_addECHO_externalLinkForm(self):
508: """Form for external Links"""
509: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
510: return pt()
511:
512:
513: def manage_addECHO_externalLink(self,id,title,label,description,contentType,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
514: """Add an external Link"""
515:
516: newObj=ECHO_externalLink(id,link,title,label,description,contentType,responsible,credits,weight,coords)
517:
518: self._setObject(id,newObj)
519:
520: if RESPONSE is not None:
521: RESPONSE.redirect('manage_main')
522:
523:
524:
525: class ECHO_collection(Folder, Persistent, Implicit):
526: """ECHO Collection"""
527: security=ClassSecurityInfo()
528: meta_type='ECHO_collection'
529:
530: def getImageTag(self):
531: """GetTag"""
532: try:
533: return self.imageTag
534: except:
535: return ""
536:
537: def addResource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
538: """SSS"""
539: try:
540: manage_addECHO_resource(self,id,title,label,description,contentType,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None)
541: return "done"
542: except:
543: return None
544:
545: def getCollectionTreeXML(self):
546: """Tree as XML"""
547:
548: def getCollection(object,depth=0):
549: depth+=1
550: collections=""
551: for entry in object.__dict__.keys():
552: element=getattr(object,entry)
553: try:
554: if element.meta_type=="ECHO_collection":
555: collections+="<element name=\""+element.title+"\" url=\""+element.absolute_url()+"\">"
556: collections+=getCollection(element,depth)+"</element>\n"
557: except:
558: """nothing"""
559: return collections
560:
561:
562: return "<collection>"+getCollection(self)+"</collection>"
563:
564: def createJavaScript(self):
565: """CreateJava"""
566: ret=javaScriptMain
567:
568: dynamical=""
569: for ob in self.getGraphicCoords():
570: dynamical+="""Coords.push(new Coord('%s', Img, %s));\n"""%(ob[1],ob[0])
571: ret+=javaHandler%dynamical
572: return ret
573:
574: security.declarePublic('getCreditObject')
575: def getCreditObject(self,name):
576: """credit id to credititem"""
577: try:
578: return getattr(self.partners,name)
579: except:
580: return ""
581:
582: security.declarePublic('ECHO_generateNavBar')
583: def ECHO_generateNavBar(self):
584: """Erzeuge Navigationsbar"""
585: link=""
586: object="self"
587: ret=[]
588: path=self.getPhysicalPath()
589: for element in path:
590:
591:
592: if not element=="":
593: object+="."+element
594:
595: label=eval(object).label
596: link+="/"+element
597: if not label=="":
598: ret.append((label,link))
599: return ret
600:
601: security.declarePublic('ECHO_rerenderLinksMD')
602: def ECHO_rerenderLinksMD(self):
603: """Rerender all Links"""
604:
605: for entry in self.__dict__.keys():
606: object=getattr(self,entry)
607:
608:
609: try:
610:
611: if object.meta_type == 'ECHO_resource':
612:
613: object.ECHO_getResourceMD(template="no")
614:
615: except:
616: """nothing"""
617:
618: return "Rerenderd all links to resources in: "+self.title
619:
620: security.declarePublic('ECHO_newViewerLink')
621:
622:
623: def getCoords(self):
624: try:
625:
626: x= [string.join(x,",") for x in self.coords]
627: return x
628:
629: except:
630:
631: return []
632:
633: def __init__(self,id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,imageTag=""):
634: #print "CO",coords
635:
636: self.id = id
637: """Festlegen der ID"""
638: self.credits=toList(credits)
639: self.label = label
640: self.title=title
641: self.description=description
642: self.contentType=contentType
643: self.responsible=responsible
644: self.imageTag=imageTag
645: self.weight=weight
646: self.sortfield=sortfield
647: coordsnew=[ string.split(x,",") for x in coords]
648: self.coords=coordsnew
649:
650:
651: manage_options = Folder.manage_options+(
652: {'label':'Main Config','action':'ECHO_collection_config'},
653: {'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
654: {'label':'Graphics','action':'ECHO_graphicEntry'},
655:
656: )
657:
658: def getOverview(self):
659: """overview graphics"""
660:
661: return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
662:
663:
664: def ECHO_graphicEntry(self):
665: """DO nothing"""
666: overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
667:
668:
669: if overview:
670: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
671: return pt()
672: else:
673: return "NO OVERVIEW GRAPHICS"
674:
675: def ECHO_enterCoords(self,coordstr,angle="",RESPONSE=None):
676: """Enter coords"""
677: coords=self.coords
678: temco=coordstr.split(",")
679: temco.append(angle)
680: coords.append(temco)
681: self.coords=coords[0:]
682:
683: if RESPONSE is not None:
684: RESPONSE.redirect('ECHO_graphicEntry')
685:
686:
687: security.declarePublic('ECHO_collection_config')
688: def ECHO_collection_config(self):
689: """Main configuration"""
690:
691: if not hasattr(self,'weight'):
692: self.weight=""
693:
694: if not hasattr(self,'sortfield'):
695: self.sortfield="weight"
696:
697: if not hasattr(self,'coords'):
698: self.coords=[]
699:
700: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
701: return pt()
702:
703:
704: security.declarePublic('changeECHO_collection')
705:
706:
707: def changeECHO_collection(self,title,label,description,contentType,responsible,weight,credits=None,sortfield="weight",coords=None,RESPONSE=None,imageTag=""):
708: """Änderung der Properties"""
709:
710: self.imageTag=imageTag
711: coordsnew=[ string.split(x,",") for x in coords]
712:
713: setECHO_collectionInformation(self,title,label,description,contentType,responsible,credits,weight,coordsnew)
714:
715: self.coords=coordsnew[0:]
716: self.sortfield=sortfield
717:
718: if RESPONSE is not None:
719: RESPONSE.redirect('manage_main')
720:
721: security.declarePublic('index_html')
722:
723:
724: def showOverview(self):
725: """overview"""
726: if 'ECHO_overview.html' in self.__dict__.keys():
727: return getattr(self,'ECHO_overview.html')()
728: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_overview.zpt').__of__(self)
729: return pt()
730:
731:
732: def index_html(self):
733: """standard page"""
734:
735: if 'index.html' in self.__dict__.keys():
736: return getattr(self,'index.html')()
737: elif 'overview' in self.__dict__.keys():
738: return self.showOverview()
739:
740:
741: pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self)
742: pt.content_type="text/html"
743: return pt()
744:
745: def content_html(self):
746: """template fuer content"""
747: return content_html(self,'collection')
748:
749: def getCredits(self):
750: """Ausgabe der credits"""
751: if self.credits:
752: return self.credits
753: else:
754: return []
755:
756:
757:
758: def getGraphicCoords(self):
759: """Give list of coordinates"""
760: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
761: ids=[]
762: for entry in self.__dict__.keys():
763: object=getattr(self,entry)
764: try:
765: if object.meta_type in subColTypes:
766: for coordtemp in object.coords:
767: if len(coordtemp)>3:
768: coord=coordtemp[0:4]
769: if hasattr(object,'label') and not object.label=="":
770: ids.append([string.join(coord,", "),object.getId(),object.label,object])
771: elif hasattr(object,'title'):
772: if not object.title=="":
773: ids.append([string.join(coord,", "),object.getId(),object.title,object])
774: else:
775: ids.append([string.join(coord,", "),object.getId(),object.getId(),object])
776: else:
777: ids.append([string.join(coord,", "),object.getId(),object.getId(),object])
778:
779: except:
780: """nothing"""
781:
782: return ids
783:
784: def getSubCols(self,sortfield="weight"):
785:
786: subColTypes=['ECHO_collection','ECHO_externalLink','ECHO_resource']
787: ids=[]
788: for entry in self.__dict__.keys():
789: object=getattr(self,entry)
790: try:
791: if object.meta_type in subColTypes:
792: ids.append(object)
793:
794: except:
795: """nothing"""
796: try:
797: sortfield=self.sortfield
798: except:
799: """nothing"""
800:
801: tmplist=[]
802: for x in ids:
803: if hasattr(x,sortfield):
804: try:
805: x=int(x)
806: except:
807: """nothing"""
808: tmp=getattr(x,sortfield)
809: else:
810: tmp=10000000
811: tmplist.append((tmp,x))
812: tmplist.sort()
813: return [x for (key,x) in tmplist]
814:
815:
816:
817:
818:
819:
820: def manage_addECHO_collectionForm(self):
821: """Add collection form"""
822: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
823: return pt()
824:
825:
826: def manage_addECHO_collection(self,id,title,label,description,contentType,responsible,weight,sortfield,coords="",credits=None,RESPONSE=None,imageTag=""):
827: """add a echo collection"""
828:
829:
830: newObj=ECHO_collection(id,title,label,description,contentType,responsible,credits,weight,sortfield,coords,imageTag)
831:
832: self._setObject(id,newObj)
833:
834: if RESPONSE is not None:
835: RESPONSE.redirect('manage_main')
836:
837: class ECHO_root(Folder,Persistent,Implicit):
838: """ECHO Root Folder"""
839: meta_type="ECHO_root"
840:
841:
842: def contentTypeSelector_HTML(self,selected=None):
843: """give type selector"""
844: if not selected:
845: retStr="<option selected>\n"
846: else:
847: retStr="<option>\n"
848:
849: try:
850: for contentType in self.ZopeFind(self.contentTypes,obj_metatypes="ECHO_contentType"):
851: if selected and (contentType[0]==selected):
852: retStr+="""<option selected value="%s">%s\n"""%(contentType[0],contentType[0])
853: else:
854: retStr+="""<option value="%s">%s\n"""%(contentType[0],contentType[0])
855: except:
856: """nothing"""
857: return retStr
858:
859: def patchContentType(self,obj=None):
860: """austauschen content_type with contentType (patch bei umstieg von alter Version)"""
861:
862:
863: if not obj:
864: obj = self
865:
866: entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection','ECHO_externalLink','ECHO_pageTemplate'])
867:
868: for entry in entries:
869: setattr(entry[1],'contentType',entry[1].content_type)
870: #entry[1].contentType == entry[1].content_type
871:
872: if entry[1].meta_type == 'ECHO_collection':
873: entry[1].patchContentType(entry[1])
874:
875:
876: return "Rerenderd all links to resources in: "+self.title
877:
878: def ECHO_newViewerLink(self,obj=None):
879: """change links (:86 faellt weg)"""
880:
881: if not obj:
882: obj = self
883:
884: entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
885:
886: for entry in entries:
887:
888: if entry[1].meta_type == 'ECHO_resource':
889:
890: entry[1].link=re.sub('\:86','',entry[1].link)
891:
892: else:
893:
894: entry[1].ECHO_newViewerLink(entry[1])
895:
896: return "Rerenderd all links to resources in: "+self.title
897:
898: def __init__(self,id,title):
899: """init"""
900: self.id = id
901: self.title=title
902:
903: def deleteSpace(self,str):
904: """delete space at the end of a line"""
905: if str[len(str)-1]==" ":
906: return str[0:len(str)-1]
907: else:
908: return str
909:
910:
911:
912: # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
913:
914: def formatAscii(self,str,url=None):
915: """ersetze ascii umbrueche durch <br>"""
916: #url=None
917: if url:
918:
919: retStr=""
920: words=str.split("\n")
921:
922: for word in words:
923: strUrl=url%word
924: print "str",strUrl
925: retStr+="""<a href="%s">%s</a><br/>"""%(strUrl,word)
926: str=retStr
927: if str:
928: return re.sub(r"[\n]","<br/>",str)
929: else:
930: return ""
931:
932: def link2html(self,str):
933: """link2html fuer VLP muss hier noch raus"""
934: if str:
935: print str
936: str=re.sub("\&","&",str)
937: dom=xml.dom.minidom.parseString("<?xml version='1.0' ?><txt>"+str+"</txt>")
938: links=dom.getElementsByTagName("link")
939:
940: print "link",links
941: for link in links:
942: link.tagName="a"
943: ref=link.getAttribute("ref")
944: if self.checkRef(ref):
945: link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
946:
947: return dom.toxml('utf-8')
948: return ""
949:
950:
951: def checkRef(self,ref):
952: dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
953: res=None
954: for db in dbs.keys():
955: #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
956:
957: res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
958: return res
959:
960: #Ende Methode fuer vlp
961:
962: def PgQuoteString(self,string):
963: """Quote string"""
964: #print "PG",string
965: return libpq.PgQuoteString(string)
966:
967: def getPartners(self):
968: """Get list of Partners. Presently only from a subfolder partners"""
969:
970: return [ item[1] for item in self.partners.ZopeFind(self.partners,obj_metatypes=['ECHO_partner'])]
971:
972:
973:
974:
975:
976: def getPartnersXML(self):
977: """partner liste als xml"""
978: partners=self.getPartners()
979: ret="<partners>"
980: for partner in partners:
981: ret+="""<partner id="%s" title="%s"/>\n"""%(partner.getId(),partner.title)
982:
983: return ret+"\n</partners>"
984:
985: def getCollectionTree(self):
986: """get the collection tree (list of triples (parent,child, depth)"""
987:
988: def getCollection(object,depth=0):
989: depth+=1
990: collections=[]
991: for entry in object.__dict__.keys():
992: element=getattr(object,entry)
993: try:
994: if element.meta_type=="ECHO_collection":
995: collections.append((object,element,depth))
996: collections+=getCollection(element,depth)
997: except:
998: """nothing"""
999: return collections
1000:
1001:
1002: return getCollection(self)
1003:
1004: def getCollectionTreeIds(self):
1005: """Show the IDs of the Tree"""
1006: ret=[]
1007: for collection in self.getCollectionTree():
1008: ret.append((collection[0].getId(),collection[1].getId(),collection[2]))
1009: return ret
1010:
1011:
1012:
1013: def manage_addECHO_root(self,id,title,RESPONSE=None):
1014: """Add an ECHO_root"""
1015: self._setObject(id,ECHO_root(id,title))
1016:
1017: if RESPONSE is not None:
1018: RESPONSE.redirect('manage_main')
1019:
1020: def manage_addECHO_rootForm(self):
1021: """Nothing yet"""
1022: pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
1023: return pt()
1024:
1025: class ECHO_partner(Image,Persistent):
1026: """ECHO Partner"""
1027:
1028: meta_type="ECHO_partner"
1029:
1030: def __init__(self, id, title,url, file, content_type='', precondition=''):
1031: self.__name__=id
1032: self.title=title
1033: self.url=url
1034: self.precondition=precondition
1035:
1036: data, size = self._read_data(file)
1037: content_type=self._get_content_type(file, data, id, content_type)
1038: self.update_data(data, content_type, size)
1039:
1040: manage_options = Image.manage_options+(
1041: {'label':'Partner Information','action':'ECHO_partner_config'},
1042: )
1043:
1044: def changeECHO_partner(self,url,RESPONSE=None):
1045: """Change main information"""
1046: self.url=url
1047: if RESPONSE is not None:
1048: RESPONSE.redirect('manage_main')
1049:
1050:
1051:
1052: def ECHO_partner_config(self):
1053: """Main configuration"""
1054: if not hasattr(self,'url'):
1055: self.url=""
1056: pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
1057: return pt()
1058:
1059:
1060: manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
1061: Kind='ECHO_partner',kind='ECHO_partner')
1062:
1063:
1064:
1065: def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
1066: REQUEST=None):
1067: """
1068: Add a new ECHO_partner object.
1069:
1070: Creates a new ECHO_partner object 'id' with the contents of 'file'.
1071: Based on Image.manage_addImage
1072: """
1073:
1074: id=str(id)
1075: title=str(title)
1076: content_type=str(content_type)
1077: precondition=str(precondition)
1078:
1079: id, title = OFS.Image.cookId(id, title, file)
1080:
1081: self=self.this()
1082:
1083: # First, we create the image without data:
1084: self._setObject(id, ECHO_partner(id,title,url,'',content_type, precondition))
1085:
1086: # Now we "upload" the data. By doing this in two steps, we
1087: # can use a database trick to make the upload more efficient.
1088: if file:
1089: self._getOb(id).manage_upload(file)
1090: if content_type:
1091: self._getOb(id).content_type=content_type
1092:
1093: if REQUEST is not None:
1094: try: url=self.DestinationURL()
1095: except: url=REQUEST['URL1']
1096: REQUEST.RESPONSE.redirect('%s/manage_main' % url)
1097: return id
1098:
1099:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>