Thanks for the tips, Crusty!

I took your advice and changed the field
names in my models to be more specific
just in case. I felt a bit uncomfortable with
those field names, as I've had weird reserved
words bite me in the past. I "think" that's
why I was getting that `str object` stuff
in the field value. On top of that I had to
tweak the template snippet. I'd put:

 value='values'

...instead of...

 value=values

Genshi just quietly blew me off, taking what I gave
it and went on with it's life ignoring what I wanted.
Genchi's a lot like an ex girlfriend of mine. I just
had to learn to ask correctly. Huh, code as a metaphor
for social interaction. Go figure.


Thanks again, Crusty!


In case anyone else runs into a similar problem,
here's a slightly cut-down version of what I have
that works in a canned controller:

##########################################################
import datetime
from sprox.formbase import AddRecordForm

# ddate will be smarter later
ddate = datetime.datetime(2009, 10, 31)
prod = DBSession.query(Product).filter_by(
           display_date = ddate).one()

# place_order_form
class PlaceOrder(AddRecordForm):
 __model__ = SalesOrder
 __hide_fields__ = ['order_id', 'product_id',]
place_order_form = PlaceOrder(DBSession)

class RootController(BaseController):
 """other stuff between here and placeorder"""
 #placeorder
 @expose('tgdeal.templates.placeorder')
 def placeorder(self):
   """Displays the placeorder form using
   the product for 'ddate'."""
   tmpl_context.place_order_form = place_order_form
   values = {
     'product_id' : prod.prod_id,
     'order_title': prod.prod_title,
     'condition'  : prod.condition,
     'options'    : prod.options,
     'price'      : prod.price,
     'shipping'   : prod.shipping,
     }
   return dict(product = prod,
               values = values,
               page='placeorder')

 #place_order_form
 @expose()
 @validate(
   form=place_order_form,
   error_handler=placeorder,
   )


## placeorder.html  template
########################################################

   ${tmpl_context.place_order_form(
       action = 'place_banana_order',
       value=values
       )}





On Oct 28, 7:38 am, Crusty <[email protected]> wrote:
> Hi There
>
> the "error" kinda says it all.
>
> "<built-in method title of str object at 0x7fbe302ae4e0>"
>
> That means, that "product" in your context is not the name of a
> table/row of a table in your database, but its a string object and
> youre displaying its title-method's string representation.
>
> Any python string has a method "title", so you can do this:
>
> >>> somestring = "hey there"
> >>> somestring.title()
> 'Hey There'
>
> >>> somestring.title
>
> <built-in method title of str object at 0x00B60958>
>
>
>
> Basically you tell python to display infos about a method, instead of
> calling it. Seems that in your code, product.title() would actually
> work, which means the error is buried elsewhere. Your product variable
> holds a string, which it shouldnt.
>
> I dont really know why it is acting like this, because your
> DBSession.query looks fine to me, which is a little creepy to me,
> because it shouldnt be doing this. If i were you, i'd try what happens
> when you change the name of the column to something other than title,
> but actually this has to work with title.
>
> I am confused because calling "type(product)" is supposed to output
> something like an SQLAlchemyMappedClass but in your class its type
> string.
>
> Hope that helps a little bit even if I cant spot the real error right now.
>
> Greets,
>
> Tom
>
> On Tue, Oct 27, 2009 at 1:13 AM, KurtB <[email protected]> wrote:
>
> > Hi guys,
>
> > I'm creating a really basic ordering system and
> > am trying to use to use sprox to create an order form
> > using the 'SalesOrder' model, *and* I want to
> > fill some fields using results from a query
> > on the 'Products' model.
>
> > I'm attempting to pass product_id and title
> > values in the controller. When rendering
> > the template the product field gets nothing, and
> > the title field renders:
> > "<built-in method title of str object at 0x7fbe302ae4e0>"
>
> > I'm sure I'm missing something.
>
> > I looked at EditFormFiller but it's not clear to me
> > how to wedge it in. I'd appreciate any suggestions
> > on either how to get this working or how you think
> > I should better approach this. I'm not averse
> > to throwing it all aout and coming at it from
> > another angle.
>
> > Here's what I'm trying (obviously not working):
>
> > #From root.py
> > #######################################
> > # place_order_form
> > class PlaceOrder(AddRecordForm):
> >  __model__ = SalesOrder
> >  __omit_fields__ = ['id', 'purch_datetime', 'display_date']
>
> > place_order_form = PlaceOrder(DBSession)
>
> > class RootController(BaseController):
> >  """There's other stuff between here and placeorder."""
> >  #placeorder
> > �...@expose('tgdeal.templates.placeorder')
> >  def placeorder(self):
> >    """Displays the placeorder form using
> >    the product for 'cdate'."""
> >    cdate = datetime.datetime(2009, 10, 31)
> >    product = DBSession.query(Product).filter_by(
> >      display_date = cdate).one()
> >    tmpl_context.place_order_form = place_order_form
> >    values = { 'product_id':product.id, 'title': product.title }
> >    return dict(product = product,
> >                values = values,
> >                page='placeorder')
>
> >  #place_order_form
> > �...@expose()
> > �...@validate(
> >    form=place_order_form,
> >    error_handler=placeorder,
> >    )
>
> > # from placeorder.html
> > ################################################################
> >    <h2>Place Your Order for - ${product.title}</h2>
> >    ${tmpl_context.place_order_form(
> >        action = 'place_order',
> >        value='values',
> >        )}
>
> > ################################################################
>
> > This is my first TG project, and I'm just
> > figuring most of this out. A judicious
> > application of the clue bat would be most
> > appreciated.
>
> > Thanks,
>
> >  -KurtB
>
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to