Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Add default/global context processor. Fixes #306
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Wright committed Sep 17, 2014
1 parent 3d7b97a commit 679cee7
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 8 deletions.
3 changes: 3 additions & 0 deletions flask_security/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ def _run_ctx_processor(self, endpoint):
rv.update(fn())
return rv

def context_processor(self, fn):
self._add_ctx_processor(None, fn)

def forgot_password_context_processor(self, fn):
self._add_ctx_processor('forgot_password', fn)

Expand Down
2 changes: 1 addition & 1 deletion tests/templates/custom_security/change_password.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM CHANGE PASSWORD

{{ global }}
{{ foo }}
2 changes: 1 addition & 1 deletion tests/templates/custom_security/forgot_password.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM FORGOT PASSWORD

{{ global }}
{{ foo }}
2 changes: 1 addition & 1 deletion tests/templates/custom_security/login_user.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM LOGIN USER

{{ global }}
{{ foo }}
2 changes: 1 addition & 1 deletion tests/templates/custom_security/register_user.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM REGISTER USER

{{ global }}
{{ foo }}
2 changes: 1 addition & 1 deletion tests/templates/custom_security/reset_password.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM RESET PASSWORD

{{ global }}
{{ foo }}
2 changes: 1 addition & 1 deletion tests/templates/custom_security/send_confirmation.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM SEND CONFIRMATION

{{ global }}
{{ foo }}
2 changes: 1 addition & 1 deletion tests/templates/custom_security/send_login.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM SEND LOGIN

{{ global }}
{{ foo }}
2 changes: 1 addition & 1 deletion tests/templates/security/email/reset_instructions.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
CUSTOM RESET INSTRUCTIONS

{{ global }}
{{ foo }}
11 changes: 11 additions & 0 deletions tests/test_context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,40 @@
send_confirmation_template='custom_security/send_confirmation.html',
register_user_template='custom_security/register_user.html')
def test_context_processors(client, app):
@app.security.context_processor
def default_ctx_processor():
return {'global': 'global'}

@app.security.forgot_password_context_processor
def forgot_password():
return {'foo': 'bar'}

response = client.get('/reset')
assert b'global' in response.data
assert b'bar' in response.data

@app.security.login_context_processor
def login():
return {'foo': 'bar'}

response = client.get('/login')
assert b'global' in response.data
assert b'bar' in response.data

@app.security.register_context_processor
def register():
return {'foo': 'bar'}

response = client.get('/register')
assert b'global' in response.data
assert b'bar' in response.data

@app.security.reset_password_context_processor
def reset_password():
return {'foo': 'bar'}

response = client.get('/reset')
assert b'global' in response.data
assert b'bar' in response.data

@app.security.change_password_context_processor
Expand All @@ -58,13 +66,15 @@ def change_password():

authenticate(client)
response = client.get('/change')
assert b'global' in response.data
assert b'bar' in response.data

@app.security.send_confirmation_context_processor
def send_confirmation():
return {'foo': 'bar'}

response = client.get('/confirm')
assert b'global' in response.data
assert b'bar' in response.data

@app.security.mail_context_processor
Expand All @@ -75,6 +85,7 @@ def mail():
client.post('/reset', data=dict(email='matt@lp.com'))

email = outbox[0]
assert b'global' in email.html
assert 'bar' in email.html


Expand Down

0 comments on commit 679cee7

Please sign in to comment.