Hello list, --- I can't seem to find an elegant solution to checking if an object has a certain attribute. The following fails (i.e. zope dies), if the attribute does not exist: <p tal:condition="exists: obj/someAttribute" tal:replace="obj/someAttribute" /> Of course, I just want it to skip the tag. Dying is a bit rash. Specifically, I want to test if a certain CGI parameter has been set, i.e. that the REQUEST object has a certain attribute. What is the best way to do this in both ZPT and Python? \malthe ---- mail: mborch@3avod.dk blog: www.3avod.dk/blog/ crypto-key: 3avod.dk/keys/mborch.asc --------------------------------------
How about: <p tal:condition="obj/attribute|nothing" tal:replace="obj/attribute" /> Ben
-----Original Message----- From: zope-bounces@zope.org [mailto:zope-bounces@zope.org] On Behalf Of Malthe Borch Sent: 27 March 2005 00:16 To: zope@zope.org Subject: [Zope] avoiding 'AttributeError'
Hello list, ---
I can't seem to find an elegant solution to checking if an object has a certain attribute. The following fails (i.e. zope dies), if the attribute does not exist:
<p tal:condition="exists: obj/someAttribute" tal:replace="obj/someAttribute" />
Of course, I just want it to skip the tag. Dying is a bit rash.
Specifically, I want to test if a certain CGI parameter has been set, i.e. that the REQUEST object has a certain attribute.
What is the best way to do this in both ZPT and Python?
\malthe
---- mail: mborch@3avod.dk blog: www.3avod.dk/blog/ crypto-key: 3avod.dk/keys/mborch.asc --------------------------------------
_______________________________________________ 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 )
Malthe Borch wrote:
I can't seem to find an elegant solution to checking if an object has a certain attribute. The following fails (i.e. zope dies),
You probably want to get to tthe bottom of that since i suspect you're probably the only person on the planet that applies to ;-)
<p tal:condition="exists: obj/someAttribute" tal:replace="obj/someAttribute" />
if you're processing stuff, you sghould probably be doing it in a python script. ZPT is just for presentation... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Chris wrote: ' if you're processing stuff, you sghould probably be doing it in a python ' script. ZPT is just for presentation... Well, --- I'm using an external script to open a firewall and I'd like it to inform the user of the result of that operation. So I redirect it to the page the user came from and add '?fw_result=something'. Naturally, this page is sometimes shown without this parameter attached, so I need to make sure that the attribute exists before displaying it. I don't think that's logic. However, I would like to know how to use Plone's built-in form result logic. It seems you always get a little nifty orange bar telling you the result. I tried this: qs = context.create_query_string( REQUEST.get('QUERY_STRING', ''), portal_status_message=("My Message") ) But that didn't work ;) \malthe ---- mail: mborch@3avod.dk blog: www.3avod.dk/blog/ crypto-key: 3avod.dk/keys/mborch.asc --------------------------------------
Malthe Borch wrote:
Naturally, this page is sometimes shown without this parameter attached, so I need to make sure that the attribute exists before displaying it.
<div class="message" tal:define="fw_result request/fw_result|nothing" tal:condition="fw_result" tal:content="fw_result"/>
I don't think that's logic. However, I would like to know how to use Plone's built-in form result logic. It seems you always get a little nifty orange bar telling you the result. I tried this:
Google for CMFFormController to find out how it works... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
Malthe Borch wrote at 2005-3-27 01:15 +0100:
I can't seem to find an elegant solution to checking if an object has a certain attribute. The following fails (i.e. zope dies), if the attribute does not exist:
<p tal:condition="exists: obj/someAttribute" tal:replace="obj/someAttribute" />
This should not fail and, especially, Zope should not die. If Zope really dies, then there is a *severe* problem elsewhere (not with your ZPT code). -- Dieter
' -----Original Message----- ' From: Dieter Maurer [mailto:dieter@handshake.de] ' <p tal:condition="exists: obj/someAttribute" ' tal:replace="obj/someAttribute" /> ' ' This should not fail and, especially, Zope should not die. ' ' If Zope really dies, then there is a *severe* problem elsewhere ' (not with your ZPT code). It does fail, however zope doesn't 'die', it merely fails, displaying an error message. But as somebody else pointed out, it should read: <p tal:condition="obj/someAttribute|nothing" tal:replace="obj/someAttribute" /> because it's the tal:condition-tag that is failing. that's how I understand it at least. \malthe
participants (4)
-
Ben Mason -
Chris Withers -
Dieter Maurer -
Malthe Borch