Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #362 (closed enhancement: fixed)

Opened 13 years ago

Last modified 12 years ago

[PATCH] Add foreign key handler to formmaker

Reported by: randall@… Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TG Widgets Version:
Severity: normal Keywords:
Cc:

Description

Allow formmaker to create a SelectField? widget for the foreign key of an SQLObject class.

@formmaker.column_widget.when("isinstance(column, SOKeyCol)")
def column_widget_fk_col(column):
    """Return a SelectField for a Foreign Key with the form_option_value attribute"""
    parms = formmaker.column_parms(column)
    fk_class_name = column.foreignKey
    fk_class = classregistry.findClass(fk_class_name)
    fk_class_data = fk_class.select()
    if hasattr(fk_class, 'form_option_value'):
        options = [[rset.id, rset.form_option_value] for rset in
fk_class_data]
        return_widget = widgets.SelectField(validator=None, options=options,
                                            **parms)
    else:
        return_widget =  widgets.TextField(validator=None, **parms)
    # For some reason, if I don't do this, I get stuck in a transaction.
    hub.commit()
    return return_widget

Attachments

foreignkey.patch Download (5.7 KB) - added by ksenia 13 years ago.
foreignkey.2.patch Download (5.0 KB) - added by ksenia 13 years ago.
ignore the previous file please, it contains non-related code

Change History

comment:1 Changed 13 years ago by anonymous

  • Milestone set to 0.9

comment:2 Changed 13 years ago by kevin

  • Summary changed from Add foreign key handler to formmaker to [PATCH] Add foreign key handler to formmaker

comment:3 Changed 13 years ago by kevin

#334 has an alternative form

comment:4 Changed 13 years ago by kevin

  • Summary changed from [PATCH] Add foreign key handler to formmaker to Add foreign key handler to formmaker

My preference between this and #334 is this one because #334 requires you to set which column to use for each table that has that foreign key.

I'm not completely sold on this patch, though. Here are my thoughts:

  • in order to vary with each item, form_option_value would have to be a property. If it has to be a property, it may as well be a callable.
  • I don't like mixing model and view as a general rule, and I think there is actually a more common concept we can use here than "form_option_value". Basically, the value returned should be whatever a human being would use to identify the row. Perhaps we should just use str()?

comment:5 Changed 13 years ago by kevin

oh yeah, and tests would be good :)

comment:6 Changed 13 years ago by ksenia

  • Summary changed from Add foreign key handler to formmaker to [PATCH] Add foreign key handler to formmaker

Here is the modified version of Randall's patch, together with some tests.

Changed 13 years ago by ksenia

Changed 13 years ago by ksenia

ignore the previous file please, it contains non-related code

comment:7 Changed 13 years ago by kevin

  • Status changed from new to closed
  • Resolution set to fixed

Yeah, I think that does it for me! Thanks!

Committed in [578].

Note: See TracTickets for help on using tickets.