pombreda / formalchemy

Automatically exported from code.google.com/p/formalchemy
MIT License
0 stars 0 forks source link

dropdown.options does not support ResultProxy iterables #112

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I tried this:
dropdown_options = list(model.session.execute("select key, value from
options_table"))
Form.configure(options=[Form.selector.dropdown(options=languages)],

This gives me:
'(key1, value1)'
'(key2, value2)'
'(key3, value3)'
in the dropdown. 
Converting the reslut to a normal list of pairs works fine. It would be
nice if this was supported.

Original issue reported on code.google.com by joakim.l...@gmail.com on 27 Aug 2009 at 3:04

GoogleCodeExporter commented 9 years ago
can you give a real example ? you use options=languages but language is never 
defined
here.

I need this to create a unittest to reproduce the problem.

Thanks

Original comment by gael.pas...@gmail.com on 27 Aug 2009 at 3:37

GoogleCodeExporter commented 9 years ago
Here is a full working example that exhibits the problem:

from sqlalchemy import engine, create_engine, Column, String
from formalchemy import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Text(Base):
    __tablename__ = "texts"    
    name = Column(String, primary_key=True)
    language = Column(String)
engine = create_engine('sqlite:///:memory:')
r = engine.execute("select 'Swedish' as name, 'sv_SE' as iso_code union all 
select
'English', 'en_US'").fetchall()
print FieldSet(Text).language.dropdown(options=r).render() #should work, but 
gives 
value="(u'English', u'en_US')">(u'English', u'en_US')
print FieldSet(Text).language.dropdown(options=map(list, r)).render() # works 
correctly

Original comment by joakim.l...@gmail.com on 28 Aug 2009 at 9:44

GoogleCodeExporter commented 9 years ago
It work for me with SQLAlchemy-0.5.5-py2.5

I've added a test for this:
http://code.google.com/p/formalchemy/source/diff?spec=svne95bb449481b2dd7f4fcf8c
89e2a5ad94b960c21&r=e95bb449481b2dd7f4fcf8c89e2a5ad94b960c21&format=side&path=/f
ormalchemy/tests/test_options.py

Original comment by gael.pas...@gmail.com on 1 Sep 2009 at 2:04

GoogleCodeExporter commented 9 years ago
I get the same wrong result with my testcase, even with SQLAlchemy-0.5.5. This 
is the
incorrect output from my testcase:
<select id="Text--language" name="Text--language"><option value="(u'Swedish',
u'sv_SE')">(u'Swedish', u'sv_SE')</option>
<option value="(u'English', u'en_US')">(u'English', u'en_US')</option></select>

...and this is how it should look:
<select id="Text--language" name="Text--language"><option 
value="sv_SE">Swedish</option>
<option value="en_US">English</option></select>

Original comment by joakim.l...@gmail.com on 2 Sep 2009 at 8:57

GoogleCodeExporter commented 9 years ago
Which version of python / FA ?

Original comment by gael.pas...@gmail.com on 2 Sep 2009 at 12:25