Re: metal:Macro mit optionalen Parametern?

Andreas Jung <[email protected]>
Newsgroups gmane.comp.web.zope.german
Organization ZOPYX Ltd & Co. KG
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hartmut Goebel wrote:
> Am 11.03.2010 19:15, schrieb Andreas Jung:
>
>>> <div class="zettel" tal:define="object nocall:object |
>>> nocall:here;
>> Sorry aber das ist frickliger Code. Mach hier bitte explizite
>> Checks
>>
>> python: object is None
>>
>> oder so ähnlich rein - aber niemals via nocall:
>
> Lasen wir mal außen vor, dass der Name 'object' ungeschickt gewählt
> ist ;-)
>
> Ja, mir gefällt das auch nicht wirklich. Aber ich habe noch keine
> andere Lösung gefunden, wie ich optionale Parameter an ein
> metal:macro übergeben kann. Also dieses hier in METAL:
>
> def view_macro(object=None): if object is None: object = here
>
> Der Code stammt aus einem metal:macro, das Teil von teaser_view.pt
> ist. teaser_view.pt implementiert die document_view für Teaser,
> quasi als Vorschau im Hauptteil der Seite.
>
> Das Makro verwende ich dann, um die Teaser in einem Portlet
> anzuzeigen:
>
> <div ... tal:repeat="ref refs"> <!-- refs sind die gefundenen
> Teaser --> <div tal:define="object nocall:ref" tal:omit-tag="">
> <div metal:use-macro="here/teaser_view/macros/main"> Kontaktdaten
> </div> </div> </div>
>
> Wie kann ich das eleganter lösen?
Hier hast Du ein Beispiel wo ein eine Objekt Instanz nicht
zu True evaluiert - d.h. der vergleichbare Check auf
Existenz greift nicht:

ajung@suxmac2:~ cat test.py

class Foo(object):

    def __nonzero__(self):
        return False

    def __len__(self):
        return False

foo = Foo()

if foo:
    print 'foo'
else:
    print 'not foo'

ajung@suxmac2:~ python2.4 test.py
not foo


- -aj


- -- 
ZOPYX Limited              \ zopyx group
Charlottenstr. 37/1         \ The full-service network for your
D-72070 Tübingen             \ Python, Zope and Plone projects
www.zopyx.com, [email protected] \ www.zopyxgroup.com
- ------------------------------------------------------------------------
E-Publishing, Python, Zope & Plone development, Consulting


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkuZRBcACgkQCJIWIbr9KYweiACeNl0RhmmCMF+fXW4E6++XXwh5
5xMAnim5Y+VVvUrd9KIZWn5x22ZN6JZA
=Nvzm
-----END PGP SIGNATURE-----



_______________________________________________
zope mailing list
[email protected]
https://mail.dzug.org/mailman/listinfo/zope
lists.vcf (text/x-vcard, 331 B)
begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[email protected]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.