[Twisted-web] two questions abt nevow

Little mordaha at gmail.com
Mon Apr 25 00:41:32 MDT 2005

I'm newbie now in Model-View-Controller pattern, from perl/php it's
difficult to think in DOM-model :)

So i have two questions, answers on which i can't google:

Q1: I have a page. At page i have 2 elements. The values(data->render)
of both elements must calculated from single request to the Database.
Simple, it's looks like:

[total: 100 rows]
[table-like result]

So, in the template i have 2 elements, with 2 data_functions:

<div n:data="totals"> - ???
<div n:data="result"> - select * from db ... where ...

But "totals" i will knew only after "result" makes request to DB

So, i must to make "select * " in data_totals(), store data in
self.var, and take it from self.var in data_result() function.
This way is not perfect to me, coz if request to DB failed - it's very
difficult to pass message about error into "request" function. May be
not difficult but not clear. :(

Another way is to use "fake" tag before "totals" and "request", like this:

<n:invisible data="real_request">
<div n:data="fetch_totals">
<div n:data="fetch_data">

Where data_real_request() doing "select *" and stores result (or error
msg) in self.var
It's not perfect too, coz we have program logic layer in template,
and, again, it's not clear to programmer.

Third way is to use 2 requests to DB - the worst way, coz requests are
long in time.

Is there another, perfect, clear way to produce such pages in nevow?

Q2: About formless. How can i use my own check of form element's value?
For example, i have "e-mail" field in form. And i wanna check char '@'
existense in it.
When my code falls into anotate.autocallable() function in
FormImplementation class - i have only values of form elements.
If e-mail value doesn't have "@"-char, how can i stop submitting and
show error near "e-mail" field in form when RenderForm() called?

More information about the Twisted-web mailing list