Hi Anthony, thanks again for taking time out to explain and answered below questions. I did define the customer table before auth tables were created and used lazy_tables=False, it works this time when I put all the tables in a single database without using CAS (i do need to share group/membership across app). One last point I want to raise for potentially other readers is it works only when i took out the auth.signature in customer table (as customer table needs to be defined before auth tables are created. Since I watched massimo's tutorial videos having this auth.signature in most / all cases, I thought it should always include it as best practice. Many thanks!
On Thursday, March 30, 2017 at 11:31:22 PM UTC+8, Anthony wrote: > > 1st question: i want to use auth_user table to store my internal staffs >> and external customers info, so that I can leverage all the built-in >> authentication and authorisation functions provided by web2py out of the >> box (please let me know if I should not do that). I added some fields in >> auth_user as below, and got this error - 'Cannot resolve reference >> customer in auth_user definition'if I didn't use lazy_tables=True in >> DAL. Is lazy_tables=True the solution for this case? >> auth.settings.extra_fields['auth_user']= [ >> Field('customer', 'reference customer'), >> Field('mobile', requires=IS_NOT_EMPTY()), >> Field('title', requires=IS_NOT_EMPTY()), >> ] >> > > This can be corrected by defining the db.customer table before defining > the Auth tables. Note, it used to be possible to create a reference to > table that was not yet defined (even with lazy=False), and according to this > thread > <https://groups.google.com/forum/#!msg/web2py-developers/cU_ZpBAOXAU/6Hx2OPxEDuIJ>, > > it still should be possible, but apparently that is broken. An issue was > opened in the pydal repository about this a while back but was closed with > wontfix. I have added a comment suggesting it be re-opened: > https://github.com/web2py/pydal/issues/258#issuecomment-290439396 > > >> Or i should leverage CAS to store all the user/group/membership info in >> 'provider', and let accounting & ticketing 'consumer' applications to >> access them (my test didn't work with auth_user referencing customer table >> using CAS)? >> > > Please show your code (though CAS might not be what you want if you also > need to share groups/memberships across apps, as CAS only handles > login/authentication). > > >> Or should I create an auth_db = DAL(..) having these 2 web2py >> applications using this auth_db connection for >> authentication/authorization, and create accounting_db=DAL(..) and >> ticketing_db=DAL(..) for application specific databases? >> > > You will not be able to create reference fields in the other DBs that > reference records in auth_db.auth_user (which I assume you would need to > do), so this approach likely won't work for you. Alternatively, you could > keep everything in a single database and simply share the database between > the two apps. > > >> Or I should put everything in a single web2py application folder, create >> 2 controllers for accounting and ticketing respectively (what if I want to >> sell the accounting application to a client but not the ticketing >> application)? >> > > Well, if you might want to sell just one app at some point, this approach > won't work well. > > >> 3rd question: i have a customer table, an invoice table, an item table in >> my accounting application, below is the simplified version. When I created >> a view_customer() action with customer_grid = >> SQLFORM.smartgrid(db.customer,linked_tables=['auth_user','invoice'],user_signature=False), >> >> it only showed 'Auth users' link but not 'Invoice', why? >> Now I tried to create invoice_grid=SQLFORM.smartgrid(db.invoice, >> linked_tables=['item'], >> constraints=dict(invoice=db.invoice.customer==request.args(0))), the >> 'Items' link (when I clicked) on the grid raised error - Query Not >> Supported: invalid literal for long() with base 10: 'item' and 'no records >> found. when i didn't have constraints set, the 'Items' link worked >> correctly. Any ideas? >> > > Answered here > <https://groups.google.com/d/msg/web2py/hf_olaWbIBE/M_mrLJRYAgAJ>. > > Anthony > -- 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.