--- ECHO_content/ECHO_collection.py 2003/12/10 10:53:55 1.5
+++ ECHO_content/ECHO_collection.py 2004/03/30 12:44:57 1.20
@@ -1,4 +1,4 @@
-
+"""New version of the product started February, 8th. Without scientific classification, use content-type for further classification."""
"""Echo collection provides the classes for the ECHO content web-site.
class ECHO_collection is the basis class for an ECHO collection.
@@ -8,9 +8,9 @@ class ECHO_resource contains information
class ECHO_externalLink contains information on externalLinks
-
"""
import string
+import re
import OFS.Image
from types import *
from OFS.Image import Image
@@ -24,12 +24,18 @@ from Products.PageTemplates.PageTemplate
from Products.PageTemplates.PageTemplate import PageTemplate
from Globals import Persistent
from Acquisition import Implicit
-
+#from psycopg import libpq
+#from pyPgSQL import libpq
+import xml.dom.minidom
import urllib
import xml.dom.minidom
+#List of different types for the graphical linking viewer
+viewClassificationListMaster=['view point','area']
+
+
def toList(field):
"""Einzelfeld in Liste umwandeln"""
if type(field)==StringType:
@@ -90,10 +96,12 @@ def readMetadata(url):
return metadict,""
-def setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coordstrs):
+def setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordstrs,viewClassification=""):
"""Allegemeine Informationen zu einer ECHO Collection"""
+ self.viewClassification=viewClassification
+
self.label = label
self.title=title
self.description=description
@@ -102,24 +110,26 @@ def setECHO_CollectionInformation(self,c
self.credits=toList(credits)
self.weight=weight
- self.scientific_Information.source_type=source_type
- self.scientific_Information.period=period
- self.scientific_Information.scientific_Classification.context=context
- self.scientific_Information.scientific_Classification.science=science
- self.scientific_Information.scientific_Classification.practice=practice
-
coords=[]
#coordinates of for rectangles
- for coordstr in coordstrs:
-
- temco=coordstr.split(",")
- #temco.append(angle)
- coords.append(temco)
+
+ #print "cs", coordstrs
+ if coordstrs:
+ for coordstr in coordstrs:
+ #print "cs", coordstr
+ try:
+ temco=coordstr.split(",")
+ except:
+ temco=[]
+ #temco.append(angle)
+ coords.append(temco)
+
+
self.coords=coords[0:]
class scientificClassification(SimpleItem,Persistent,Implicit):
- """subclass"""
+ """outdated will be deleeted in the next versions: subclass"""
security=ClassSecurityInfo()
def __init__(self,context,science,practice):
@@ -142,7 +152,7 @@ class scientificClassification(SimpleIte
class scientificInformation(Folder,Persistent,Implicit):
- """subclass scientificInformation"""
+ """outdated will be deleted in the next versions: subclass scientificInformation"""
security=ClassSecurityInfo()
@@ -168,7 +178,21 @@ class ECHO_resource(Folder):
"""ECHO Ressource"""
meta_type='ECHO_resource'
+ viewClassificationList=viewClassificationListMaster
+ def getViewClassification(self):
+ if hasattr(self,'viewClassification'):
+ return self.viewClassification
+ else:
+ return ""
+
+ def getCredits(self):
+ """Ausgabe der credits"""
+ if self.credits:
+ return self.credits
+ else:
+ return []
+
def __init__(self,id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords):
self.id = id
@@ -183,13 +207,17 @@ class ECHO_resource(Folder):
self.description=description
self.content_type=content_type
self.responsible=responsible
- coordsnew=[ string.split(x,",") for x in coords]
+
+ if coords:
+ coordsnew=[ string.split(x,",") for x in coords]
+ else:
+ coordsnew=[]
+
self.coords=coordsnew
def getCoords(self):
try:
- print
return [string.join(x,",") for x in self.coords]
except:
return []
@@ -203,16 +231,17 @@ class ECHO_resource(Folder):
if not hasattr(self,'coords'):
self.coords=[]
- pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_resource.zpt').__of__(self)
+ pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_resource.zpt').__of__(self)
return pt()
- def changeECHO_resource(self,metalink,link,context,science,practice,source_type,period,title,label,description,content_type,responsible,credits,weight,coords,RESPONSE=None):
+ def changeECHO_resource(self,metalink,link,title,label,description,content_type,responsible,weight,viewClassification="",coords=None,credits=None,RESPONSE=None):
+
"""Änderung der Properties"""
- setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords)
+ setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coords,viewClassification)
self.link=link
@@ -228,10 +257,16 @@ class ECHO_resource(Folder):
{'label':'Graphics','action':'ECHO_graphicEntry'},
)
+ def getOverview(self):
+ """overview graphics"""
+
+ return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
+
def ECHO_graphicEntry(self):
"""DO nothing"""
- if 'overview' in self.aq_parent.__dict__.keys():
- pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self)
+ overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
+ if overview:
+ pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
return pt()
else:
return "NO OVERVIEW GRAPHICS"
@@ -244,7 +279,7 @@ class ECHO_resource(Folder):
coords.append(temco)
self.coords=coords[0:]
- #pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self)
+
if RESPONSE is not None:
RESPONSE.redirect('ECHO_graphicEntry')
@@ -252,7 +287,7 @@ class ECHO_resource(Folder):
"""Einlesen der Metadaten und Anlegen dieser Metadaten als Informationen zur Resource"""
(metadict, error)=readMetadata(self.metalink)
- #print "BLA"
+
if not error=="": #Fehler beim Auslesen des Metafiles
return "ERROR:",error
@@ -262,11 +297,11 @@ class ECHO_resource(Folder):
self.metadata=metadict.keys()
- #return "BLUccssB"
+
self.label=self.generate_label()
if template=="yes":
- pt=PageTemplateFile('Products/ECHO_content/ECHO_resourceMD.zpt').__of__(self)
+ pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_resourceMD.zpt').__of__(self)
return pt()
def ECHO_getMD(self,item):
@@ -281,29 +316,23 @@ class ECHO_resource(Folder):
def generate_label(self):
"""Erzeugt_standard_Label aus Template"""
pt=getattr(self,"label_template_"+self.bib_type)
- #return pt
- #pt.content_type="text/html; charset=utf-8"
+
return pt()
-def manage_AddECHO_resourceForm(self):
- """Nothing yet"""
- pt=PageTemplateFile('Products/ECHO_content/AddECHO_resourceForm.zpt').__of__(self)
+def manage_addECHO_resourceForm(self):
+ """Form for adding a ressource"""
+ pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_resourceForm.zpt').__of__(self)
return pt()
-def manage_AddECHO_resource(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,link,metalink,credits,weight,coords,RESPONSE=None):
- """nothing yet"""
- scientificClassificationObj=scientificClassification(context,science,practice)
-
- scientificInformationObj=scientificInformation(source_type,period)
-
+def manage_addECHO_resource(self,id,title,label,description,content_type,responsible,link,metalink,weight,credits=None,coords=None,RESPONSE=None):
+ """addaresource"""
newObj=ECHO_resource(id,link,metalink,title,label,description,content_type,responsible,credits,weight,coords)
self._setObject(id,newObj)
- getattr(self,id)._setObject('scientific_Information',scientificInformationObj)
- getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj)
+
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
@@ -336,20 +365,20 @@ class ECHO_externalLink(Folder):
if not hasattr(self,'weight'):
self.weight=""
if not hasattr(self,'coords'):
- print "HI"
+
self.coords=['']
- print "G",self.coords
+ #print "G",self.coords
- pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_externalLink.zpt').__of__(self)
+ pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_externalLink.zpt').__of__(self)
return pt()
- def changeECHO_externalLink(self,link,context,science,practice,source_type,period,title,label,description,content_type,responsible,credits,weight,coords,RESPONSE=None):
+ def changeECHO_externalLink(self,link,title,label,description,content_type,responsible,weight,coords=None,credits=None,RESPONSE=None):
"""Änderung der Properties"""
- setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords)
+ setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coords)
self.link=link
@@ -360,31 +389,32 @@ class ECHO_externalLink(Folder):
manage_options = Folder.manage_options+(
{'label':'Main Config','action':'ECHO_externalLink_config'},
)
-
+
+ def getCredits(self):
+ """Ausgabe der credits"""
+ if self.credits:
+ return self.credits
+ else:
+ return []
+
def index_html(self):
"""standard page"""
return self.REQUEST.RESPONSE.redirect(self.link)
-def manage_AddECHO_externalLinkForm(self):
- """Nothing yet"""
- pt=PageTemplateFile('Products/ECHO_content/AddECHO_externalLinkForm.zpt').__of__(self)
+def manage_addECHO_externalLinkForm(self):
+ """Form for external Links"""
+ pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_externalLinkForm.zpt').__of__(self)
return pt()
-def manage_AddECHO_externalLink(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,link,credits,weight,coords,RESPONSE=None):
-
- """nothing yet"""
- scientificClassificationObj=scientificClassification(context,science,practice)
-
- scientificInformationObj=scientificInformation(source_type,period)
-
+def manage_addECHO_externalLink(self,id,title,label,description,content_type,responsible,link,weight,coords=None,credits=None,RESPONSE=None):
+ """Add an external Link"""
newObj=ECHO_externalLink(id,link,title,label,description,content_type,responsible,credits,weight,coords)
self._setObject(id,newObj)
- getattr(self,id)._setObject('scientific_Information',scientificInformationObj)
- getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj)
+
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
@@ -399,8 +429,11 @@ class ECHO_collection(Folder, Persistent
security.declarePublic('getCreditObject')
def getCreditObject(self,name):
"""credit id to credititem"""
- return getattr(self.partners,name)
-
+ try:
+ return getattr(self.partners,name)
+ except:
+ return ""
+
security.declarePublic('ECHO_generateNavBar')
def ECHO_generateNavBar(self):
"""Erzeuge Navigationsbar"""
@@ -423,8 +456,7 @@ class ECHO_collection(Folder, Persistent
security.declarePublic('ECHO_rerenderLinksMD')
def ECHO_rerenderLinksMD(self):
"""Rerender all Links"""
- #print "HI"
- #return "OK"
+
for entry in self.__dict__.keys():
object=getattr(self,entry)
@@ -439,25 +471,22 @@ class ECHO_collection(Folder, Persistent
"""nothing"""
return "Rerenderd all links to resources in: "+self.title
-
-
-
- security.declarePublic('printall')
- def printall(self):
- return self.scientific_information.__dict__.keys()
+ security.declarePublic('ECHO_newViewerLink')
+
def getCoords(self):
try:
- print self.coords
- return [string.join(x,",") for x in self.coords]
-
+
+ x= [string.join(x,",") for x in self.coords]
+ return x
except:
+
return []
def __init__(self,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords):
- print "CO",coords
+ #print "CO",coords
self.id = id
"""Festlegen der ID"""
@@ -475,16 +504,25 @@ class ECHO_collection(Folder, Persistent
manage_options = Folder.manage_options+(
- {'label':'Main Config','action':'ECHO_Collection_config'},
+ {'label':'Main Config','action':'ECHO_collection_config'},
{'label':'Rerender Links','action':'ECHO_rerenderLinksMD'},
{'label':'Graphics','action':'ECHO_graphicEntry'},
)
+ def getOverview(self):
+ """overview graphics"""
+
+ return self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])[0][1]
+
+
def ECHO_graphicEntry(self):
"""DO nothing"""
- if 'overview' in self.aq_parent.__dict__.keys():
- pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self)
+ overview = self.aq_parent.ZopeFind(self.aq_parent,obj_ids=['overview'])
+
+
+ if overview:
+ pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_draw.zpt').__of__(self)
return pt()
else:
return "NO OVERVIEW GRAPHICS"
@@ -496,13 +534,13 @@ class ECHO_collection(Folder, Persistent
temco.append(angle)
coords.append(temco)
self.coords=coords[0:]
- #pt=PageTemplateFile('Products/ECHO_content/ECHO_draw.zpt').__of__(self)
+
if RESPONSE is not None:
RESPONSE.redirect('ECHO_graphicEntry')
- security.declarePublic('ECHO_Collection_config')
- def ECHO_Collection_config(self):
+ security.declarePublic('ECHO_collection_config')
+ def ECHO_collection_config(self):
"""Main configuration"""
if not hasattr(self,'weight'):
@@ -510,22 +548,23 @@ class ECHO_collection(Folder, Persistent
if not hasattr(self,'sortfield'):
self.sortfield="weight"
- #print "HI"
+
if not hasattr(self,'coords'):
self.coords=[]
- pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_Collection.zpt').__of__(self)
+ pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_collection.zpt').__of__(self)
return pt()
- security.declarePublic('changeECHO_Collection')
+ security.declarePublic('changeECHO_collection')
- def changeECHO_Collection(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coords,sortfield="weight",RESPONSE=None):
+ def changeECHO_collection(self,title,label,description,content_type,responsible,weight,credits=None,sortfield="weight",coords=None,RESPONSE=None):
"""Änderung der Properties"""
coordsnew=[ string.split(x,",") for x in coords]
- setECHO_CollectionInformation(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,coordsnew)
+
+ setECHO_collectionInformation(self,title,label,description,content_type,responsible,credits,weight,coordsnew)
self.sortfield=sortfield
@@ -534,24 +573,28 @@ class ECHO_collection(Folder, Persistent
security.declarePublic('index_html')
- showOverview=DTMLFile('ECHO_content_overview',globals())
+ showOverview=DTMLFile('dtml/ECHO_content_overview',globals())
def index_html(self):
"""standard page"""
- #print self.objectIDs()
if 'index.html' in self.__dict__.keys():
return getattr(self,'index.html')()
elif 'overview' in self.__dict__.keys():
- #print "HI"
return self.showOverview()
- pt=PageTemplateFile('Products/ECHO_content/ECHO_content_standard.zpt').__of__(self)
+ pt=PageTemplateFile('Products/ECHO_content/zpt/ECHO_content_standard.zpt').__of__(self)
pt.content_type="text/html"
return pt()
+ def getCredits(self):
+ """Ausgabe der credits"""
+ if self.credits:
+ return self.credits
+ else:
+ return []
def getGraphicCoords(self):
"""Give list of coordinates"""
@@ -559,12 +602,8 @@ class ECHO_collection(Folder, Persistent
ids=[]
for entry in self.__dict__.keys():
object=getattr(self,entry)
- #print "OB:",object
-
try:
- #print "MT:",object.meta_type
if object.meta_type in subColTypes:
- #print "MT:",object.meta_type,object.getId()
for coordtemp in object.coords:
if len(coordtemp)>3:
coord=coordtemp[0:4]
@@ -578,7 +617,7 @@ class ECHO_collection(Folder, Persistent
except:
"""nothing"""
- #print "IDS",ids
+
return ids
def getSubCols(self,sortfield="weight"):
@@ -587,10 +626,7 @@ class ECHO_collection(Folder, Persistent
ids=[]
for entry in self.__dict__.keys():
object=getattr(self,entry)
- #print "OB:",object
-
try:
- #print "MT:",object.meta_type
if object.meta_type in subColTypes:
ids.append(object)
@@ -620,25 +656,20 @@ class ECHO_collection(Folder, Persistent
-def manage_AddECHO_collectionForm(self):
- """Nothing yet"""
- pt=PageTemplateFile('Products/ECHO_content/AddECHO_collectionForm.zpt').__of__(self)
+def manage_addECHO_collectionForm(self):
+ """Add collection form"""
+ pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_collectionForm.zpt').__of__(self)
return pt()
-def manage_AddECHO_collection(self,context,science,practice,source_type,period,id,title,label,description,content_type,responsible,credits,weight,sortfield,coords,RESPONSE=None):
-
- """nothing yet"""
- scientificClassificationObj=scientificClassification(context,science,practice)
-
- scientificInformationObj=scientificInformation(source_type,period)
+def manage_addECHO_collection(self,id,title,label,description,content_type,responsible,weight,sortfield,coords="",credits=None,RESPONSE=None):
+ """add a echo collection"""
newObj=ECHO_collection(id,title,label,description,content_type,responsible,credits,weight,sortfield,coords)
self._setObject(id,newObj)
- getattr(self,id)._setObject('scientific_Information',scientificInformationObj)
- getattr(self,id).scientific_Information._setObject('scientific_Classification',scientificClassificationObj)
+
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
@@ -646,25 +677,112 @@ class ECHO_root(Folder,Persistent,Implic
"""ECHO Root Folder"""
meta_type="ECHO_root"
+ def ECHO_newViewerLink(self,obj=None):
+ """change links (:86 faellt weg)"""
+
+ if not obj:
+ obj = self
+
+ entries=obj.ZopeFind(obj,obj_metatypes=['ECHO_resource','ECHO_collection'])
+
+ for entry in entries:
+
+ if entry[1].meta_type == 'ECHO_resource':
+
+ entry[1].link=re.sub('\:86','',entry[1].link)
+
+ else:
+
+ entry[1].ECHO_newViewerLink(entry[1])
+
+ return "Rerenderd all links to resources in: "+self.title
+
def __init__(self,id,title):
"""init"""
self.id = id
self.title=title
+
+ def deleteSpace(self,str):
+ """delete space at the end of a line"""
+ if str[len(str)-1]==" ":
+ return str[0:len(str)-1]
+ else:
+ return str
+
+
+
+ # zusaetliche methoden fuer das vlp muessen in ein eigenes produkt
+
+ def formatAscii(self,str,url=None):
+ """ersetze ascii umbrueche durch
"""
+ #url=None
+ if url:
+
+ retStr=""
+ words=str.split("\n")
+
+ for word in words:
+ strUrl=url%word
+ print "str",strUrl
+ retStr+="""%s
"""%(strUrl,word)
+ str=retStr
+ if str:
+ return re.sub(r"[\n]","
",str)
+ else:
+ return ""
+
+ def link2html(self,str):
+ """link2html fuer VLP muss hier noch raus"""
+ if str:
+ print str
+ str=re.sub("\&","&",str)
+ dom=xml.dom.minidom.parseString(""+str+"")
+ links=dom.getElementsByTagName("link")
+
+ print "link",links
+ for link in links:
+ link.tagName="a"
+ ref=link.getAttribute("ref")
+ if self.checkRef(ref):
+ link.setAttribute("href",self.aq_parent.absolute_url()+"/vlp_coll?id="+ref)
+
+ return dom.toxml('utf-8')
+ return ""
+
+
+ def checkRef(self,ref):
+ dbs={'vl_literature':'AND CD LIKE \'%lise%\'','vl_technology':'','vl_people':''}
+ res=None
+ for db in dbs.keys():
+ #print ref,"select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])
+
+ res=res or self.search(var=str("select reference from %s where reference =\'%s\' %s"%(db,ref,dbs[db])))
+ return res
+
+ #Ende Methode fuer vlp
+
+ def PgQuoteString(self,string):
+ """Quote string"""
+ #print "PG",string
+ return libpq.PgQuoteString(string)
def getPartners(self):
"""Get list of Partners. Presently only from a subfolder partners"""
partnerTypes=['ECHO_partner']
ids=[]
- for entry in self.partners.__dict__.keys():
- object=getattr(self.partners,entry)
-
- try:
+ try:
+ for entry in self.partners.__dict__.keys():
+ object=getattr(self.partners,entry)
- if object.meta_type in partnerTypes:
- ids.append(object)
+ try:
+
+ if object.meta_type in partnerTypes:
+ ids.append(object)
- except:
- """nothing"""
+ except:
+ """nothing"""
+ except:
+ ids=[] # no partners
return ids
def getCollectionTree(self):
@@ -695,16 +813,16 @@ class ECHO_root(Folder,Persistent,Implic
-def manage_AddECHO_root(self,id,title,RESPONSE=None):
+def manage_addECHO_root(self,id,title,RESPONSE=None):
"""Add an ECHO_root"""
self._setObject(id,ECHO_root(id,title))
if RESPONSE is not None:
RESPONSE.redirect('manage_main')
-def manage_AddECHO_rootForm(self):
+def manage_addECHO_rootForm(self):
"""Nothing yet"""
- pt=PageTemplateFile('Products/ECHO_content/AddECHO_root.zpt').__of__(self)
+ pt=PageTemplateFile('Products/ECHO_content/zpt/AddECHO_root.zpt').__of__(self)
return pt()
class ECHO_partner(Image,Persistent):
@@ -738,16 +856,16 @@ class ECHO_partner(Image,Persistent):
"""Main configuration"""
if not hasattr(self,'url'):
self.url=""
- pt=PageTemplateFile('Products/ECHO_content/ChangeECHO_partner.zpt').__of__(self)
+ pt=PageTemplateFile('Products/ECHO_content/zpt/ChangeECHO_partner.zpt').__of__(self)
return pt()
-manage_AddECHO_partnerForm=DTMLFile('ECHO_partnerAdd',globals(),
+manage_addECHO_partnerForm=DTMLFile('dtml/ECHO_partnerAdd',globals(),
Kind='ECHO_partner',kind='ECHO_partner')
-def manage_AddECHO_partner(self, id, file,url, title='', precondition='', content_type='',
+def manage_addECHO_partner(self, id, file,url, title='', precondition='', content_type='',
REQUEST=None):
"""
Add a new ECHO_partner object.