[Zope] non static size parameter in dtml-var

Scott Parish sRp@srparish.net
Sun, 7 May 2000 21:46:45 +0000


--aVD9QWMuhilNxW9f
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

Thus spake Steve Alexander (steve@cat-box.net):

> Steve Alexander wrote:
> >=20
> > Scott Parish wrote:
> > >
> > > I have a dtml-var tag that is being repeated over and over inside of =
a dtml-in
> > > tag.  I would like the client to be able to custimize the maximum amo=
unt of
> > > text output they see, so i did something like the following:
> > >
> > >  <dtml-var "item['title']" size=3D"getTitleLen()">
> > >
> > > Where getTitleLen is a method which returns an integer of how many ch=
aracters
> > > max the title is to be.  However, when i have this dtml method render=
ed, i
> > > get the following error:
> > >
> > >   a size attribute was used in a var tag with a non-integer value.
> >=20
> > Looks like you'll need to patch lib/python/DocumentTemplate/DT_Var.py to
> > get this working.
> >=20
> > 326,328c326,331
> > <             except: raise 'Document Error',(
> > <                 '''a <code>size</code> attribute was used in a
> > <code>var</code>
> > <                 tag with a non-integer value.''')
> > ---
> > >             except:
> > >             try: size=3Datoi(str(md[size]))
> > >             except:
> > >               raise 'Document Error',(
> > >                   '''a <code>size</code> attribute was used in a <cod=
e>var</code>
> > >                   tag with a non-integer value.''')
> >=20
> > After this patch, you can use normal numeric literals, or you can use
> > values from the namespace.
>=20
> Except that the indentation of the patch hasn't come out right :-(
>=20
> The final code should look like this:
>=20
>         if have_arg('size'):
>             size=3Dargs['size']
>             try: size=3Datoi(size)
>             except:
>                 try: size=3Datoi(str(md[size]))
>                 except:
>                     raise 'Document Error',(
>                           '''a <code>size</code> attribute
>                           was used in a <code>var</code>
>                           tag with a non-integer value.''')
>=20
> Narrative:
>=20
> If the literal value of the attribute "size" doesn't easily parse into
> an integer, try looking up the value of the attribute "size" in the
> namespace, and see if that wants to be a number. If all that fails, give
> normal error message.
>=20
> --
> Steve Alexander
> Software Engineer
> Cat-Box limited
>=20
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -=20
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )

Beutiful!  Thank you very much!

Is this something that will get put into the zope tree for future versions,
or is this something that i'm going to need to send patch files out with my
product for?

sRp

--=20
Scott Parish
http://srparish.net

--aVD9QWMuhilNxW9f
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.0 (OpenBSD)
Comment: For info see http://www.gnupg.org

iD8DBQE5FeQ/QIKxCnswXL0RAXm4AKCEygZK+21QSqxCZQCpYHyj6Sh7EgCdGCQD
kxFJwTL0l88hnGEEEOEDUZc=
=LCmg
-----END PGP SIGNATURE-----

--aVD9QWMuhilNxW9f--