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 #581 (closed enhancement: fixed)

Opened 13 years ago

Last modified 12 years ago

allow formmaker.py to handle inherited fields PATCH

Reported by: gavin@… Owned by: anonymous
Priority: normal Milestone: 0.9
Component: TurboGears Version:
Severity: normal Keywords:
Cc:

Description

based on the method used in Catwalk does not handle inherited joins yet, need to fix join_widget handling first in order to be able to test for my project. (Not using Many-to-Many)

Index: turbogears/fastdata/formmaker.py =================================================================== --- turbogears/fastdata/formmaker.py (revision 779) +++ turbogears/fastdata/formmaker.py (working copy) @@ -117,24 +117,48 @@

def sqlwidgets(sqlclass, fields=None):

if fields:

  • columnlist = fields

+ columnlist = fields

elif hasattr(sqlclass, "form_order"):

columnlist = sqlclass.form_order

else:

  • columnlist = sqlclass.sqlmeta.columns

+ columnlist = get_sql_columns_for_sqlclass(sqlclass) + sqlcolumns = get_sql_columns_for_sqlclass(sqlclass)

widgetlist = [] for column in columnlist:

widget = None

  • if sqlclass.sqlmeta.columns.has_key(column):
  • widget = column_widget(sqlclass.sqlmeta.columns[column])
  • elif sqlclass.sqlmeta.columns.has_key(column + 'ID'): #key column
  • widget = column_widget(sqlclass.sqlmeta.columns[column + 'ID'])

+ if sqlcolumns.has_key(column): + widget = column_widget(sqlcolumns[column]) + elif sqlcolumns(column + 'ID'): #key column + widget = column_widget(sqlcolumns[column + 'ID'])

else:

for join in sqlclass.sqlmeta.joins:

if join.joinMethodName == column:

widget = join_widget(join) break

  • if not widget:
  • raise Exception, "Join or column %r not found in class %r" % (column, sqlclass.name)

+ if not widget: + raise Exception, "Join or column %r not found in class %r" % (column, sqlclass.name)

widgetlist.append(widget)

return widgetlist

+ +def get_sql_columns_for_sqlclass(sqlclass): + """Return list of sqlmeta comumns, does not include joins + @param object: model instance + """ + cols = {} + """get normal columns""" + for column_name in sqlclass.sqlmeta.columns: + column = sqlclass.sqlmeta.columns[column_name] + if sqlclass._inheritable and column_name == 'childName':continue + cols[column_name] = column + if sqlclass._inheritable and not is_inheritable_base_class(sqlclass): + inherited_columns = get_inherited_columns(sqlclass) + if inherited_columns: cols.update(inherited_columns) + return cols + +def get_inherited_columns(sqlclass): + """Return the columns inherited from the parent class""" + return get_sql_columns_for_sqlclass(sqlclass._parentClass) + +def is_inheritable_base_class(obj): + Check if the object is a direct subclass of InheritableSQLObject + return 'sqlobject.inheritance.InheritableSQLObject' in '%s'% obj.bases

Attachments

inherit_formfix.patch Download (2.6 KB) - added by gavin@… 13 years ago.
Uploaded Patch

Change History

comment:1 Changed 13 years ago by anonymous

gack, the wiki makes a mess of python code, attaching diff as file

Changed 13 years ago by gavin@…

Uploaded Patch

comment:2 Changed 13 years ago by alberto

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

Fixed in [1485]

Note: See TracTickets for help on using tickets.