make publict product for PythonScripts
hello I have created a few useful functions that I keep in a file Products.mennucc (that I attach); I use them in my external products I would like to use them in Python Scripts; I have then imitated what is done e.g. in Products.PythonScripts.standard to make my functions 'public'.... but it does not work what am I doing wrong? thanks. a. -- Andrea Mennucc "one houndred and fifty - the chicken sings"
debdev@tonelli.sns.it wrote:
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
------------------------------------------------------------------------
Date: Thu, 15 Apr 2004 16:39:33 +0200
MIME-Version: 1.0 Content-Type: message/rfc822
------------------------------------------------------------------------
Date: Thu, 15 Apr 2004 16:39:33 +0200
MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----_=_NextPart_004_01C422CC.61B39B90"
------------------------------------------------------------------------
hello
I have created a few useful functions that I keep in a file Products.mennucc (that I attach); I use them in my external products
I would like to use them in Python Scripts; I have then imitated what is done e.g. in Products.PythonScripts.standard to make my functions 'public'.... but it does not work
what am I doing wrong?
thanks. a.
------------------------------------------------------------------------
"my own functions"
from AccessControl import ModuleSecurityInfo, getSecurityManager security = ModuleSecurityInfo()
security.declarePublic('append_par', 'add_par', 'manage_addProperty2')
from RestrictedPython.Utilities import same_type
def append_par_old(obj,kp,vp): if not same_type(vp,[]): return '('+kp+' is REALLY NOT a LIST?)' if obj.hasProperty(kp): v=obj.getProperty(kp) v=v+vp obj.manage_changeProperties({kp:v}) else: obj.manage_addProperty(kp, vp, 'lines') return '(appended '+kp+')'
def manage_addProperty2(self,id, value, type, selectionlist=None): if selectionlist is None: selectionlist = id+"_list" if self.hasProperty(id): self.manage_changeProperties({id:value}) else: if type == 'selection' : self.manage_addProperty(id, selectionlist, 'selection') self.manage_changeProperties({id:value}) else: self.manage_addProperty(id, value, type)
def append_par(obj,kp,vp): "add to 'list' parameters; vp must be a list" if not same_type(vp,[]): raise Exception,' argument vp is not a LIST? it is = '+repr(vp) if obj.hasProperty(kp): v=obj.getProperty(kp) if same_type(v,[]): v=v+vp elif same_type(v,()): v=v+tuple(vp) else: raise Exception, 'in obj '+repr(obj)+', property '+kp+' is not a LIST or a TUPLE' obj.manage_changeProperties({kp:v}) else: obj.manage_addProperty(kp, vp, 'lines') return '(appended '+kp+')'
def add_par(obj,kp,vp): "add parameter; if it is a list in the original request, as lines" #'descr' is standard in ExtFile if obj.hasProperty(kp): obj.manage_changeProperties({kp:vp}) print '(changed '+kp+')' else: #normalizza if request.form.has_key(kp): if same_type(request.form[kp],[]) and not same_type(vp,[]): vp=[vp] print '('+kp+' is NOT a LIST?)' if not same_type(request.form[kp],[]) and same_type(vp,[]): print '('+kp+' is a LIST?)' vp=vp[0] #verifica se c'e' una pre selezione per questa variabile nel container if container.hasProperty(kp+"_list"): obj.manage_addProperty(kp, kp+"_list", 'selection') obj.manage_changeProperties({kp:vp}) else: if same_type(vp,[]): obj.manage_addProperty(kp, vp, 'lines') else: obj.manage_addProperty(kp, vp, 'string') print '(added '+kp+')' return printed
#per pigrizia lo ho messo in CMF_ExtFile ma andrebbe qui.... def manage_beforeDelete(self, item, container): """Both of my parents have a beforeDelete method""" import sys a=PortalContent.manage_beforeDelete(self, item, container) b='PortalContent.manage_beforeDelete = '+repr(a)+'\n' a=EF.ExtFile.manage_beforeDelete(self, item, container) b=b+'EF.ExtFile.manage_beforeDelete = '+repr(a)+'\n' kp='filechilds' try: if item.hasProperty(kp): for j in item.getProperty(kp): try: container.manage_delObjects(j) b=b+' deleted '+repr(j) + ' alongside \n ' except: LOG('CMF_ExtFile',ERROR,'error while deleting alongside file '+repr(j), error=sys.exc_info()) b=b+' cant delete '+repr(j)+'\n'+sys.exc_info()+'\n' except: LOG('CMF_ExtFile',ERROR,'error while deleting filechilds', error=sys.exc_info()) pass LOG('CMF_ExtFile',DEBUG, b) return b
security.apply(globals())
had the same problem see: http://www.zopelabs.com/cookbook/991933953
participants (2)
-
Bernd Dorn -
debdev@tonelli.sns.it