Skip to content

Commit

Permalink
fixing the middleware rules
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Aug 8, 2013
1 parent a5359f3 commit d1cd1af
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
History
-------

0.1.7 (2013-08-08)
+++++++++++++++++++

* Middleware excepts all of the djstripe namespaced URLs. This way people can pay.

0.1.6 (2013-08-08)
+++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion djstripe/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.6'
__version__ = '0.1.7'
20 changes: 11 additions & 9 deletions djstripe/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,35 @@

from .models import Customer

# So we don't have crazy long lines of code
EXEMPT = list(DJSTRIPE_SUBSCRIPTION_REQUIRED_EXCEPTION_URLS)
EXEMPT.append("[djstripe]")


class SubscriptionPaymentMiddleware(object):
"""
Rules:
"(app_name)" means everything from this app is exempt
"[namespace]" means everything with this name is exempt
"namespace:name" means this namespaced URL is exempt
"name" means this URL is exempt
* "(app_name)" means everything from this app is exempt
* "[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
Example::
DJSTRIPE_SUBSCRIPTION_REQUIRED_EXCEPTION_URLS = (
"(allauth)", # anything in the django-allauth URLConf
"[djstripe]", # Anything in the djstripe app
"[blogs]", # Anything in the blogs namespace
"products:detail", # A ProductDetail view you want shown to non-payers
"home", # Site homepage
)
"""

# TODO - needs tests

def process_request(self, request):

# So we don't have crazy long lines of code
EXEMPT = DJSTRIPE_SUBSCRIPTION_REQUIRED_EXCEPTION_URLS

if request.user.is_authenticated() and not request.user.is_staff:
match = resolve(request.path)
if "({0})".format(match.app_name) in EXEMPT:
Expand Down
3 changes: 2 additions & 1 deletion docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ 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

Example:

.. code-block:: python
DJSTRIPE_SUBSCRIPTION_REQUIRED_EXCEPTION_URLS = (
"(allauth)", # anything in the django-allauth URLConf
"[djstripe]", # Anything in the djstripe app
"[blogs]", # Anything in the blogs namespace
"products:detail", # A ProductDetail view you want shown to non-payers
"home", # Site homepage
)
Expand Down

0 comments on commit d1cd1af

Please sign in to comment.