myconf.take, myconf.get
This commit is contained in:
@@ -14,10 +14,12 @@ from gluon.contrib.appconfig import AppConfig
|
|||||||
## once in production, remove reload=True to gain full speed
|
## once in production, remove reload=True to gain full speed
|
||||||
myconf = AppConfig(reload=True)
|
myconf = AppConfig(reload=True)
|
||||||
|
|
||||||
|
|
||||||
if not request.env.web2py_runtime_gae:
|
if not request.env.web2py_runtime_gae:
|
||||||
## if NOT running on Google App Engine use SQLite or other DB
|
## if NOT running on Google App Engine use SQLite or other DB
|
||||||
db = DAL(myconf.take('db.uri'), pool_size=myconf.take('db.pool_size', cast=int), check_reserved=['all'])
|
db = DAL(myconf.get('db.uri'),
|
||||||
|
pool_size = myconf.get('db.pool_size'),
|
||||||
|
migrate_enabled = myconf.get('db.migrate'),
|
||||||
|
check_reserved = ['all'])
|
||||||
else:
|
else:
|
||||||
## connect to Google BigTable (optional 'google:datastore://namespace')
|
## connect to Google BigTable (optional 'google:datastore://namespace')
|
||||||
db = DAL('google:datastore+ndb')
|
db = DAL('google:datastore+ndb')
|
||||||
@@ -32,8 +34,8 @@ else:
|
|||||||
## none otherwise. a pattern can be 'controller/function.extension'
|
## none otherwise. a pattern can be 'controller/function.extension'
|
||||||
response.generic_patterns = ['*'] if request.is_local else []
|
response.generic_patterns = ['*'] if request.is_local else []
|
||||||
## choose a style for forms
|
## choose a style for forms
|
||||||
response.formstyle = myconf.take('forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other
|
response.formstyle = myconf.get('forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other
|
||||||
response.form_label_separator = myconf.take('forms.separator')
|
response.form_label_separator = myconf.get('forms.separator')
|
||||||
|
|
||||||
|
|
||||||
## (optional) optimize handling of static files
|
## (optional) optimize handling of static files
|
||||||
@@ -53,7 +55,7 @@ response.form_label_separator = myconf.take('forms.separator')
|
|||||||
|
|
||||||
from gluon.tools import Auth, Service, PluginManager
|
from gluon.tools import Auth, Service, PluginManager
|
||||||
|
|
||||||
auth = Auth(db)
|
auth = Auth(db, host=myconf.get('host.name'))
|
||||||
service = Service()
|
service = Service()
|
||||||
plugins = PluginManager()
|
plugins = PluginManager()
|
||||||
|
|
||||||
@@ -62,9 +64,11 @@ auth.define_tables(username=False, signature=False)
|
|||||||
|
|
||||||
## configure email
|
## configure email
|
||||||
mail = auth.settings.mailer
|
mail = auth.settings.mailer
|
||||||
mail.settings.server = 'logging' if request.is_local else myconf.take('smtp.server')
|
mail.settings.server = 'logging' if request.is_local else myconf.get('smtp.server')
|
||||||
mail.settings.sender = myconf.take('smtp.sender')
|
mail.settings.sender = myconf.get('smtp.sender')
|
||||||
mail.settings.login = myconf.take('smtp.login')
|
mail.settings.login = myconf.get('smtp.login')
|
||||||
|
mail.settings.tls = myconf.get('smtp.tls')
|
||||||
|
mail.settings.ssl = myconf.get('smtp.ssl')
|
||||||
|
|
||||||
## configure auth policy
|
## configure auth policy
|
||||||
auth.settings.registration_requires_verification = False
|
auth.settings.registration_requires_verification = False
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ response.title = request.application.replace('_',' ').title()
|
|||||||
response.subtitle = ''
|
response.subtitle = ''
|
||||||
|
|
||||||
## read more at http://dev.w3.org/html5/markup/meta.name.html
|
## read more at http://dev.w3.org/html5/markup/meta.name.html
|
||||||
response.meta.author = 'Your Name <you@example.com>'
|
response.meta.author = myconf.get('app.author')
|
||||||
response.meta.description = 'a cool new app'
|
response.meta.description = myconf.get('app.description')
|
||||||
response.meta.keywords = 'web2py, python, framework'
|
response.meta.keywords = myconf.get('app.keywords')
|
||||||
response.meta.generator = 'Web2py Web Framework'
|
response.meta.generator = myconf.get('app.generator')
|
||||||
|
|
||||||
## your http://google.com/analytics id
|
## your http://google.com/analytics id
|
||||||
response.google_analytics_id = None
|
response.google_analytics_id = None
|
||||||
|
|||||||
@@ -1,17 +1,28 @@
|
|||||||
; App configuration
|
; App configuration
|
||||||
|
[app]
|
||||||
|
name = Welcome
|
||||||
|
author = Your Name <you@example.com>
|
||||||
|
description = a cool new app
|
||||||
|
keywords = web2py, python, framework
|
||||||
|
generator = Web2py Web Framework
|
||||||
|
|
||||||
|
; Host configuration
|
||||||
|
[host]
|
||||||
|
name = localhost
|
||||||
|
|
||||||
; db configuration
|
; db configuration
|
||||||
[db]
|
[db]
|
||||||
uri = sqlite://storage.sqlite
|
uri = sqlite://storage.sqlite
|
||||||
migrate = 1
|
migrate = true
|
||||||
pool_size = 1
|
pool_size = 10 ; ignored for sqlite
|
||||||
|
|
||||||
; smtp address and credentials
|
; smtp address and credentials
|
||||||
[smtp]
|
[smtp]
|
||||||
server = smtp.gmail.com:587
|
server = smtp.gmail.com:587
|
||||||
sender = you@gmail.com
|
sender = you@gmail.com
|
||||||
login = username:password
|
login = username:password
|
||||||
|
tls = true
|
||||||
|
ssl = true
|
||||||
|
|
||||||
; form styling
|
; form styling
|
||||||
[forms]
|
[forms]
|
||||||
|
|||||||
@@ -58,6 +58,27 @@ class AppConfigDict(dict):
|
|||||||
dict.__init__(self, *args, **kwargs)
|
dict.__init__(self, *args, **kwargs)
|
||||||
self.int_cache = {}
|
self.int_cache = {}
|
||||||
|
|
||||||
|
def get(self, path, default=None):
|
||||||
|
try:
|
||||||
|
value = self.take(path).strip()
|
||||||
|
if value.lower() in ('none','null',''):
|
||||||
|
return None
|
||||||
|
elif value.lower() == 'true':
|
||||||
|
return True
|
||||||
|
elif value.lower() == 'false':
|
||||||
|
return False
|
||||||
|
elif value.isdigit() or (value[0]=='-' and value[1:].isdigit()):
|
||||||
|
return int(value)
|
||||||
|
elif ', ' in value:
|
||||||
|
return value.split(', ')
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
return float(value)
|
||||||
|
except:
|
||||||
|
return value
|
||||||
|
except:
|
||||||
|
return default
|
||||||
|
|
||||||
def take(self, path, cast=None):
|
def take(self, path, cast=None):
|
||||||
parts = path.split('.')
|
parts = path.split('.')
|
||||||
if path in self.int_cache:
|
if path in self.int_cache:
|
||||||
|
|||||||
+7
-4
@@ -1710,8 +1710,9 @@ class Auth(object):
|
|||||||
args = []
|
args = []
|
||||||
if vars is None:
|
if vars is None:
|
||||||
vars = {}
|
vars = {}
|
||||||
|
host = scheme and self.settings.host
|
||||||
return URL(c=self.settings.controller,
|
return URL(c=self.settings.controller,
|
||||||
f=f, args=args, vars=vars, scheme=scheme)
|
f=f, args=args, vars=vars, scheme=scheme, host=host)
|
||||||
|
|
||||||
def here(self):
|
def here(self):
|
||||||
return URL(args=current.request.args, vars=current.request.get_vars)
|
return URL(args=current.request.args, vars=current.request.get_vars)
|
||||||
@@ -1720,7 +1721,7 @@ class Auth(object):
|
|||||||
hmac_key=None, controller='default', function='user',
|
hmac_key=None, controller='default', function='user',
|
||||||
cas_provider=None, signature=True, secure=False,
|
cas_provider=None, signature=True, secure=False,
|
||||||
csrf_prevention=True, propagate_extension=None,
|
csrf_prevention=True, propagate_extension=None,
|
||||||
url_index=None, jwt=None):
|
url_index=None, jwt=None, host=None):
|
||||||
|
|
||||||
## next two lines for backward compatibility
|
## next two lines for backward compatibility
|
||||||
if not db and environment and isinstance(environment, DAL):
|
if not db and environment and isinstance(environment, DAL):
|
||||||
@@ -1763,9 +1764,10 @@ class Auth(object):
|
|||||||
# ## what happens after registration?
|
# ## what happens after registration?
|
||||||
|
|
||||||
settings = self.settings = Settings()
|
settings = self.settings = Settings()
|
||||||
settings.update(Auth.default_settings)
|
settings.update(Auth.default_settings)
|
||||||
|
host = host or request.env.http_host,
|
||||||
settings.update(
|
settings.update(
|
||||||
cas_domains=[request.env.http_host],
|
cas_domains=[host],
|
||||||
enable_tokens=False,
|
enable_tokens=False,
|
||||||
cas_provider=cas_provider,
|
cas_provider=cas_provider,
|
||||||
cas_actions=dict(login='login',
|
cas_actions=dict(login='login',
|
||||||
@@ -1815,6 +1817,7 @@ class Auth(object):
|
|||||||
label_separator=current.response.form_label_separator,
|
label_separator=current.response.form_label_separator,
|
||||||
two_factor_methods = [],
|
two_factor_methods = [],
|
||||||
two_factor_onvalidation = [],
|
two_factor_onvalidation = [],
|
||||||
|
host = host,
|
||||||
)
|
)
|
||||||
settings.lock_keys = True
|
settings.lock_keys = True
|
||||||
# ## these are messages that can be customized
|
# ## these are messages that can be customized
|
||||||
|
|||||||
Reference in New Issue
Block a user