Created
December 7, 2015 19:40
-
-
Save rdegges/8de4ec51e2e370246b38 to your computer and use it in GitHub Desktop.
Stormpath Flask example application demonstrating how to subscribe to resource creation signals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask.ext.stormpath import StormpathManager | |
from pydispatch import dispatcher | |
from stormpath.resources.base import SIGNAL_RESOURCE_CREATED | |
app = Flask(__name__) | |
app.config['SECRET_KEY'] = 'xxx' | |
app.config['STORMPATH_API_KEY_ID'] = 'xxx' | |
app.config['STORMPATH_API_KEY_SECRET'] = 'xxx' | |
app.config['STORMPATH_APPLICATION'] = 'name' | |
stormpath_manager = StormpathManager(app) | |
def resource_created(signal, sender, data, params): | |
"""Prints off some signal data when a resource is created.""" | |
print 'signal:', signal | |
print 'sender:', sender | |
print 'data:', data | |
print 'params:', params | |
@app.route('/') | |
def home(): | |
return 'home page!' | |
# Listen for all object creations. | |
# You can also bind to SIGNAL_RESOURCE_UPDATED / SIGNAL_RESOURCE_DELETED | |
dispatcher.connect(resource_created, signal=SIGNAL_RESOURCE_CREATED) | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment