Dropdown fields not functional with TW2

69 views
Skip to first unread message

Juraj Variny

unread,
Aug 20, 2012, 1:05:14 PM8/20/12
to sp...@googlegroups.com
Hi, I am trying to follow Form Tutorial http://sprox.org/tutorials/form.html , while using Turbogears 2.2 with Sprox 0.8 / ToscaWidgets2. I can't get any dropdown field working. In the log I get (a bit garbled) message:

site-packages/sprox-0.8-py2.7.egg/sprox/sa/provider.py:195: UserWarning: No dropdown options will be shown for <class 'x.model.trade.Order'>.  Try passing the session into the initialization of your form base object so that this sprocket can have values in the drop downs
  'can have values in the drop downs'%entity)

and my custom _my_update_params method is never called.

Regards,
Juraj

Juraj Variny

unread,
Aug 20, 2012, 4:21:23 PM8/20/12
to sp...@googlegroups.com
The error from the log was fixed by adding DBSession parameter to form constructor. However, the dropbox still contained only numeric database IDs, not the data I wanted and _my_update_params() is still never called. The code looks like:

class MpsicField(PropertySingleSelectField):
    def _my_update_params(self, d, nullable=False):
        items = DBSession.query(Item).filter(Item.isopen==True).all()
        options = [(item.item_id, item.getDisplayName())
                            for item in items]
        d['options']= options
        return d

class OrderForm(AddRecordForm):
    __model__=Order
    __omit_fields__ = ['dateCreated', 'dateExpires','tx_id','status','address','currency','user','trades']
    __dropdown_field_names__ = ['account']
    __field_order__ =['account']
    account = MpsicField

I had to overload prepare() method to get my data into the dropbox.
Another problem: If I want the dropbox to be custom field (not found in Order model), it gets completely ignored and nothing is rendered. I tried this:

class OrderForm(AddRecordForm):
    __model__=Order
    __omit_fields__ = ['dateCreated', 'dateExpires','tx_id','status','address','currency','user','trades','account']
    __dropdown_field_names__ = ['item']
    __field_order__ =['item']
    item = MpsicField

Dňa pondelok, 20. augusta 2012 19:05:14 UTC+2 Juraj Variny napísal(-a):

Alessandro Molina

unread,
Aug 22, 2012, 6:54:43 AM8/22/12
to sp...@googlegroups.com
TW2 provides the prepare method, so _my_update_params is not required anymore.
Just override the prepare method.

About the dropdown_field_names, if I'm not wrong, they specify the
names used by the parent when selecting the children, so it should be
placed inside the parent, not inside the child.
> --
> You received this message because you are subscribed to the Google Groups
> "sprox" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sprox/-/C6p0Dc214U8J.
>
> To post to this group, send email to sp...@googlegroups.com.
> To unsubscribe from this group, send email to
> sprox+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sprox?hl=en.
Reply all
Reply to author
Forward
0 new messages