I found an interesting github project demonstrating how to use deform and 
colander:

https://github.com/ericrasmussen/deform_retail_demo

I've tried to integrate it with a project of mine and I'm encountering an 
issue here: 
https://github.com/ericrasmussen/deform_retail_demo/blob/master/deformretail/templates/login.mako#L92

<%def name="render_error(error)">
    <%doc>
      Note: we use our own translate filter here to handle deform error 
messages
      with the TranslationString type (they require additional processing
      before rendering).
    </%doc>

    ## include any error messages if present
    % if error:
        % for e in error.messages():
            <small>${e|n,translate}</small>
        % endfor
    % endif
</%def>

The runtime exception is:

  File 
"/Users/Shared/webapp/deformport_env/deformport/deformport/templates/auth/login.mako",
 
line 92, in render_render_error
    <small>${e|n,translate}</small>
*TypeError: 'Undefined' object is not callable*

It's doing something with some class called TranslationString but the 
incoming "e" object is null/undefined

Looking at the calling code: 
https://github.com/ericrasmussen/deform_retail_demo/blob/master/deformretail/views.py#L138

    if submitted:
        # try to validate the form and save the user/redirect on success
        try:
            appstruct = form.validate(controls)
            request.session.flash("You are now logged in! (not really)")
            location = request.route_url('login')
            return HTTPFound(location=location)
        # if the form failed, return it with errors and don't save changes
        except deform.ValidationFailure, e:
            return {'form': form}
    return {'form': form}

I notice the exception is returning the same form object as if the 
submission was successful? Anyway, I found another page on how to use 
deform: http://blog.vmfarms.com/2011/10/how-to-use-deform-in-django.html

And here, he returns e.render():

            except ValidationFailure, e:
                # The exception contains a reference to the form object
                rendered = e.render()

When I try to print out e.render() on my own, I get some HTML:

(Pdb) p e.render()
u'<form\n  id="deform"\n  method="POST"\n  enctype="multipart/form-data"\n 
 accept-charset="utf-8" class="deform"\n  >\n\n  <fieldset 
class="deformFormFieldset">\n\n    \n\n    <input type="hidden" 
name="_charset_" />\n    <input type="hidden" name="__formid__" 
value="deform"/>\n\n    <div class="alert alert-danger">\n      <div 
class="errorMsgLbl"\n        >There was a problem with your 
submission</div>\n      <p class="errorMsg"></p>\n    </div>\n\n    \n\n   
 <div\n     class="form-group has-error item-email"\n     title="Your 
email"\n     id="item-deformField1">\n\n  <label for="deformField1"\n       
  class="control-label required"\n         id="req-deformField1"\n         
>\n    Email\n  </label>\n\n  \n    <input type="text" name="email" 
value="afeawef"\n           id="deformField1" class=" form-control "/>\n 
 \n\n  <p class="help-block" id="error-deformField1">Invalid email 
address</p>\n\n  <p\n     class="help-block" >\n    Your email\n 
 </p>\n</div>\n\n    <div\n     class="form-group has-error "\n     
title="Your password"\n     id="item-deformField2">\n\n  <label 
for="deformField2"\n         class="control-label required"\n         
id="req-deformField2"\n         >\n    Password\n  </label>\n\n  \n   
 <input \n    type="password" \n    name="password" \n    value=""\n   
 id="deformField2" class=" form-control "/>\n  \n\n  <p class="help-block" 
id="error-deformField2">Required</p>\n\n  <p\n     class="help-block" >\n   
 Your password\n  </p>\n</div>\n\n\n    <div class="form-group">\n      \n 
   </div>\n\n  </fieldset>\n\n  \n\n</form>\n'


Where's the bug? Is it how 
        except deform.ValidationFailure, e:
            return {'form': form}

is trying to return a valid form instead of a error object? Or perhaps 
ericarassmussen is handling the error(s) in a non-standard way? Or is it 
how the login.mako is trying to parse a non-existent TranslationString? Or 
is it something I'm missing in my usage? Any suggestions on how to fix this?

regards,
Michael


-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to