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