Skip to content

Commit

Permalink
If settings.DEBUG is True, then django-debug-toolbar is exempt
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed May 1, 2014
1 parent f6d913b commit 93d6a56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
17 changes: 15 additions & 2 deletions djstripe/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
()
)

DJSTRIPE_SUBSCRIPTION_REDIRECT = getattr(
settings,
"DJSTRIPE_SUBSCRIPTION_REDIRECT",
"djstripe:subscribe"
)

from .models import Customer

# So we don't have crazy long lines of code
Expand All @@ -25,6 +31,7 @@ class SubscriptionPaymentMiddleware(object):
* "namespace:name" means this namespaced URL is exempt
* "name" means this URL is exempt
* The entire djtripe namespace is exempt
* If settings.DEBUG is True, then django-debug-toolbar is exempt
Example::
Expand All @@ -41,6 +48,12 @@ class SubscriptionPaymentMiddleware(object):
def process_request(self, request):

if request.user.is_authenticated() and not request.user.is_staff:
# First, if in DEBUG mode and with django-debug-toolbar, we skip
# this entire process.
if settings.DEBUG and request.path.startswith("/__debug__"):
return

# Second we check against matches
match = resolve(request.path)
if "({0})".format(match.app_name) in EXEMPT:
return
Expand All @@ -58,10 +71,10 @@ def process_request(self, request):
# djstripe.utils.user_has_active_subscription function
customer, created = Customer.get_or_create(request.user)
if created:
return redirect("djstripe:subscribe")
return redirect(DJSTRIPE_SUBSCRIPTION_REDIRECT)

if not customer.has_active_subscription():
return redirect("djstripe:subscribe")
return redirect(DJSTRIPE_SUBSCRIPTION_REDIRECT)

# TODO get this working in tests
# if request.user.is_anonymous():
Expand Down
3 changes: 2 additions & 1 deletion docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Rules:
* "[namespace]" means everything with this name is exempt
* "namespace:name" means this namespaced URL is exempt
* "name" means this URL is exempt
* The entire djtripe namespace is exempt
* The entire djstripe namespace is exempt
* If settings.DEBUG is True, then django-debug-toolbar is exempt

Example:

Expand Down

0 comments on commit 93d6a56

Please sign in to comment.