[web2py] Re: example of model w/ model graph, multi-tenancy, record versioning (incl auth tables), and record uid

2013-03-31 Thread Massimo Di Pierro
Nice example!

On Saturday, 23 March 2013 16:18:39 UTC-5, Peter Etchells wrote:
>
> I was playing around with impressive model graph feature, & thought you 
> may be interested in the following simple model, with these features:
>
>
>- multi-tenancy 
> 
>- record 
> versioning(including
>  auth 
>tables 
>)
>- unique id for each record (eg for syncing across multiple 
> dbs
>)
>
> total code is about 14 lines, all in model db.py in a new empty application
>
> #this goes after auth=Auth(db) 
> #model code to implement multi-tenancy and tenant name table, record 
> versioning (including for auth tables), uid for all tables( for syncing 
> multiple dbs)
> #this field in a table triggers multi-tenancy
> request_tenant=Field('request_tenant', default=request.env.http_host, 
> writable=False) #try request.env.server_port on local machine for local demo
> #this field is a unique id for any record, anywhere. could/should be 
> unique=True
> unique_id=Field('uuid', length=64, default=lambda: str(uuid.uuid4()), 
> writable=False)
> #extra fields for auth & all tables
> extra_fields=[request_tenant, auth.signature, unique_id]
>
> #example of adding extra fields to various auth tables
> #auth_user gets two extra fields as below. auth_event gets no extra 
> fields. other auth tables get the extra_fields defined above.
> auth.settings.extra_fields['auth_user']=[   Field('country'),  
>  Field('tz_offset', 'double', default=0.0),   ]+extra_fields
> #example of extra fields for multiple auth tables
> #this is to exclude auth_event from getting versioning and archive
> for auth_table in 'cas membership permission group'.split():
>auth.settings.extra_fields['auth_'+auth_table]=extra_fields
> #auth.settings.extra_fields['auth_event']=[unique_id] # if we wanted 
> unique events across multiple dbs  
> #instead of the above, we could just do auth.define_tables after 
> common_fields if we wanted *all* auth_ tables to also have versioning and 
> archive
> auth.define_tables(username=False, signature=False)
>
> ## configure email
> #...
> #use_janrain(auth, filename='private/janrain.key')
>
> #this at end of model 
>
> #example of extra fields for all other tables except auth tables, which 
> have already been defined above. this implements record versioning
> for f in extra_fields:
> db._common_fields.append(f)
> 
> #the tenant table below will have only one visible record, depending on 
> tenant (if record exists)...
> #eg tenant_name=db().select(db.tenant.name, cacheable=True, 
> cache=(cache.ram, 1000)).first().name)
> db.define_table('tenant',
> Field('name', label='tenant name'), #could/should be unique=True
> )
> #sample basic table to demonstrate links to web2py tables
> db.define_table('mytable',
> Field('name'),
> )
>
> #here define more tables that will have record versioning
> auth.enable_record_versioning(db)
> #now define any tables that won't have record versioning (eg event logs)
>
>
> 
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: example of model w/ model graph, multi-tenancy, record versioning (incl auth tables), and record uid

2013-04-06 Thread Massimo Di Pierro
Can you post a web2pyslice about this?

On Saturday, 23 March 2013 16:18:39 UTC-5, Peter Etchells wrote:
>
> I was playing around with impressive model graph feature, & thought you 
> may be interested in the following simple model, with these features:
>
>
>- multi-tenancy 
> 
>- record 
> versioning(including
>  auth 
>tables 
>)
>- unique id for each record (eg for syncing across multiple 
> dbs
>)
>
> total code is about 14 lines, all in model db.py in a new empty application
>
> #this goes after auth=Auth(db) 
> #model code to implement multi-tenancy and tenant name table, record 
> versioning (including for auth tables), uid for all tables( for syncing 
> multiple dbs)
> #this field in a table triggers multi-tenancy
> request_tenant=Field('request_tenant', default=request.env.http_host, 
> writable=False) #try request.env.server_port on local machine for local demo
> #this field is a unique id for any record, anywhere. could/should be 
> unique=True
> unique_id=Field('uuid', length=64, default=lambda: str(uuid.uuid4()), 
> writable=False)
> #extra fields for auth & all tables
> extra_fields=[request_tenant, auth.signature, unique_id]
>
> #example of adding extra fields to various auth tables
> #auth_user gets two extra fields as below. auth_event gets no extra 
> fields. other auth tables get the extra_fields defined above.
> auth.settings.extra_fields['auth_user']=[   Field('country'),  
>  Field('tz_offset', 'double', default=0.0),   ]+extra_fields
> #example of extra fields for multiple auth tables
> #this is to exclude auth_event from getting versioning and archive
> for auth_table in 'cas membership permission group'.split():
>auth.settings.extra_fields['auth_'+auth_table]=extra_fields
> #auth.settings.extra_fields['auth_event']=[unique_id] # if we wanted 
> unique events across multiple dbs  
> #instead of the above, we could just do auth.define_tables after 
> common_fields if we wanted *all* auth_ tables to also have versioning and 
> archive
> auth.define_tables(username=False, signature=False)
>
> ## configure email
> #...
> #use_janrain(auth, filename='private/janrain.key')
>
> #this at end of model 
>
> #example of extra fields for all other tables except auth tables, which 
> have already been defined above. this implements record versioning
> for f in extra_fields:
> db._common_fields.append(f)
> 
> #the tenant table below will have only one visible record, depending on 
> tenant (if record exists)...
> #eg tenant_name=db().select(db.tenant.name, cacheable=True, 
> cache=(cache.ram, 1000)).first().name)
> db.define_table('tenant',
> Field('name', label='tenant name'), #could/should be unique=True
> )
> #sample basic table to demonstrate links to web2py tables
> db.define_table('mytable',
> Field('name'),
> )
>
> #here define more tables that will have record versioning
> auth.enable_record_versioning(db)
> #now define any tables that won't have record versioning (eg event logs)
>
>
> 
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




[web2py] Re: example of model w/ model graph, multi-tenancy, record versioning (incl auth tables), and record uid

2015-06-09 Thread Gene
Regarding the appending of common fields, seems to work for me when its 
declared at the beginning of the model file, not end. Does the placement 
matter, can anyone confirm/deny?

On Sunday, March 24, 2013 at 5:18:39 AM UTC+8, Peter Etchells wrote:
>
>
> #this at end of model 
>
> #example of extra fields for all other tables except auth tables, which 
> have already been defined above. this implements record versioning
> for f in extra_fields:
> db._common_fields.append(f)
> 
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[web2py] Re: example of model w/ model graph, multi-tenancy, record versioning (incl auth tables), and record uid

2015-06-10 Thread Massimo Di Pierro
Yes, it matters.

On Tuesday, 9 June 2015 22:06:47 UTC-5, Gene wrote:
>
> Regarding the appending of common fields, seems to work for me when its 
> declared at the beginning of the model file, not end. Does the placement 
> matter, can anyone confirm/deny?
>
> On Sunday, March 24, 2013 at 5:18:39 AM UTC+8, Peter Etchells wrote:
>>
>>
>> #this at end of model 
>>
>> #example of extra fields for all other tables except auth tables, which 
>> have already been defined above. this implements record versioning
>> for f in extra_fields:
>> db._common_fields.append(f)
>> 
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.