moved toolbar logic to dal, thanks Niphlod

This commit is contained in:
mdipierro
2012-10-29 18:13:58 -05:00
parent 6a13c33c70
commit 04caa5f4e4
3 changed files with 46 additions and 22 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.2.1 (2012-10-29 18:11:45) stable
Version 2.2.1 (2012-10-29 18:13:39) stable
+32 -2
View File
@@ -180,7 +180,7 @@ if PYTHON_VERSION == 2:
bytes, unicode = str, unicode
else:
import pickle
from io import StringIO as StringIO
from io import StringIO as StringIO
import copyreg
long = int
hashlib_md5 = lambda s: hashlib.md5(bytes(s,'utf8'))
@@ -256,6 +256,7 @@ REGEX_STORE_PATTERN = re.compile('\.(?P<e>\w{1,5})$')
REGEX_QUOTES = re.compile("'[^']*'")
REGEX_ALPHANUMERIC = re.compile('^[0-9a-zA-Z]\w*$')
REGEX_PASSWORD = re.compile('\://([^:@]*)\:')
REGEX_NOPASSWD = re.compile('(?<=\:)([^:@/]+)(?=@.+)')
# list of drivers will be built on the fly
# and lists only what is available
@@ -2106,7 +2107,7 @@ class SQLiteAdapter(BaseAdapter):
dbpath = pjoin(
self.folder.decode(path_encoding).encode('utf8'), dbpath)
else:
dbpath = pjoin(self.folder, dbpath)
dbpath = pjoin(self.folder, dbpath)
if not 'check_same_thread' in driver_args:
driver_args['check_same_thread'] = False
if not 'detect_types' in driver_args:
@@ -6661,6 +6662,35 @@ class DAL(object):
"""
BaseAdapter.set_folder(folder)
@staticmethod
def get_instances():
"""
Returns a dictionary with uri as key with timings and defined tables
{'sqlite://storage.sqlite': {
'dbstats': [(select auth_user.email from auth_user, 0.02009)],
'dbtables': {
'defined': ['auth_cas', 'auth_event', 'auth_group',
'auth_membership', 'auth_permission', 'auth_user'],
'lazy': '[]'
}
}
}
"""
dbs = getattr(THREAD_LOCAL,'db_instances',{}).items()
infos = {}
for db_uid, db_group in dbs:
for db in db_group:
if not db._uri:
continue
k = REGEX_NOPASSWD.sub('******',db._uri)
infos[k] = dict(dbstats = [(row[0], row[1]) for row in db._timings],
dbtables = {'defined':
sorted(list(set(db.tables) -
set(db._LAZY_TABLES.keys()))),
'lazy': sorted(db._LAZY_TABLES.keys())}
)
return infos
@staticmethod
def distributed_transaction_begin(*instances):
if not instances:
+13 -19
View File
@@ -48,7 +48,6 @@ except ImportError:
have_minify = False
regex_session_id = re.compile('^([\w\-]+/)?[\w\-\.]+$')
regex_nopasswd = re.compile('(?<=\:)([^:@/]+)(?=@.+)')
__all__ = ['Request', 'Response', 'Session']
@@ -127,7 +126,10 @@ class Request(Storage):
If request comes in over HTTP, redirect it to HTTPS
and secure the session.
"""
if not global_settings.cronjob and not self.is_https:
cmd_opts = global_settings.cmd_options
#checking if this is called within the scheduler or within the shell
#in addition to checking if it's not a cronjob
if not cmd_opts.shell and not cmd_opts.scheduler and not global_settings.cronjob and not self.is_https:
current.session.forget()
redirect(URL(scheme='https', args=self.args, vars=self.vars))
@@ -434,24 +436,16 @@ class Response(Storage):
BUTTON = TAG.button
admin = URL("admin", "default", "design",
args=current.request.application)
from gluon.dal import THREAD_LOCAL
dbs = getattr(THREAD_LOCAL,'db_instances',{}).items()
from gluon.dal import DAL
dbstats = []
dbtables = {}
for db_uid, db_group in dbs:
for db in db_group:
if not db._uri:
continue
k = regex_nopasswd.sub('******',db._uri)
dbstats.append(TABLE(*[TR(PRE(row[0]),'%.2fms' %
(row[1]*1000)) \
for row in db._timings]))
dbtables[k] = {'defined':
sorted(list(set(db.tables) -
set(db._LAZY_TABLES.keys()))) or
'[no defined tables]',
'lazy': sorted(db._LAZY_TABLES.keys()) or
'[no lazy tables]'}
infos = DAL.get_instances()
for k,v in infos.iteritems():
dbstats.append(TABLE(*[TR(PRE(row[0]),'%.2fms' %
(row[1]*1000))
for row in v['dbstats']]))
dbtables[k] = dict(defined=v['dbtables']['defined'] or '[no defined tables]',
lazy=v['dbtables']['lazy'] or '[no lazy tables]')
u = web2py_uuid()
backtotop = A('Back to top', _href="#totop-%s" % u)
return DIV(
@@ -509,7 +503,7 @@ class Session(Storage):
request = current.request
if response is None:
response = current.response
if separate == True:
if separate is True:
separate = lambda session_name: session_name[-2:]
self._unlock(response)
if not masterapp: