I changed 'request_precinct' to 'request_tenant' since this is more
appropriate. We are talking about buildig multi-tenant apps.

db._common_fields=[Field('request_tenant',default=request.env.http_host,w
ritable=False,readable=False)]

Notice you can also do

db._common_fields=[auth.signature]

and all tables will have created_by, modified_by, created_on,
modified_on, etc.


On May 26, 7:17 am, Massimo Di Pierro <massimo.dipie...@gmail.com>
wrote:
> yes.
>
> On May 25, 11:37 pm, mattgorecki <m...@goelephant.com> wrote:
>
>
>
>
>
>
>
> > So in this example request_precinct would equal harvard.anyschool.org?
>
> > Matt
>
> > On May 25, 9:47 pm, Massimo Di Pierro <massimo.dipie...@gmail.com>
> > wrote:
>
> > > There are two more features in trunk that I could use some testing
> > > with (common fields and precints)
>
> > > Imagine you have created an app "school" designed to manage one
> > > school. It has one database and many tables. You wrote it with one
> > > school in mind. Now you want to turn it into a service so that
> > > multiple schools can register and use it. You want to identify the
> > > school for example by the urlhttp://harvard.anyschool.organdeach
> > > school should ONLY see its own users, groups, records, etc. etc.
>
> > > Before today to do this you would have to rewrite all your tables and
> > > queries.
>
> > > Today you can do it without changing your code at all. You just have
> > > to add this line after db=DAL(...)
>
> > > db._common_fields=[Field('request_precinct',default=request.env.http_host,w
> > >  ritable=False,readable=False)]
>
> > > Yes. That is it!
>
> > > How does it work?
>
> > > 1) db._common_fields is a list of fields that you want to add to all
> > > tables.
> > > 2) The field called 'request_precinct' is special. Every query
> > > involving a table having this field is automatically filtered byfield
> > > value == field default. In our example the default is
> > > request.env.http_host, i.e. the hostname in the http request which
> > > identifies the school.
> > > 3) The field is hidden (writable=False,readable=False) but has a
> > > default therefore it is automatically set for all inserts.
>
> > > There is nothing special about schools here. You can use it with any
> > > other app.
>
> > > Give it a try and let me know.
>
> > > I could use some help in writing some documentation about the new
> > > features added today. ;-)
>
> > > Massimo

Reply via email to