Hi,

This is my first attempt at a pyramid app, and I could sure use some help. 
 I am trying to add records to a database table.  I can enter values into 
the fields specified in the views schema, but when I enter the last field I 
get an error:

AttributeError: 'unicode' object has no attribute 'get'

 - Expression: "
            ${form.csrf_token()}

            ${form.errorlist('seq')}
            ${form.label('seq', 'Seq:')}
            ${form.text('seq')}
            "

Oddly, the error message shows the first field.  And no data is committed 
to the database table.  Here is the source for my views.py:

import formencode
from operator import itemgetter
from pyramid.response import Response
from pyramid.view import view_config
from pyramid_simpleform import Form
from pyramid_simpleform.renderers import FormRenderer
from pyramid.renderers import render
from sqlalchemy.exc import DBAPIError

from .models import (
    DBSession,
    MyModel,
    )

class AddTreeSchema(formencode.Schema):
    allow_extra_fields = False
    seq     = formencode.validators.Int(not_empty=True)
    dbh     = formencode.validators.Int(not_empty=False)
    merch   = formencode.validators.Int(not_empty=False)
    species = formencode.validators.String(not_empty=True)

@view_config(permission='post',route_name='tree_add', 
             renderer='templates/tree_add.pt')

def tree_add(request):
    target = request.params.get('target')
    session = DBSession()
    if target:
        target = Trees.get_by_id(target, with_joinedload=False)
        if not target:
            return {} 

    form = Form(request, schema=AddTreeSchema)

    if 'form.submitted' in request.POST and form.validate():
        session = DBSession()
        tree = Tree(
            seq  =form.data['seq'],
            dbh  =form.data['dbh'],
            merch=form.data['merch'],
            species=form.data['species']
        )
        session.add(tree)

        headers = remember(request, seq)
        
    return {
        'form': FormRenderer(form),
    }

Here is the template "tree_add.pt":


<html metal:use-macro="load:global_template.pt">
   <div metal:fill-slot="content">
      <h1>tree_add</h1>

<tal:block metal:fill-slot="content">
    <div class="instructions">
        <p>You are adding a tree</p>
    </div>
        <p>Please submit your tree.</p>
    ${form.begin(request.route_url('tree_add'), id='tree_add_form')}
        <fieldset>
            ${form.csrf_token()}

            ${form.errorlist('seq')}
            ${form.label('seq', 'Seq:')}
            ${form.text('seq')}
            <br />
            ${form.errorlist('dbh')}
            ${form.label('dbh', 'DBH:')}
            ${form.text('dbh')}
            <br />
            ${form.errorlist('merch')}
            ${form.label('merch', 'Merch:')}
            ${form.text('merch')}
            <br />
            ${form.errorlist('species')}
            ${form.label('species', 'Species:')}
            ${form.text('species')}
            <br />
            ${form.submit('form.submitted','tree_add',class_='submit')}
        </fieldset>
    ${form.end()}
</tal:block>
</html>

I am surely missing something.  Thanks much for any help!

Tom 


-- 
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