FormAlchemy / formalchemy

MIT License
81 stars 29 forks source link

Fieldset insert and insert_after issue #2

Closed marcofalcioni closed 13 years ago

marcofalcioni commented 13 years ago

I believe there is an issue in forms.py, lines 614 and 638 - (FA1.3.7). If I try to add a field for a relation, the name and the key differ, and the .index call fails.

Thanks Marco

gawel commented 13 years ago

Can you add your use case ? I don't really know how you add a relation

marcofalcioni commented 13 years ago

Hi, I was mistaken: the issue is when you want to insert a field before or after a relation. The use case is to remove a field and replace it with a hidden field, without having to reconfigure the entire form. Here is something to reproduce:

from sqlalchemy import from sqlalchemy.orm import mapper, relationship from formalchemy import from formalchemy import fatypes

metadata = MetaData()

widget_table = Table('widgets', metadata, Column('id', Integer, primary_key=True), Column('name', String), Column('user_id', Integer, ForeignKey('users.id')) )

users_table = Table('users', metadata, Column('id', Integer, primary_key=True), Column('name', String), Column('fullname', String), Column('password', String) )

engine = create_engine('sqlite:///:memory:', echo=True) metadata.create_all(bind=engine)

class User(object): def repr(self): return "<User('%s','%s', '%s')>" % (self.name, self.fullname, self.password)

class Widget(object): def repr(self): return "<widget('%s')>" % (self.name)

mapper(User, users_table) mapper(Widget, widget_table, properties={ 'user': relationship(User, backref="widgets") })

UserGrid = Grid(User) UserGrid.configure(include=[UserGrid.fullname, UserGrid.password, UserGrid.name], options=[UserGrid.fullname.label("Full Name")]) UserGrid.readonly = True UserGrid.render()

def test_forms(): WidgetFs = FieldSet(Widget) WidgetFs.configure(include=[WidgetFs.user, WidgetFs.name]) widget = Widget()

WidgetFs1 = WidgetFs.bind(model=widget)
del WidgetFs1.name
WidgetFs1.insert(WidgetFs1.user, Field('name', 

fatypes.String).hidden().set(value="widgetname"))

test_forms()

Marco Falcioni 415 886 7363


From: gawel reply@reply.github.com To: marcofalcioni@yahoo.com Sent: Fri, April 15, 2011 9:43:10 AM Subject: Re: [GitHub] Fieldset insert and insert_after issue [FormAlchemy/formalchemy GH-2]

Can you add your use case ? I don't really know how you add a relation

Reply to this email directly or view it on GitHub: https://github.com/FormAlchemy/formalchemy/issues/2#comment_1008777

gawel commented 13 years ago

fixed at 40411dfea20b894d5e58. Thanks!