Changeset - 4a67271b94d9
[Not reviewed]
0 1 1
Christopher Neugebauer - 4 years ago 2017-10-05 23:09:16
chrisjrn@gmail.com
monkey_patches sync_card
2 files changed with 33 insertions and 0 deletions:
0 comments (0 inline, 0 general)
pinaxcon/monkey_patch.py
Show inline comments
 
new file 100644
 
from django.conf import settings
 
from django.core.mail import EmailMultiAlternatives
 
from functools import wraps
 

	
 

	
 
class MonkeyPatchMiddleware(object):
 
    ''' Ensures that our monkey patching only gets called after it is safe to do so.'''
 

	
 
    def process_request(self, request):
 
        do_monkey_patch()
 

	
 

	
 
def do_monkey_patch():
 
    patch_stripe_card_defaults()
 

	
 
    # Remove this function from existence
 
    global do_monkey_patch
 
    do_monkey_patch = lambda: None
 

	
 

	
 
def patch_stripe_card_defaults():
 
    from pinax.stripe.actions import sources
 
    from collections import defaultdict
 

	
 
    old_sync_card = sources.sync_card
 

	
 
    def sync_card(customer, source):
 
        d = defaultdict(str)
 
        d.update(source)
 
        return old_sync_card(customer, d)
 

	
 
    sources.sync_card = sync_card
pinaxcon/settings.py
Show inline comments
...
 
@@ -149,6 +149,7 @@ MIDDLEWARE_CLASSES = [
 
    "ssl_redirect.middleware.SSLRedirectMiddleware",
 
    "pinaxcon.middleware.CanonicalHostMiddleware",
 
    "pinaxcon.middleware.UnprependWWWMiddleware",
 
    "pinaxcon.monkey_patch.MonkeyPatchMiddleware",
 
]
 

	
 
ROOT_URLCONF = "pinaxcon.urls"
0 comments (0 inline, 0 general)