Re: [Zope-dev] ZPatterns + Skinscript
Hi Steve, I did exactly (hopefully) as you sugested, but the dtml-method fails with: (I moved the SkinScript with first to the top) Error Type: KeyError Error Value: movie_link ... File /usr/local/Zope-2.2.0/lib/python/DocumentTemplate/DT_String.py, line 528, in __call__ (Object: testzclass) File /usr/local/Zope-2.2.0/lib/python/DocumentTemplate/DT_Let.py, line 147, in render (Object: theItem="getItem('anyOldThing')") File /usr/local/Zope-2.2.0/lib/python/DocumentTemplate/DT_With.py, line 146, in render (Object: theItem) KeyError: (see above) what's the best way to debug this ? On Mon, 30 Oct 2000, Steve Spicklemire wrote:
Hi Joachim,
Hmm.. I would start start really simple here, and then 'work up' to the sql query.... Create a default rack with the following SkinScript.
WITH ['a','b','c'] COMPUTE movie_link=RESULT[0],movie_title=RESULT[1], zeiten=RESULT[2]
Set the storage for this rack to be a DataSkin derived ZClass loaded by accessing attribute 'movie_link'. Then try the following method in the Specialist:
<dtml-var standard_html_header> <dtml-let theItem="getItem('anyOldThing')"> <dtml-with theItem> <dtml-var movie_link> <dtml-var movie_title> <dtml-var zeiten>
</dtml-with> </dtml-let> <dtml-var standard_html_footer>
If this does what you expect.. then you're getting close. Now change the ['a','b','c'] to be a call to your query:
WITH yourQuery(... parameters for your query... ) COMPUTE movie_link, movie_title... etc.
If you get the same errors in the first case.. then your problem has nothing to do with SQL.
-steve
"Joachim" == Joachim Schmitz <js@aixtraware.de> writes:
Joachim> On Mon, 30 Oct 2000, Steve Spicklemire wrote:
>> Hi Joachim, >> >> rackList just refers to the racks in the 'racks' tab of the >> Specialist. Do you have any racks defined for this Specialist? >> The rackList is managed magically with the plug-in-group stuff. >> Joachim> Yes that's what I found too, but it doesn't work, with Joachim> SQL-database and SkinScripts, the setup is described Joachim> below:
>> >>>>> "Joachim" == Joachim Schmitz <js@aixtraware.de> writes: >> Joachim> for debugging I inserted in Specialists.py in getItem: >> Joachim> return str(self.rackList) <-- inserted for rack in Joachim> self.rackList: item = rack.__of__(self).getItem(key) if Joachim> item is not None: return item >> Joachim> this alway returns an empty list, when calling it from Joachim> the dtml: >> Joachim> <dtml-var "getItem(_.int(609))"> returns "[]" >> Joachim> I tried to follow the magic how this rackList is setup, Joachim> but it is to much python-Zen for me. >> Joachim> On Sun, 29 Oct 2000, Joachim Schmitz wrote: >> >> On Sat, 28 Oct 2000, Phillip J. Eby wrote: >> >> >> >> > At 05:17 PM 10/28/00 +0200, Joachim Schmitz wrote: >> >> > > >> >> > >select e.event_id as event_id > >,e.zeiten as zeiten > >> >> >,v.firma as firma > >,v.tel as tel > >,e.movie_id as movie_id >> >> > >,m.movie_title as movie_title > >,m.movie_link as >> movie_link >> > >,m.movie_text as movie_text > >,e.datum_von as >> datum_von > >> >,e.datum_bis as datum_bis > >from event as e, >> veranstalter as >> v, movies as m > >where > >e.event_id = >> <dtml-sqlvar e_id >> type=int> > >and e.movie_id = m.movie_id >> and e.veran_id = >> v.veran_id > >order by m.movie_title >> >> > >> >> > Just out of curiosity, why do you have an "order by" >> clause, >> if this is > supposed to only return one row? If >> more than one >> item is returned by this > query, only the >> first will be used >> to supply data to your DataSkin. >> >> > >> >> that was just left over from an reused query-template, I >> forgot >> to take it out. >> >> >> >> > >> >> > >I also added a SkinScript method as a Data Plug-in in the >> >> defaultRack like > this >> >> > > >> >> > >WITH QUERY readEvents(e_id=self.event_id) COMPUTE >> >> zeiten,firma,tel > >,movie_id,movie_text,movie_link,movie_title >> >> > >,datum_von,datum_bis,zeiten >> >> > >> >> > Do you have some way of providing self with an "event_id" >> >> value? Keep in > mind that when DataSkins are created, they >> >> have only an "id" attribute, > nothing else. So unless you >> >> have an attribute provider that provides an > "event_id" >> value, >> this statement will fail. Perhaps what you actually >> mean > is: >> >> > >> >> > WITH QUERY readEvents(e_id=self.id) COMPUTE > event_id, > >> >> zeiten,firma,tel, > >> movie_id,movie_text,movie_link,movie_title, >> > >> datum_von,datum_bis,zeiten >> >> > >> >> > Notice that I'm passing self.id to readEvents, and that >> I've >> added event_id > to the list of attributes retrieved >> from the >> query. >> >> > >> >> how do I set "self.id" I tried in dtml-method in the >> >> event-specialist: There is a event_id 609 in the table: >> >> >> >> <dtml-var "getItem(_.int(609))"> returns none or <dtml-var >> >> "getItem(key=_.int(609))"> returns none >> >> >> >> >> >> > >> >> > >under the storage tab I selected for: >> >> > > >> >> > >Class to use for stored items: ZPatterns:DataSkin and >> >> > > >> >> > >Objects are: o stored persistently. > > x loaded by >> >> accessing attribute: event_id >> >> > >> >> > This will work fine, if you use the revised SkinScript >> above. >> You will > probably want to create a ZClass subclass >> of >> DataSkin at some point to use > instead, so that you can >> define >> permissions, methods, and so on for your > Event >> objects. >> >> > >> >> > >> >>
Mit freundlichen Grüßen Joachim Schmitz AixtraWare, Ing. Büro für Internetanwendungen Hüsgenstr. 33a, D-52457 Aldenhoven Telefon: +49-2464-8851, FAX: +49-2464-905163 _______________________________________________ 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 )
Hi Joachim, Hmm... I just put all the code in myself... to be *really* sure, and it does work. What do you see for 'current attribute handling' in the Data PlugIns tab of the default rack? I would try to simplify. Take out all the skin script execpt for the one line. -steve
"JS" == Joachim Schmitz <js@aixtraware.de> writes:
JS> Hi Steve, JS> I did exactly (hopefully) as you sugested, but the dtml-method JS> fails with: (I moved the SkinScript with first to the top) JS> Error Type: KeyError Error Value: movie_link JS> ... JS> File JS> /usr/local/Zope-2.2.0/lib/python/DocumentTemplate/DT_String.py, JS> line 528, in __call__ (Object: testzclass) File JS> /usr/local/Zope-2.2.0/lib/python/DocumentTemplate/DT_Let.py, JS> line 147, in render (Object: theItem="getItem('anyOldThing')") JS> File JS> /usr/local/Zope-2.2.0/lib/python/DocumentTemplate/DT_With.py, JS> line 146, in render (Object: theItem) KeyError: (see above) JS> what's the best way to debug this ? JS> On Mon, 30 Oct 2000, Steve Spicklemire wrote: >> Hi Joachim, >> >> Hmm.. I would start start really simple here, and then 'work >> up' to the sql query.... Create a default rack with the >> following SkinScript. >>
Hi Steve, somehow I got the first part working, I don´t exactly remember, what was wrong, but it worked anyhow. my setup was: SkinScript method in defaultRack, Data-Skin: WITH ['a','b'] COMPUTE event_id=RESULT[0],datum_von=RESULT[1] and under Storage I specified my ZClass and loaded accessing by event_id dtml-method: <dtml-let theItem="getItem('anyOldThing')"> <dtml-with theItem> <dtml-var event_id> <dtml-var datum_von> </dtml-with> </dtml-let> that finally displayed "a b" then I made a sql-method "getevent" with no arguments and a query-template: select event_id,datum_von from event where event_id = 609 tested it and it returns exactly one row. I changed the SkinScript to: WITH QUERY getevent() COMPUTE event_id ,datum_von that does not work, I get an key error: event_id but finally last try: WITH QUERY getevent() COMPUTE event_id=event_id ,datum_von=datum_von that worked, so there seams to be a little bug. mit freundlichen Grüßen Joachim Schmitz AixtraWare, Ing. Büro für Internetanwendungen Hüsgenstr. 33a, D-52457 Aldenhoven Telefon: +49-2464-8851, FAX: +49-2464-905163
OK I think I found the problem(s): *** Expressions.py 2000/10/18 23:11:55 1.1.1.3 --- Expressions.py 2000/10/31 14:14:09 *************** *** 133,139 **** def eval(self,mapping): """Return the result of looking up/calling the name from 'mapping'. If the object was created with 'call==1', call it before returning it.""" ! return md.getitem(self.name,self.call) del Eval, expr_globals, TemplateDict, Base, ComputedAttribute --- 133,139 ---- def eval(self,mapping): """Return the result of looking up/calling the name from 'mapping'. If the object was created with 'call==1', call it before returning it.""" ! return mapping.getitem(self.name,self.call) del Eval, expr_globals, TemplateDict, Base, ComputedAttribute *** SkinScript/Compiler.py 2000/10/18 23:11:56 1.1.1.4 --- SkinScript/Compiler.py 2000/10/31 14:12:09 *************** *** 168,174 **** class Compute(AST): type = 'COMPUTE' ! def __init__(self,*args,**args): self._kids=list(args)+kw.items() class Trigger(Compute): --- 168,174 ---- class Compute(AST): type = 'COMPUTE' ! def __init__(self,*args,**kw): self._kids=list(args)+kw.items() class Trigger(Compute): Try these patches and see if it works... -steve
At 09:16 AM 10/31/00 -0500, Steve Spicklemire wrote:
OK I think I found the problem(s):
*** Expressions.py 2000/10/18 23:11:55 1.1.1.3 --- Expressions.py 2000/10/31 14:14:09 *************** *** 133,139 **** def eval(self,mapping): """Return the result of looking up/calling the name from 'mapping'. If the object was created with 'call==1', call it before returning it.""" ! return md.getitem(self.name,self.call)
del Eval, expr_globals, TemplateDict, Base, ComputedAttribute --- 133,139 ---- def eval(self,mapping): """Return the result of looking up/calling the name from 'mapping'. If the object was created with 'call==1', call it before returning it.""" ! return mapping.getitem(self.name,self.call)
Yep, that's it. Looks like I screwed up while doing documentation and cleanup on the file just before release (I was changing parameter names for consistency in the internal docs). :( I'll get this fixed today, and see about releasing an updated beta that also fixes the missing "help" directory for PlugIns.
I've released new 0.4.3 beta 2 versions of ZPatterns and PlugIns to fix the minor bugs reported to date in beta 1. Specifically, the PlugIns package now contains a "help" directory, and the problem with "name" shorthand in SkinScript has been fixed as well. They can be found in the usual places. (By the way, if you haven't yet seen the latest zope.org download page, it's really cool... go to http://www.zope.org/Products/ and check it out.)
Hi Steve, that did it, many thanks, how did you debug this ? By the way, it only work if specify a DataSkin derived ZClass under the Storage tab. it solved also the problem with the following setup, which didn't work before applying the patch, with an setup like this: SkinScript method: WITH QUERY readEvents(e_id=self.id) COMPUTE event_id=event_id,zeiten=zeiten,firma=firma ,tel=tel,movie_id=movie_id,movie_text=movie_text ,movie_link=movie_link,movie_title ,datum_von=datum_von,datum_bis=datum_bis SQL-method readEvents parameter: e_id:int Querytemplate: select e.event_id as event_id ,e.zeiten as zeiten ,v.firma as firma ,v.tel as tel ,e.movie_id as movie_id ,m.movie_title as movie_title ,m.movie_link as movie_link ,m.movie_text as movie_text ,e.datum_von as datum_von ,e.datum_bis as datum_bis from event as e, veranstalter as v, movies as m where e.event_id = <dtml-sqlvar e_id type=int> and e.movie_id = m.movie_id and e.veran_id = v.veran_id dtml-method: <dtml-in getcurrentEventIDs> <dtml-let theItem="getItem(key=_.int(event_id))"> <dtml-var theItem> <dtml-if "_.hasattr(theItem,'movie_title')"> <dtml-with theItem> <tr> <td> <a href=<dtml-var event_id>><dtml-var movie_title></a> </td> <td> <dtml-var zeiten> </td> <td> <dtml-var firma> </td> </tr> </dtml-with theItem> </dtml-if theItem> </dtml-let theItem="getItem(_.int(_['sequence-item']))"> </dtml-in getcurrentEventIDs> On Tue, 31 Oct 2000, Steve Spicklemire wrote:
OK I think I found the problem(s):
*** Expressions.py 2000/10/18 23:11:55 1.1.1.3 --- Expressions.py 2000/10/31 14:14:09 *************** *** 133,139 **** def eval(self,mapping): """Return the result of looking up/calling the name from 'mapping'. If the object was created with 'call==1', call it before returning it.""" ! return md.getitem(self.name,self.call)
del Eval, expr_globals, TemplateDict, Base, ComputedAttribute --- 133,139 ---- def eval(self,mapping): """Return the result of looking up/calling the name from 'mapping'. If the object was created with 'call==1', call it before returning it.""" ! return mapping.getitem(self.name,self.call)
del Eval, expr_globals, TemplateDict, Base, ComputedAttribute
*** SkinScript/Compiler.py 2000/10/18 23:11:56 1.1.1.4 --- SkinScript/Compiler.py 2000/10/31 14:12:09 *************** *** 168,174 ****
class Compute(AST): type = 'COMPUTE' ! def __init__(self,*args,**args): self._kids=list(args)+kw.items()
class Trigger(Compute): --- 168,174 ----
class Compute(AST): type = 'COMPUTE' ! def __init__(self,*args,**kw): self._kids=list(args)+kw.items()
class Trigger(Compute):
Try these patches and see if it works...
-steve
Mit freundlichen Grüßen Joachim Schmitz AixtraWare, Ing. Büro für Internetanwendungen Hüsgenstr. 33a, D-52457 Aldenhoven Telefon: +49-2464-8851, FAX: +49-2464-905163
Hi Joachim,
"Joachim" == Joachim Schmitz <js@aixtraware.de> writes:
Joachim> Hi Steve, Joachim> that did it, many thanks, how did you debug this ? The debugger is your friend. ;-). Seriously I'd be lost without it: http://www.zope.org/Members/michel/HowTos/TheDebuggerIsYourFriend Joachim> By the way, it only work if specify a DataSkin derived ZClass Joachim> under the Storage tab. Yes... did you attempt to use a 'pure' DataSkin? -steve
Hi Steve, On Tue, 31 Oct 2000, Steve Spicklemire wrote:
Joachim> By the way, it only work if specify a DataSkin derived ZClass Joachim> under the Storage tab.
Yes... did you attempt to use a 'pure' DataSkin?
after your advise not to use a 'pure' DataSkin, I did all the testing with a DataSkin derived ZClass, when that was working, I tried the 'pure' DataSkin and it didn't work. Mit freundlichen Grüßen Joachim Schmitz AixtraWare, Ing. Büro für Internetanwendungen Hüsgenstr. 33a, D-52457 Aldenhoven Telefon: +49-2464-8851, FAX: +49-2464-905163
At 04:42 PM 10/31/00 +0100, Joachim Schmitz wrote:
Hi Steve,
On Tue, 31 Oct 2000, Steve Spicklemire wrote:
Joachim> By the way, it only work if specify a DataSkin derived ZClass Joachim> under the Storage tab.
Yes... did you attempt to use a 'pure' DataSkin?
after your advise not to use a 'pure' DataSkin, I did all the testing with a DataSkin derived ZClass, when that was working, I tried the 'pure' DataSkin and it didn't work.
DataSkin is strictly a mix-in class. Sometimes I forget to remind people of that, and sometimes I even forget it myself. :(
"Phillip J. Eby" wrote:
DataSkin is strictly a mix-in class. Sometimes I forget to remind people of that, and sometimes I even forget it myself. :(
DataskinAddons provides a nice DataSkin-derived class for debugging purposes - it has a debug() method that prints out __dict__, and lets you getattr attributes through the web as well. So you can use that for testing purposes. http://www.zope.org/Members/stevea/DataSkinAddons -- Itamar S.T. itamar@maxnm.com Fingerprint = D365 7BE8 B81E 2B18 6534 025E D0E7 92DB E441 411C
At 12:32 PM 10/31/00 +0100, Joachim Schmitz wrote:
I changed the SkinScript to:
WITH QUERY getevent() COMPUTE event_id ,datum_von
that does not work, I get an key error: event_id
but finally last try:
WITH QUERY getevent() COMPUTE event_id=event_id ,datum_von=datum_von
that worked, so there seams to be a little bug.
Weird. I'll check this out and see if I can reproduce it. Thanks.
participants (4)
-
Itamar Shtull-Trauring -
Joachim Schmitz -
Phillip J. Eby -
Steve Spicklemire