[Zope-dev] Re: ZPatterns: __getitem__ on a DataSkin instance
Steve Alexander wrote: Let's say I have a DataSkin-derived ZClass that has the attribute "forename" (in a dataskin attribute propertysheet). If I get an instance of this ZClass from the ZODB (set up to use a Folder w/ customizer suppport), I can refer to the "forename" attribute using dtml-var "this()['forename']". However, if I get an instance of the same class from a Specialist, dtml-var "this()['forename']" gives me Error Type: AttributeError Error Value: __getitem__ Any idea why there's the difference? Can the latter case be fixed? A workaround, using the ever-flexible skinscript: I've defined __getitem__ through skinscript and a PythonScript. SkinScript: WITH SELF COMPUTE __getitem__=getattr PythonScript: parameter list: index return getattr(index) -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Re: ZPatterns: __getitem__ on a DataSkin instance
Hi Steve, Hmm.. is the 'id' of your PythonScript also getattr? thanks, -steve "Steve" == Steve Alexander [EMAIL PROTECTED] writes: Steve Steve Alexander wrote: Let's say I have a DataSkin-derived ZClass that has the attribute "forename" (in a dataskin attribute propertysheet). If I get an instance of this ZClass from the ZODB (set up to use a Folder w/ customizer suppport), I can refer to the "forename" attribute using dtml-var "this()['forename']". However, if I get an instance of the same class from a Specialist, dtml-var "this()['forename']" gives me Error Type: AttributeError Error Value: __getitem__ Any idea why there's the difference? Can the latter case be fixed? Steve A workaround, using the ever-flexible skinscript: Steve I've defined __getitem__ through skinscript and a Steve PythonScript. Steve SkinScript: WITH SELF COMPUTE __getitem__=getattr Steve PythonScript: parameter list: index Stevereturn getattr(index) Steve -- Steve Alexander Software Engineer Cat-Box limited Steve http://www.cat-box.net Steve ___ Zope-Dev Steve maillist - [EMAIL PROTECTED] Steve http://lists.zope.org/mailman/listinfo/zope-dev ** No cross Steve posts or HTML encoding! ** (Related lists - Steve http://lists.zope.org/mailman/listinfo/zope-announce Steve http://lists.zope.org/mailman/listinfo/zope ) ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] Re: ZPatterns: __getitem__ on a DataSkin instance
Steve Spicklemire wrote: Hi Steve, Hmm.. is the 'id' of your PythonScript also getattr? Yes. I forgot to mention that. And, I realized just after posting the email to the list that calling a method "getattr" is asking for trouble :-) Actually, my workaround doesn't work except in the most trivial cases. My code was making more errors as Zope tried to look up the _ variable via __getitem__ and thus via my PythonScript. I've ended up using a dtml-if to choose whether to use a dtml-with stuff mapping block or just a plain dtml-with stuff block. I'd still like to know why a Dataskin from a specialist is behaving differently from one in the ZODB in this respect. -- Steve Alexander Software Engineer Cat-Box limited http://www.cat-box.net ___ Zope-Dev maillist - [EMAIL PROTECTED] http://lists.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope )