forked from orbit-oss/flask
Subscribe to signals with extra kwargs in the docs
This commit is contained in:
parent
ebd7468807
commit
230e136f32
1 changed files with 8 additions and 8 deletions
|
|
@ -86,7 +86,7 @@ specified that way one has to pass the list in as argument::
|
||||||
|
|
||||||
from flask import template_rendered
|
from flask import template_rendered
|
||||||
|
|
||||||
def captured_templates(app, recorded):
|
def captured_templates(app, recorded, **extra):
|
||||||
def record(sender, template, context):
|
def record(sender, template, context):
|
||||||
recorded.append((template, context))
|
recorded.append((template, context))
|
||||||
return template_rendered.connected_to(record, app)
|
return template_rendered.connected_to(record, app)
|
||||||
|
|
@ -94,7 +94,7 @@ specified that way one has to pass the list in as argument::
|
||||||
The example above would then look like this::
|
The example above would then look like this::
|
||||||
|
|
||||||
templates = []
|
templates = []
|
||||||
with captured_templates(app, templates):
|
with captured_templates(app, templates, **extra):
|
||||||
...
|
...
|
||||||
template, context = templates[0]
|
template, context = templates[0]
|
||||||
|
|
||||||
|
|
@ -162,7 +162,7 @@ With Blinker 1.1 you can also easily subscribe to signals by using the new
|
||||||
from flask import template_rendered
|
from flask import template_rendered
|
||||||
|
|
||||||
@template_rendered.connect_via(app)
|
@template_rendered.connect_via(app)
|
||||||
def when_template_rendered(sender, template, context):
|
def when_template_rendered(sender, template, context, **extra):
|
||||||
print 'Template %s is rendered with %s' % (template.name, context)
|
print 'Template %s is rendered with %s' % (template.name, context)
|
||||||
|
|
||||||
Core Signals
|
Core Signals
|
||||||
|
|
@ -181,7 +181,7 @@ The following signals exist in Flask:
|
||||||
|
|
||||||
Example subscriber::
|
Example subscriber::
|
||||||
|
|
||||||
def log_template_renders(sender, template, context):
|
def log_template_renders(sender, template, context, **extra):
|
||||||
sender.logger.debug('Rendering template "%s" with context %s',
|
sender.logger.debug('Rendering template "%s" with context %s',
|
||||||
template.name or 'string template',
|
template.name or 'string template',
|
||||||
context)
|
context)
|
||||||
|
|
@ -199,7 +199,7 @@ The following signals exist in Flask:
|
||||||
|
|
||||||
Example subscriber::
|
Example subscriber::
|
||||||
|
|
||||||
def log_request(sender):
|
def log_request(sender, **extra):
|
||||||
sender.logger.debug('Request context is set up')
|
sender.logger.debug('Request context is set up')
|
||||||
|
|
||||||
from flask import request_started
|
from flask import request_started
|
||||||
|
|
@ -213,7 +213,7 @@ The following signals exist in Flask:
|
||||||
|
|
||||||
Example subscriber::
|
Example subscriber::
|
||||||
|
|
||||||
def log_response(sender, response):
|
def log_response(sender, response, **extra):
|
||||||
sender.logger.debug('Request context is about to close down. '
|
sender.logger.debug('Request context is about to close down. '
|
||||||
'Response: %s', response)
|
'Response: %s', response)
|
||||||
|
|
||||||
|
|
@ -230,7 +230,7 @@ The following signals exist in Flask:
|
||||||
|
|
||||||
Example subscriber::
|
Example subscriber::
|
||||||
|
|
||||||
def log_exception(sender, exception):
|
def log_exception(sender, exception, **extra):
|
||||||
sender.logger.debug('Got exception during processing: %s', exception)
|
sender.logger.debug('Got exception during processing: %s', exception)
|
||||||
|
|
||||||
from flask import got_request_exception
|
from flask import got_request_exception
|
||||||
|
|
@ -246,7 +246,7 @@ The following signals exist in Flask:
|
||||||
|
|
||||||
Example subscriber::
|
Example subscriber::
|
||||||
|
|
||||||
def close_db_connection(sender):
|
def close_db_connection(sender, **extra):
|
||||||
session.close()
|
session.close()
|
||||||
|
|
||||||
from flask import request_tearing_down
|
from flask import request_tearing_down
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue