Files
@ 59207eb0c971
Branch filter:
Location: symposion_app/pinaxcon/monkey_patch.py - annotation
59207eb0c971
2.2 KiB
text/x-python
Other suggested django migrations
So django keeps strict synchronization between its code and migrations
so that it can help generating new migrations. These are the additional
suggested migrations. A lot of these are a null effect, some are things
like transforming an unsigned integer to a signed integer. So not super
urgent on a small scale, but worth doing to keep django happy.
So django keeps strict synchronization between its code and migrations
so that it can help generating new migrations. These are the additional
suggested migrations. A lot of these are a null effect, some are things
like transforming an unsigned integer to a signed integer. So not super
urgent on a small scale, but worth doing to keep django happy.
3118e4c11c59 3118e4c11c59 3118e4c11c59 2cdb554623e5 2cdb554623e5 2cdb554623e5 2cdb554623e5 2cdb554623e5 2cdb554623e5 2cdb554623e5 2cdb554623e5 a3474fd9cd4c 2cdb554623e5 2cdb554623e5 2cdb554623e5 39b556b7ac4f 2cdb554623e5 2cdb554623e5 39b556b7ac4f a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c a3474fd9cd4c | 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_payment_form()
# Remove this function from existence
global do_monkey_patch
do_monkey_patch = lambda: None # noqa: E731
def patch_stripe_payment_form(): # noqa: C901
import inspect # Oh no.
from django.http.request import HttpRequest
from registripe.forms import CreditCardForm
from pinaxcon.registrasion import models
old_init = CreditCardForm.__init__
@wraps(old_init)
def new_init(self, *a, **k):
# Map the names from our attendee profile model
# To the values expected in the Stripe card model
mappings = (
("address_line_1", "address_line1"),
("address_line_2", "address_line2"),
("address_suburb", "address_city"),
("address_postcode", "address_zip"),
("state", "address_state"),
("country", "address_country"),
)
initial = "initial"
if initial not in k:
k[initial] = {}
initial = k[initial]
# Find request context maybe?
frame = inspect.currentframe()
attendee_profile = None
if frame:
context = frame.f_back.f_locals
for name, value in (context.items() or {}):
if not isinstance(value, HttpRequest):
continue
user = value.user
if not user.is_authenticated():
break
try:
attendee_profile = models.AttendeeProfile.objects.get(
attendee__user=user
)
except models.AttendeeProfile.DoesNotExist:
# Profile is still none.
pass
break
if attendee_profile:
for us, stripe in mappings:
i = getattr(attendee_profile, us, None)
if i:
initial[stripe] = i
old_init(self, *a, **k)
CreditCardForm.__init__ = new_init
|