[ZPT] TAL omitAllTags proposal
Godefroid Chapelle
gotcha@swing.be
Tue, 26 Mar 2002 09:36:01 +0100
At 19:42 25/03/2002, Michael Fair wrote:
>Without meaning any offense, shouldn't this kind of
>SQL code generation really be generated in a Python
>Script (or even DTML Method) then merely rendered
>using ZPT?
>
>The reason this is so stange using ZPT is that it
>is doing more than what ZPT's are designed for.
>
>Wouldn't it be easier to pass this logic off to something
>outside the page template where you have the kind of
>branching and string manipulation tools you want
>to make this kind of string development easy?
Actually, I am writing a tool which generates a full database schema from
an XML description.
I think that (Z)PT is a wonderful tool to generate text (which SQL is).
Obviously, I also have Python code in pseudo Python scripts which I access
through PT.
But what I get is a nice separation between logic and presentation ;-)...
>-- Michael --
>
>----- Original Message -----
>From: "Godefroid Chapelle" <gotcha@swing.be>
>To: <zpt@zope.org>
>Sent: Friday, March 22, 2002 3:08 AM
>Subject: [ZPT] TAL omitAllTags proposal
>
>
> > We are using PageTemplates outside Zope to generate SQL data definitions.
> >
> > You find hereunder the type of code we wrote first in order to get
> > well-formatted (human readable) SQL code.
> >
> > CREATE TABLE <tal:block tal:replace="table/name"/> (
> > <tal:block tal:repeat="field table/field"> <tal:block
> > tal:replace="field/name"/> <tal:block tal:replace="field/type"/><tal:block
> > tal:condition="python:hasattr(field,'length')">(<tal:block
> > tal:replace="field/length"/>)</tal:block><tal:block
> > tal:condition="python:hasattr(field,'notnull')"> NOT
> > NULL</tal:block><tal:block
> > tal:condition="python:hasattr(field,'foreignkey')"> REFERENCES <tal:block
> > tal:replace="field/foreignkey/table/name"/>(<tal:block
> > tal:replace="field/foreignkey/field/name"/>)</tal:block>,</tal:block>
> > PRIMARY KEY (<tal:block tal:repeat="primarykey
> > table/primarykeys"><tal:block tal:replace="primarykey/name"/><tal:block
> > tal:condition="not:repeat/primarykey/end">, </tal:block></tal:block>)
> > );
> >
> >
> > This type of code is quite difficult to debug because of the multiplicity
> > of 'tal:block' elements.
> > So we rewrote it like this :
> >
> > CREATE TABLE <tablename tal:omit-tag="" tal:replace="table/name"/> (
> > <fields tal:omit-tag="" tal:repeat="field table/field"> <fieldname
> > tal:omit-tag="" tal:replace="field/name"/> <fieldtype tal:omit-tag=""
> > tal:replace="field/type"/><typelength tal:omit-tag=""
> > tal:condition="python:hasattr(field,'length')">(<tal:block
> > tal:replace="field/length"/>)</typelength><notnull tal:omit-tag=""
> > tal:condition="python:hasattr(field,'notnull')"> NOT
> > NULL</notnull><foreignkey tal:omit-tag=""
> > tal:condition="python:hasattr(field,'foreignkey')"> REFERENCES <tablename
> > tal:omit-tag="" tal:replace="field/foreignkey/table/name"/>(<fieldname
> > tal:omit-tag=""
> > tal:replace="field/foreignkey/field/name"/>)</foreignkey>,</fields>
> > PRIMARY KEY (<primarykeys tal:omit-tag="" tal:repeat="primarykey
> > table/primarykeys"><tal:block tal:replace="primarykey/name"/><comma
> > tal:omit-tag="" tal:condition="not:repeat/primarykey/end">,
> > </comma></primarykeys>)
> > );
> >
> > where we get easier code to debug but with a lot of 'tal:omit-tag'.
> >
> >
> > As I am generating SQL, I know I do not want any xml-like tags. I would
> > like to state it and avoid repetitions of 'tal:omit-tag'.
> > I would be able to use the following code:
> >
> > CREATE TABLE <tablename tal:replace="table/name"/> (
> > <fields tal:repeat="field table/field"> <fieldname
> > tal:replace="field/name"/> <fieldtype
>tal:replace="field/type"/><typelength
> > tal:condition="python:hasattr(field,'length')">(<tal:block
> > tal:replace="field/length"/>)</typelength><notnull
> > tal:condition="python:hasattr(field,'notnull')"> NOT
> > NULL</notnull><foreignkey
> > tal:condition="python:hasattr(field,'foreignkey')"> REFERENCES <tablename
> > tal:replace="field/foreignkey/table/name"/>(<fieldname
> > tal:replace="field/foreignkey/field/name"/>)</foreignkey>,</fields>
> > PRIMARY KEY (<primarykeys tal:repeat="primarykey
> > table/primarykeys"><tal:block tal:replace="primarykey/name"/><comma
> > tal:condition="not:repeat/primarykey/end">, </comma></primarykeys>)
> > );
> >
> >
> > I went through the python source code. It was really easy to add the
>feature.
> >
> >
> > I came to the following patches:
> >
> > TAL/HTMLTALParser.py ( 1.30.4.3.4.1 )
> >
> > 102c
> > < def __init__(self, gen=None):
> > ---
> > > def __init__(self, gen=None, omitAllTags=0):
> > 109a
> > > self.omitAllTags = omitAllTags
> > 288a288,289
> > > if self.omitAllTags:
> > > taldict['omit-tag'] = ''
> >
> >
> > PageTemplates/PageTemplate.py ( 1.20.10.2 )
> >
> > 49c49,50
> > < def pt_edit(self, text, content_type):
> > ---
> > > def pt_edit(self, text, content_type, omitAllTags=0):
> > > self.omitAllTags = omitAllTags
> > 145c
> > < parser = HTMLTALParser(gen)
> > ---
> > > parser = HTMLTALParser(gen, self.omitAllTags)
> >
> >
> > As both patches are light and nonintrusive, I propose to introduce them in
> > the core.
> >
> >
> > --
> >
> > Godefroid Chapelle
> >
> > BubbleNet sprl
> > rue Victor Horta, 18 / 202
> > 1348 Louvain-la-Neuve
> > Belgium
> >
> > Tel + 32 (10) 459901
> > Mob + 32 (477) 363942
> >
> > TVA 467 093 008
> > RC Niv 49849
> >
> >
> > _______________________________________________
> > ZPT mailing list
> > ZPT@zope.org
> > http://lists.zope.org/mailman/listinfo/zpt
> >
>
>
>_______________________________________________
>ZPT mailing list
>ZPT@zope.org
>http://lists.zope.org/mailman/listinfo/zpt
--
Godefroid Chapelle
BubbleNet sprl
rue Victor Horta, 18 / 202
1348 Louvain-la-Neuve
Belgium
Tel + 32 (10) 459901
Mob + 32 (477) 363942
TVA 467 093 008
RC Niv 49849