[Zope-dev] Expressions like <dtml-var this url> bail out contrary to intuition -- proposed fix enclosed
Jarkko Kniivilä
jarkko.kniivila@ambientfactor.fi
Mon, 7 Feb 2000 14:53:03 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_0082_01BF717B.08C99D10
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hi fellow Zopistas!
While upgrading a Zope 2.1.0 beta installation recently to 2.1.3, I
discovered that a recent change made to 'DT_Var.py' rendered DTML
expressions like <dtml-var this url> and &dtml.url-this; inoperative. I had
been relying on them for a default action url on my forms (in DTML methods).
Especially the entity reference syntax is quite a nice abbreviation for the
more explicit <dtml-var "this().absolute_url()"> which still continues to
work.
The enclosed fix simply acknowledges that 'this' isn't a ZODB namespace
object but a method encapsulating python 'self' and thus always needs to be
invoked. I'm not quite on the top of things why the previous behavior was
changed in the first place (Jim? Anyone?).
I'll file this to the Collector if there's no objection by you. Copyright to
the patch is hereby transfered to Digital Creations to be used freely.
Cheers,
// Jarkko Kniivila, CTO, Ambient Factor New Media, Hameenlinna, Finland
------=_NextPart_000_0082_01BF717B.08C99D10
Content-Type: application/octet-stream;
name="Zope-2.1.x-enable-useful-this.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="Zope-2.1.x-enable-useful-this.diff"
--- Zope2/lib/python/DocumentTemplate/DT_Var.py Mon Dec 13 20:14:51 1999
+++ Zope2-verrokki/lib/python/DocumentTemplate/DT_Var.py Fri Feb 4 =
14:46:59 2000
@@ -264,11 +264,12 @@
=20
if val is None:
if md.has_key(name):
- if have_arg('url'):
- val=3Dmd.getitem(name,0)
- val=3Dval.absolute_url()
+ # In order to make <dtml-var this url> and =
&dtml.url-this;
+ # work, this() needs attention here.
+ if name=3D=3D'this' or not have_arg('url'):
+ val=3Dmd[name]
else:
- val =3D md[name]
+ val=3Dmd.getitem(name,0)
else:
if have_arg('missing'):
return args['missing']
@@ -276,7 +277,8 @@
raise KeyError, name
else:
val=3Dval.eval(md)
- if have_arg('url'): val=3Dval.absolute_url()
+
+ if have_arg('url'): val=3Dval.absolute_url()
=20
__traceback_info__=3Dname, val, args
=20
------=_NextPart_000_0082_01BF717B.08C99D10--