--- ECHO_content/ECHO_helpers.py 2004/12/02 20:11:49 1.31
+++ ECHO_content/ECHO_helpers.py 2005/02/03 11:34:00 1.38
@@ -4,7 +4,7 @@ import socket
import urllib
import string
import xml.dom.minidom
-from types import *
+import types
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
from OFS.SimpleItem import SimpleItem
from Globals import package_home
@@ -37,7 +37,9 @@ class ECHO_basis:
"""showrdf"""
self.REQUEST.RESPONSE.setHeader('Content-Type','text/xml')
ret="""\n\n"""
- ret+=self.getRDF(urn="echo:colllectionroot")+"\n"
+
+ ret+=self.getRDF(urn="echo:collectionroot")+"\n"
+
ret+=""""""
return ret
@@ -95,6 +97,7 @@ class ECHO_basis:
def getTitle(self):
"""title"""
+ return self.decode(self.title)
try:
return self.title.encode('utf-8','ignore')
except:
@@ -103,6 +106,8 @@ class ECHO_basis:
def getLabel(self):
"""title"""
+
+ return self.decode(self.label)
try:
return self.label.encode('utf-8','ignore')
except:
@@ -221,11 +226,12 @@ class ECHO_basis:
"""generate img-tag for map"""
bt = BrowserCheck(self)
tag = ""
- #src = self.REQUEST['URL1'] + "/overview"
src = self.getOverview().absolute_url()
if bt.isN4:
+ # N4 needs ilayer to create an id
tag += ''%src
else:
+ # img with id
tag += ''%src
return tag
@@ -242,14 +248,17 @@ class ECHO_basis:
text = ob.getLabel()
if text is None:
text = "link"
+ tiptext = ob.getText()
tag = ""
if bt.isN4:
+ # N4 needs layer for highlighting
tag += '" + text + ""
else:
+ # a-element
tag = '" + text + ""
return tag
@@ -262,6 +271,7 @@ class ECHO_basis:
tag = ""
if bt.isN4:
+ # N4 needs layer and img elements
tag += ''%(id,id,id)
if ob.isTypeArrow():
rot = ob.angle
@@ -273,21 +283,29 @@ class ECHO_basis:
tag += ' />'
tag += ''
else:
+ # create a-element
tag = ''%(id,id,id,link)
if ob.isTypeArrow():
rot = ob.angle
if bt.isIEWin and bt.versIE > 5:
+ # IE/Win 5.5 has "feature" for PNG transparency
tag += ''%(id,arrowsrc,rot,arrowsrc,rot)
else:
+ # arrow image
tag += ''%(id,arrowsrc,rot)
else:
- if bt.isIEWin:
- tag += '"
else:
+ # div for area
tag += '
'
+ if tiptext:
+ tag += ' title="%s"'%tiptext
+ tag += '> '
tag += ''
return tag
@@ -297,7 +315,7 @@ class ECHO_basis:
def toList(field):
"""Einzelfeld in Liste umwandeln"""
- if type(field)==StringType:
+ if type(field)==types.StringType:
return [field]
else:
return field
@@ -370,12 +388,18 @@ def checkOnlyOneInGroup(object):
return displayedObjects[0][1]
else: return object
-def getSubCols(self,sortfield="weight",subColTypes= displayTypes,sortFieldMD=None):
+def getSubCols(self, sortfield="weight", subColTypes=displayTypes, sortFieldMD=None):
def sortfnc(sortfield,x,y):
- xa=x[1].getMDValue(sortfield)
- ya=y[1].getMDValue(sortfield)
- print xa,ya
+ try:
+ xa=x[1].getMDValue(sortfield)
+ except:
+ xa=""
+ try:
+ ya=y[1].getMDValue(sortfield)
+ except:
+ ya=""
+ #print xa,ya
return cmp(xa,ya)
sortWithMD = lambda sortfield : (lambda x,y : sortfnc(sortfield,x,y))
@@ -394,23 +418,24 @@ def getSubCols(self,sortfield="weight",s
"""nothing"""
tmplist=[]
- for x in ids:
- if hasattr(x,sortfield):
- try:
- x=int(x)
- except:
- """nothing"""
- tmp=getattr(x,sortfield)
- else:
- tmp=10000000
- tmplist.append((tmp,x))
+ for x in ids:
+ if hasattr(x,sortfield):
+ try:
+ tmp=int(getattr(x,sortfield))
+ except:
+ tmp=getattr(x,sortfield)
+
+ else:
+ tmp=10000000
+
+ tmplist.append((tmp,x))
if not sortFieldMD:
tmplist.sort()
else:
tmplist.sort(sortWithMD(sortFieldMD))
-
+
return [x for (key,x) in tmplist]
def ECHO_rerenderLinksMD(self,obj=None,types=['title','label']):
@@ -567,23 +592,46 @@ def checkDiffs(self,metadict):
return diffs
-def zptFile(self, path):
+def zptFile(self, path, orphaned=False):
"""returns a page template file from the product"""
- pt=PageTemplateFile(os.path.join(package_home(globals()), path)).__of__(self)
+ if orphaned:
+ # unusual case
+ pt=PageTemplateFile(os.path.join(package_home(globals()), path))
+ else:
+ pt=PageTemplateFile(os.path.join(package_home(globals()), path)).__of__(self)
return pt
-def sendFile(self, filename, type):
- """sends an object or a local file (in the product) as response"""
+def findObjectPath(startobject, filename):
+ """returns the object with the name filename starting at startobject"""
+ if startobject is None:
+ return None
paths = filename.split('/')
- object = self
- # look for an object called filename
+ object = startobject
for path in paths:
if hasattr(object, path):
object = getattr(object, path)
else:
object = None
break
+ return object
+
+
+def zptObjectOrFile(self, filename, localdir='zpt', orphaned=False):
+ """returns a page template instance or a file from the product"""
+ # look for an object called path
+ pt = findObjectPath(self, filename)
+ # the object should also not be a python function
+ if (pt is None) or isinstance(pt, types.FunctionType):
+ # get a ZPT file
+ pt = zptFile(self, localdir+'/'+filename, orphaned=orphaned)
+ return pt
+
+
+def sendFile(self, filename, type):
+ """sends an object or a local file (in the product) as response"""
+ # look for an object called filename
+ object = findObjectPath(self, filename)
if object:
# if the object exists then send it
return object.index_html(self.REQUEST.REQUEST, self.REQUEST.RESPONSE)