Let me explain the scenario. I have several pairs of controllers/views (eg. opt, opt_cat, equip) that each manage a single table because they have different characteristics.
And I have several pairs of controllers/views that are shared (eg. single_equip and table_management) and manage several different tables each (all the tables each manages have the same characteristics). I use session vars to indicate, among other things, the table name to be managed. This all works fine. Now I have must add a new controller/view pair called get_approval to require a supervisor password to allow an operator to delete (inactivate really) a record of any of the above tables. This action is started by the operator pressing the "Delete" button on the grid that shows the table in one of the above mentioned controller/view pairs (single-table opt, opt_cat... and shared single_equip and table_management). Bare in mind that each table has different checks to be made before allowing the "deletion". So the solutions I tried were: 1. Use a session var to pass the query (as a string, not the results) so that the get_approval would execute the query. This works, but because it uses eval I dismissed the idea. 2. I created a function called deletion_checks in each of the controllers. I assigned the function to a session var hopping that I could then execute it in the get_approval, but unfortunately it is not pickleable, therefore it doesn't work. 3. I repeated the get_approval function in each of the controllers. This works fine, but if I need to make change, I must propagate the change to all controllers (not good). The solution you suggest I didn't try because I think a controller with a view doesn't accept function args (only request.args and request.vars if I'm not mistaken) and I need to pass it the deletion_checks function "pointer" so that get_approval executes it (and I remind you that the deletion_checks function is different for each table). Any ideas? Thanks. sábado, 4 de Maio de 2019 às 16:19:42 UTC+1, Anthony escreveu: > > In each controller: > > from mymodule import shared_function > rows = shared_function(pass, some, args) > > Not clear why you instead need to use the session and have another > controller action involved. > > Anthony > > On Friday, May 3, 2019 at 8:35:53 AM UTC-4, [email protected] > <javascript:> wrote: >> >> That was what I was trying to do. >> The problem is that the queries that were going to be executed in the >> destination (shared function) vary according to the requesting controller. >> The query string passed through the session would solve this, but because >> the only way to execute it in the destination would be to use eval, I >> dismissed the idea. >> >> >> sexta-feira, 3 de Maio de 2019 às 12:42:05 UTC+1, Anthony escreveu: >>> >>> It might help to show some code. Why don't you just put the shared >>> function in a model or module and call it directly from each controller? >> >> -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.

