Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow callbacks to live outside of settings.py. #13

Merged
merged 1 commit into from

2 participants

@jsocol

Allow strings in the ARECIBO_SETTINGS['CALLBACKS'] list, so callback functions don't need to live in settings.py or get imported that early. e.g.

ARECIBO_SETTINGS['CALLBACKS'] = ['myapp.utils.arecibo_callback']
@andymckay andymckay merged commit 1194561 into andymckay:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 1, 2012
  1. Allow callbacks to live outside of settings.py.

    James Socol authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 1 deletion.
  1. +7 −1 django_arecibo/wrapper.py
View
8 django_arecibo/wrapper.py
@@ -90,7 +90,13 @@ def __init__(self, request, status, **kw):
# will be tested against them before posting. This is good for
# blocking certain user agents under certain conditions for examples.
for callback in arecibo_setting('CALLBACKS', []):
- if not callback(request, status):
+ if callable(callback):
+ fn = callback
+ else: # Should be a string, anything else is wrong.
+ module, _, function = callback.rpartition('.')
+ mod = __import__(module)
+ fn = mod.getattr(function)
+ if not fn(request, status):
return
exc_info = sys.exc_info()
Something went wrong with that request. Please try again.