I see. eval is dangerous. I would suggest:

description = 'description_'+lang
records = db(db.image.project_id==project_id).select(db.image
[description])
...
return dict(...,description=description,...)

VIEW:
......
{{for record in records:}}
{{=record[description]}}
{{pass}}
......

On Jan 28, 9:51 am, Khaled ElAdawy <kha...@el.adawi.name> wrote:
> I need it to retrieve fields from the database dynamically according
> to the current language,
> Please refer to the example below:
>
> MODEL:
> ......
> Field('description_en', 'string',
>     label=str(T('Image Description'))+" "+str(T('EN')),
>     requires=[IS_NOT_EMPTY(), IS_LENGTH(maxsize=250, minsize=0)]
> ),
> Field('description_ar', 'string',
>     label=str(T('Image Description'))+" "+str(T('AR')),
>     requires=[IS_NOT_EMPTY(), IS_LENGTH(maxsize=250, minsize=0)]
> ),
> ......
>
> CONTROLLER:
> ......
> query = eval('db.image.description_'+lang)
> records = db(db.image.project_id==project_id).select(query AS
> description)
> ...
>
> VIEW: (One view for all languages)
> ......
> {{for record in records:}}
> {{=record.description}}
> {{pass}}
> ......
>
> However, I solved the problem by modifying the code as follows:
>
> CONTROLLER:
> ......
> query = eval('db.image.description_'+lang)
> records = db(db.image.project_id==project_id).select(query)
> ...
>
> VIEW:
> ......
> {{for record in records:}}
> {{=eval('record.description_'+lang)}}
> {{pass}}
> ......
>
> Regards,
>
> On Jan 28, 5:13 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > the DAL allows you to use AS only for the purpose of renaming tables
> > in left joins, not for the purpose or renaming field names. The reason
> > it does not is that it would introduce a lot of complexity but not
> > necessarily provide a useful functionality. The new DAL will have the
> > ability to do he re-naming at the DAL level.
>
> > Perhaps I miss something? Why do you need this?
>
> > On Jan 28, 5:04 am, Khaled ElAdawy <kha...@el.adawi.name> wrote:
>
> > > I just want to map this simple query to DAL syntax:
> > > "SELECT field_name FROM table_name AS my_name"
>
> > > Regards,
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to