You can do:
db.define_table(...., common_filter = None if not session.org else (lambda
query:(db.my_table.org==session.org)))
you can also use the check:
from gluon.fileutils import check_credentials
check_credentials('admin') #returns true if you are logged as admin.
On Monday, 20 August 2012 12:48:29 UTC-5, mweissen wrote:
>
> (1) session.org will be set with the login. But I am an administrator: I
> think I should use the admin application without a login to the application
> itself.
>
> (2) Lets say session.org==1: now it is not possible to change a record
> with my_table.org==2 using the admin app.
>
> (3) Did you mean:
>
> common_filter = lambda query:
> (db.my_table.org==session.org) if session.org else True
>
>
> Interesting idea!
>
> 2012/8/20 Massimo Di Pierro <[email protected] <javascript:>>
>
>> How do you set the common filter? Seems to me if session.org is not set,
>> the common filter should not be set. web2py cannot ignore it because it
>> does the wrong thing.
>>
>>
>> On Monday, 20 August 2012 11:41:41 UTC-5, mweissen wrote:
>>>
>>> I have an application which should be used by some organizations.
>>> Therefore I have added
>>>
>>> Field('org','reference org', default=lambda:session.org),
>>>
>>> and
>>>
>>> common_filter = lambda query: db.my_table.org==session.org
>>>
>>> to my_table. session.org contails the id of the respective organization.
>>> Great feature,works fine! But using the database administration of the
>>> admin-application the common filter is still active.
>>> There is an "ignore_rw=True" in the admin application and I think I
>>> have read somewhere that there is also an "ignore_common_filters=True".
>>>
>>> If session.org is not set, a "database db select" shows strange effects:
>>>
>>> - I can see the first 100 rows.
>>> - But the message is "0 selected"
>>> - It is not possible to Update a record
>>>
>>>
>>> A simple "ignore_common_filters=True" at the appropriate location should
>>> solve the problem. I have taken a quick look at the code, but I think this
>>> statement has to be "very inside", therefore I have no concrete proposal.
>>>
>>> Regards, Martin
>>>
>>>
>>>
>>>
>>> --
>>
>
--