I understand that it requires attention to use
- variables from models
- variables from controllers
- request, response, db, auth, T(?)
in modules.
Inside functions and method of class they can be used
- through function parameter/argument
- as current.xxxxx
Outside functions/methods, i.e. in all code which run at 'import' time
(like at module level, class attributes)
they should be avoided at all, because 'import' run once, but such
variables have thread-versions.
But I am not sure why the T() requires such attention too,
and if next use is correct and safe or isn't:
from gluon import current
from gluon.validators import IS_NOT_EMPTY, IS_IN_DB
class FormTxt(object):
err_choose = current.T('choose one or more')
err_required = current.T('this is required')
class IS_NOT_EMPTY_(IS_NOT_EMPTY):
def __init__(self):
super(IS_NOT_EMPTY_,
self).__init__(error_message=FormTxt.err_required)
class IS_IN_DB_(IS_IN_DB):
def __init__(self, *args, **kwargs):
super(IS_IN_DB_, self).__init__(*args,
error_message=FormTxt.err_choose, **kwargs)
So I use current.T() in module in class attributes,
which evaluates only once,
but I think it is not problem, because we have here just a text, which is
always the same, thread-independent.
Am I correct, or this could be problem too...?
Thanks, Mirek
--
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.