On Jul 15, 4:56 am, Seth <[email protected]> wrote:
> Hey guys,
>
> So I've been messing around with tw.forms a little bit and maybe I'm
> looking in the wrong places but I'm having a little bit of trouble
> finding docs on some of the more advanced use cases.
>
> The biggest thing I'm trying to figure out is how to return to the
> form after some custom validation in my "save" method. So I've got my
> "form" method that loads a template with the form and submits to the
@expose('cp.templates.template')
def reform(self, **kw):
tmpl_context.form = ReForm()
return dict(template='form', value=kw)
@validate(ReForm(), error_handler=reform)
def reformcheck(self, **kw):
flash('great success')
redirect('reform',kw)
That method will hand you dirty URLs and is not PCI DSS compliant.
However, you probably want to use a chained validator to do something
like this:
class PaymentSchema(Schema):
chained_validators = [CreditCardValidator('cctype','ccnum'),
CreditCardExpires('expmon','expyear'),
CreditCardSecurityCode('cctype','cvv'),
RunCharge
('cctype','ccnum','expmon','expyear','cvv','addr1']
class PaymentForm(TableForm):
action = 'makepayment'
submit_text = 'make my payment'
validator = PaymentSchema
Then write your own validator for RunCharge:
class RunCharge(FancyValidator):
def _to_python(self, value, state):
# do magic
if card.declined:
flash(_('card declined'))
raise Invalid(
_('sorry, your card was declined'),
value, state)
return value
If you are using 2.0.1, you might take a look at
http://trac.turbogears.org/ticket/2341
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---