def session(self): """Get current glashammer/securecookie session""" # TODO: This has to be refactored! This is in Request, too! req = get_request() if 'beaker.session' in req.environ: return req.environ['beaker.session'] else: return get_session()
def add_query_debug_headers(response): """Add headers with the SQL info.""" request = get_request() if settings['database/track_queries']: count = len(request.sql_queries) sql_time = 0.0 for stmt, param, time in request.sql_queries: sql_time += time response.headers['X-SQL-Query-Count'] = str(count) response.headers['X-SQL-Query-Time'] = str(sql_time)
def request_track_query(cursor, statement, parameters, time): """If there is an active request, it logs the query on it.""" if settings['database/track_queries']: # It's possible we're not in a request. This happens e. g. in test # cases. try: request = get_request() except AttributeError: pass else: # Users can use their own wrappers that does not necessarilly have # an sql_queries attribute. We create our own here, if this happens. request.sql_queries.append((statement, parameters, time))
def get_redirect_target(invalid_targets=(), request=None): """Check the request and get the redirect target if possible. If not this function returns just `None`. """ if request is None: request = get_request() check_target = request.values.get('_redirect_target') or \ request.args.get('next') or \ request.environ.get('HTTP_REFERER') print check_target # if there is no information in either the form data # or the wsgi environment about a jump target we have # to use the target url if not check_target: return return check_target
def __init__(self): self.environ = get_request().environ