Re: construct id from multiple fields

classic Classic list List threaded Threaded
2 messages Options
Dave Turvene Dave Turvene
Reply | Threaded
Open this post in threaded view
|

Re: construct id from multiple fields

Raphael Ritz <r.ritz@...> writes:

>
> Dave Turvene wrote:
> [..]
> > Yes, by combining lastname and firstname into a single AT
field, one can achieve
> > this.  I refer to the your Addressbook example a lot.
> >
> > I think the question remains of how to create an id from
multiple AT fields.
> >
> > One solution is to pull this information directly from the
validated form input
> > in an overloaded post_validate method via the REQUEST
dictionary. A terse

> > example is:
> >   ln = self.REQUEST.get('lastname')
> >   co = self.REQUEST.get('company')
> >   self.setId(ln+co)
> >
> > Are there better ways to do this?
>
> I wouldn't say better but an alternative is to use a
> widget's 'process_form' method. E.g., provide your own
> IdWidget class (by subclassing the existing one) and
> override 'process_form' to generate the id from the
> values of arbitrary other fields from that form.
> The values themselves can easily be obtained here as
> the entire 'form' dictionary from the REQUEST is passed
> to 'process_form'.
>
> HTH,
>
> Raphael

This solution appeals to me because it isolates the 'id'
synthesis behavior to something related to the 'id' field,
rather than a general post_validate method. So, I coded
it up in an IdWidget subclass and it worked.

*BUT*, I stepped through the code using PDB and found a
disturbing thread within ATs.  The widget.process_form
method is called at least four times
on every submit:
* during field validation
* during an automatically attached EmptyValidator method
Then both again when the validate_integrity page template
is invoked after successful validation.

Okay, technically I guess this is not a bug, but doing
the same thing four times on every field every time I
submit a form, seems wasteful. I'll post a query to the
devel list when I understand it better.

Dave




-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users
Raphael Ritz Raphael Ritz
Reply | Threaded
Open this post in threaded view
|

Re: construct id from multiple fields

Dave Turvene wrote:
[..]
> This solution appeals to me because it isolates the 'id'
> synthesis behavior to something related to the 'id' field,
> rather than a general post_validate method. So, I coded
> it up in an IdWidget subclass and it worked.

Great ;-)

> *BUT*, I stepped through the code using PDB and found a
> disturbing thread within ATs.  The widget.process_form
> method is called at least four times
> on every submit:
> * during field validation
> * during an automatically attached EmptyValidator method
> Then both again when the validate_integrity page template
> is invoked after successful validation.

Yeah, and there are even more things called several times
(e.g., reindex) :-(

> Okay, technically I guess this is not a bug, but doing
> the same thing four times on every field every time I
> submit a form, seems wasteful. I'll post a query to the
> devel list when I understand it better.

If your operation is expensive you could set a flag
within the form dict indicating that the value was
updated already but this is of course only a poor
workaround.

Generally speaking, I think most AT core developers
don't care that much about improving the current AT
version(s) but rather focus on implementing something
AT-like for Zope 3 from scratch (but hopefully backwards
compatible - or at least including a migration path).

Raphael


>
> Dave
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Archetypes-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/archetypes-users