On Jun 21, 4:26 pm, mdipierro <[email protected]> wrote:
> my guess is that currently do not change often so I would use cache
> the mapping:
>
> currencies=cache.ram('currencies',lambda: dict([(row.code,row.name)
> for row in db(db.currency.id>0).select()]), 5000)
> db.cache_account.currency.represent=lambda id: currencies[id]
Nice but with needs a few adjustments:
# you want id and code fields
currencies=cache.ram('currencies',lambda: dict([(row.id,row.code) for
row in db(db.currency.id>0).select()]), 5000)
# Francois is not using FORM or SQLFORM
# so represent is of no use here
cash_acc_code=lambda id: currencies[id]
so now the controller reads:
def list_banks_and_accounts():
currencies=cache.ram('currencies',lambda: dict([(row.id,row.code)
for row in db(db.currency.id>0).select()]), 5000)
cash_acc_code=lambda id: currencies[id]
banks=db().select(db.bank.ALL,orderby=db.bank.name)
return dict(banks=banks,cash_acc_code=cash_acc_code)
and in the view where it says
{{=cash_account.currency}}
change to
{{=cash_acc_code(cash_account.currency)}}
I would also add these to the model:
db.bank.name.requires=[IS_NOT_EMPTY(),IS_NOT_IN_DB(db,'bank.name')]
db.cash_account.bank.requires=IS_IN_DB(db,'bank.id','%(name)s')
db.cash_account.currency.requires=IS_IN_DB(db,'currency.id','%(code)
s')
db.cash_account.name.requires=IS_NOT_IN_DB(db
((db.cash_account.bank==request.vars.bank)&
(db.cash_account.currency==request.vars.currency)),'cash_account.name')
Denes.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---