<dtml-in> how do I get count of records in sequence? (aka batch-size)
I want to be able to do something like this: <dtml-in "GetDB()[Table][Indice][Rec].fetchall()"> <dtml-with "_['sequence-item']"> <dtml-if "_['sequence-size'] == 1"> <dtml-var "tableFromView(URL=URL0)"> <dtml-else> <dtml-var "tableFromView(viewName='DefaultLocatorView',URL=URL0)"> </dtml-if> </dtml-with> </dtml-in> That is, produce different output depending on the number of items returned from dtml-in. There isn't a "sequence-size" variable. I thought "batch-size" would work, but that doesn't seem to exist either, even when I use "size=nn" in the dtml-in statement. I know I can use total-nnn, but then I need to know an attribute name. In this case, I do *not* know any of the attributes in the objects returned from fetchall(). Therefore I'm stuck doing something like this: <dtml-if "_.len(GetDB()[Table][Indice][Rec].fetchall()) == 1"> <dtml-var "GetDB()[Table][Indice][Rec].fetchone().tableFromView(URL=URL0)"> <dtml-else> <dtml-in "GetDB()[Table][Indice][Rec].fetchall()"> <dtml-with "_['sequence-item']"> <dtml-var "tableFromView(viewName='DefaultLocatorView',URL=URL0)"> </dtml-with> </dtml-in> This is ugly, and unlike SQLMethods, the value returned from fetchall() is not cached. (not sure if DTML caches the result of the call or not) FYI, I'm using SQLDict.py here, and its very nice. Next step is to emulate a DB interface using Zope Database Adapters. This way I can test my core logic outside of Zope, but work with the transaction machinery inside zope. Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements
the right way to do it is to extract a field from the database (lets call it "field") and then: <dtml-if "_['count-field'] == 1"> ... <dtml-else> ... </dtml-if> Scavenging the mail folder uncovered Brad Clements's letter:
I want to be able to do something like this:
<dtml-in "GetDB()[Table][Indice][Rec].fetchall()"> <dtml-with "_['sequence-item']"> <dtml-if "_['sequence-size'] == 1"> <dtml-var "tableFromView(URL=URL0)"> <dtml-else> <dtml-var "tableFromView(viewName='DefaultLocatorView',URL=URL0)"> </dtml-if> </dtml-with> </dtml-in>
That is, produce different output depending on the number of items returned from dtml-in.
There isn't a "sequence-size" variable. I thought "batch-size" would work, but that doesn't seem to exist either, even when I use "size=nn" in the dtml-in statement.
I know I can use total-nnn, but then I need to know an attribute name. In this case, I do *not* know any of the attributes in the objects returned from fetchall().
Therefore I'm stuck doing something like this:
<dtml-if "_.len(GetDB()[Table][Indice][Rec].fetchall()) == 1"> <dtml-var "GetDB()[Table][Indice][Rec].fetchone().tableFromView(URL=URL0)"> <dtml-else> <dtml-in "GetDB()[Table][Indice][Rec].fetchall()"> <dtml-with "_['sequence-item']"> <dtml-var "tableFromView(viewName='DefaultLocatorView',URL=URL0)"> </dtml-with> </dtml-in>
This is ugly, and unlike SQLMethods, the value returned from fetchall() is not cached. (not sure if DTML caches the result of the call or not)
FYI, I'm using SQLDict.py here, and its very nice. Next step is to emulate a DB interface using Zope Database Adapters. This way I can test my core logic outside of Zope, but work with the transaction machinery inside zope.
Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org 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 )
-- Federico Di Gregorio MIXAD LIVE System Programmer fog@mixadlive.com Debian GNU/Linux Developer & Italian Press Contact fog@debian.org Put a GNOME on your desktop! [http://www.gnome.org] -- brought to you by One Line Spam
On 17 Apr 2000, at 17:52, Federico Di Gregorio wrote:
the right way to do it is to extract a field from the database (lets call it "field") and then:
<dtml-if "_['count-field'] == 1"> ... <dtml-else> ... </dtml-if>
Right, but as I said in my post, I do *NOT* know any of the field names in advance. This is a generic DTML method that needs to work with any table, therefore I can not use "count-xxx". Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax netmeeting: ils://ils.murkworks.com AOL-IM: BKClements
Scavenging the mail folder uncovered Brad Clements's letter:
On 17 Apr 2000, at 17:52, Federico Di Gregorio wrote:
the right way to do it is to extract a field from the database (lets call it "field") and then:
<dtml-if "_['count-field'] == 1"> ... <dtml-else> ... </dtml-if>
Right, but as I said in my post, I do *NOT* know any of the field names in advance.
sorry... mmm... <dtml-if "_['sequence-last'] and _['sequence-first']"> ? if you have only one entry both sequence-last and sequence-fist should be true, isn't it? ciao, federico -- Federico Di Gregorio MIXAD LIVE System Programmer fog@mixadlive.com Debian GNU/Linux Developer & Italian Press Contact fog@debian.org All programmers are optimists. -- Frederick P. Brooks, Jr.
I'm trying to use Aquisition to allow access to a file repository called stylesheets (it's simply a top level folder which holds a bunch of files). I want to be able to access the data attribute of a specific file in the repository from anywhere in the zope heirarchy using aquisition, but i'm not sure how to go about this. Right now I'm doing this: <dtml-let xsldata="stylesheets._[stylesheet].data"> where the 'stylesheet' is the id of the file I want to access in the repository. I'm getting an unauthorized error, and I think it's because I don't have access to the stylesheet folder's _ object even thought I can reference the folder itself via aquisition. There are no accessible methods (not even those inherited from Object Manager) that will help me retrieve a file (by an id string) from a folder refered to via aquisition, at least there is none that I know of. Can anyone help me with this or advise a better way to tackle this problem? Chime
----- Original Message ----- From: "Chimezie Ogbuji" <cogbuji@fourthought.com>
<dtml-let xsldata="stylesheets._[stylesheet].data">
This ought to work: <dtml-let xsldata="stylesheets[stylesheet].data"> You were only two characters away :-) In general, Folders allow you to access their contents through item access like this. If you wanted to acquire instead of just access contents (or if it wasn't a Folder), you could write: <dtml-let xsldata="_.getattr(stylesheets, stylesheet).data"> Cheers, Evan @ 4-am & digicool
Brad Clements wrote:
I want to be able to do something like this:
<dtml-in "GetDB()[Table][Indice][Rec].fetchall()"> <dtml-with "_['sequence-item']"> <dtml-if "_['sequence-size'] == 1"> <dtml-var "tableFromView(URL=URL0)"> <dtml-else> <dtml-var "tableFromView(viewName='DefaultLocatorView',URL=URL0)"> </dtml-if> </dtml-with> </dtml-in>
First off, the <dtml-with "_['sequence-item']"> is superfluous, the <dtml-in> tag automagically pushes sequence-item on the top of the namespace stack. Second, there is the python builtin function _.len() that you can use to determine the size of a sequence (untested):: <dtml-let sequence="whatever()"> <dtml-in sequence> <dtml-if "_.len(sequence) == 1"> one </dtml-in> </dtml-in> </dtml-let> The <dtml-let> is useful because it caches the possibly expensive whatever() operation into a 'local' variable. -Michel
Michel Pelletier wrote:
Second, there is the python builtin function _.len() that you can use to determine the size of a sequence (untested)::
<dtml-let sequence="whatever()"> <dtml-in sequence> <dtml-if "_.len(sequence) == 1"> one </dtml-in>
^^
</dtml-in> </dtml-let>
Oops. <dtml-let sequence="whatever()"> <dtml-in sequence> <dtml-if "_.len(sequence) == 1"> one </dtml-if> </dtml-in> </dtml-let> -Michel
participants (5)
-
Brad Clements -
Chimezie Ogbuji -
Evan Simpson -
fog@mixadlive.com -
Michel Pelletier