Hellow everyone,
I'm developing an application for a consulting company. To make a long
story short, there is some data in the database that is user administered,
and some formulas to execute with that data. Those formulas should be
administered by the consultant.
The database data can be easily manageable by the end user in web2py.
With regard to the formulas, I considered to use some business rules
engine. Then I realised that python is such a nice programming language
that who needs a business rules engine? I gave a try to python as a user
formulas specification.
I tried with a user module file with a function. That function has the
following parameters:
- parameteres: where selected data from the database is injected and
available to be used in formulas
- results: another dictionary where the user can store the results back
to the calling function.
This works quite fine.
Just to give an idea with a simplified sample code:
*controllers/controller.py:*
from gluon.storage import Storage
def calling_function():
parameters, results = Storage(), Storage()
parameters=get_data_from_database()
# Now we have defined things like:
# parameters.var1, parameters.var2, ...
from user_module import user_function
user_function(parameters, results)
# Now we have in results the key value1 with the resulting value
*modules/user_module.py*
def user_function(p, r):
# For instance if we want to add two values:
r.value1=p.var1 + p.var2
return None
My question is:
I need different versions of the user function and allow the end user to
edit those functions. This is needed because different organizational
units(OU) would have different formula definition.
Those formulas would be edited by a trusted and trained user. Obviously
there are some risks in allowing the end user to edit python code. To
minimize the risk, it is isolated in one module and the call to that user
function would be controlled by a try: clause.
I considered several alternatives:
1. Using just one user module and different functions, like
user_function1, user_function2, and calling
usermodule.user_function1(), user_module.user_function2() from the
calling_function depending on the OU related.
2. Using different user modules with the same user_function. That means
calling user_module1.userfunction(), user_module2.userfunction()
Obviously there is a need of creating a kind of scaffolding function
user_module.user_functionX() to be edited by the user, or an scaffolding
module user_moduleX with a user_function() to be edited by the user. The
scaffolding function or module would be created by a controller.
Can you recommend any of those approaches, or a better one?
Thanks in advance.
Best regards
--
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.