I want to use one controller method( "save") for both creating and
updating a record. I have two methods for displaying a form: "add" and
"edit". The problem is that the form for adding and editing are
slightly different (different validator in this case) . I can
instantiate two forms, but I can pass only one instance to @validate
decorator of "save" method.
Are separate methods for creating and updating record the only way out?
Appreciate any hints!
Thanks
Ksenia
I'm facing a similar problem right now [1]. The solution I found is creating my
own decorator for validation. It receives a callable which generates the schema
for validation. I could send you some snippets if you need.
But I believe in your case it would be better to use separate methods. What is
the point of using single method? Code reuse? You could achieve it by extracting
common parts into separate reusable methods.
[1] http://groups.google.com/group/turbogears/browse_frm/thread/0f57bc6b3dc3caa5/
--
Timur Izhbulatov
OILspace, 26 Leninskaya sloboda, bld. 2, 2nd floor, 115280 Moscow, Russia
P:+7 495 105 7245 + ext.205 F:+7 495 105 7246 E:TimurIz...@oilspace.com
Building Successful Supply Chains - One Solution At A Time.
www.oilspace.com
1. You can pass a callable to
@turbogears.validate(form=...)
that would return appropriate form. Of course, to select appropriate
form you need info from a form submitted which is not available from a
callable directly. Though you may check HTTP referer header.
2. You can validate inside your controller's method. Not as pretty but
it works.
Max.
thanks for the tips,
On 9/8/06, Timur Izhbulatov <ti...@oilspace.com> wrote:
> I'm facing a similar problem right now [1]. The solution I found is creating my
> own decorator for validation. It receives a callable which generates the schema
> for validation. I could send you some snippets if you need.
Thanks, I'd like to see that! Or maybe you can put your code on the wiki?
>
> But I believe in your case it would be better to use separate methods. What is
> the point of using single method? Code reuse? You could achieve it by extracting
> common parts into separate reusable methods.
>
You are right i can do that. For this particular case it's more a
habbit of me for the /add/edit/save url pattern :)
On 9/8/06, Max Ischenko <isch...@gmail.com> wrote:
>
>
> Two ideas:
>
> 1. You can pass a callable to
> @turbogears.validate(form=...)
> that would return appropriate form. Of course, to select appropriate
> form you need info from a form submitted which is not available from a
> callable directly. Though you may check HTTP referer header.
I've noticed that @validate accepts a callable, but didnt think about
using referer! Good one, thanks.
>
> 2. You can validate inside your controller's method. Not as pretty but
> it works.
>
True, but this is the thing I like the most in TG - widgets with
validators separated from controller code :)
thanks,
Ksenia.
You mean http://trac.turbogears.org/turbogears/wiki/?
I could do this on Monday. But you only need your own @validate for something
really special.
What about me, I've found the way to get rid of my own decorator
(http://groups.google.com/group/turbogears/tree/browse_frm/thread/0f57bc6b3dc3caa5/358a92ca7d83ecfe?rnum=1&_done=%2Fgroup%2Fturbogears%2Fbrowse_frm%2Fthread%2F0f57bc6b3dc3caa5%2F%3F#doc_0829c3fb0ecfc6fe)
OK. Here is the summary:
http://trac.turbogears.org/turbogears/wiki/DynamicValidation
> OK. Here is the summary:
> http://trac.turbogears.org/turbogears/wiki/DynamicValidation
Cool. Though overly complicated to my own taste. Hopefully TG 1.1/2.0
will make implementing dynamic validation a bit easier.
--
Max Ischenko
http://www.developers.org.ua -- Ukranian software developers community
> OK. Here is the summary:
> http://trac.turbogears.org/turbogears/wiki/DynamicValidation
Cool. Though overly complicated to my own taste. Hopefully TG 1.1/2.0
will make implementing dynamic validation a bit easier.
--
Max Ischenko
http://www.developers.org.ua -- Ukrainian software developers community
Yeah, kind of. I couldn't find a simpler way. And the task itself is rather
complex too so I took the tradeoff between complexity and flexibility.
> Hopefully TG 1.1/2.0
> will make implementing dynamic validation a bit easier.
I can't make any assumptions on this, my imagination refuses to work =)
Widgets look good as general approach for me but still far from perfection when
it comes to form rendering, and they are tightly coupled with Kid.