I'm dealing with django-paypal and want to change the button src images. So I went the the conf.py file in the source and edited the src destination. However, I really want to leave the source alone, and I noticed that the
class PayPalPaymentsForm(forms.Form):
has
def get_image(self):
return {
(True, self.SUBSCRIBE): SUBSCRIPTION_SANDBOX_IMAGE,
(True, self.BUY): SANDBOX_IMAGE,
(True, self.DONATE): DONATION_SANDBOX_IMAGE,
(False, self.SUBSCRIBE): SUBSCRIPTION_IMAGE,
(False, self.BUY): IMAGE,
(False, self.DONATE): DONATION_IMAGE,
}[TEST, self.button_type]
which handles all the image src destinations. Since changing this def in the source is wo开发者_开发知识库rse than changing conf, I was wondering if there was a way to pass in customized defs you make like passing in initial arguments in forms? This way no source code is changed, and I can customize the get_image def as much as I need.
passing in def something like this?
def get_image(self):
....
....
paypal = {
'amount': 10,
'item_name': 'test1',
'item_number': 'test1_slug',
# PayPal wants a unique invoice ID
'invoice': str(uuid.uuid4()),
}
form = PayPalPaymentsForm(initial=paypal, get_image)
Thanks!
As seen here: https://github.com/dcramer/django-paypal/blob/master/paypal/standard/conf.py
You have to change PAYPAL_IMAGE, or PAYPAL_SUBSCRIPTION_IMAGE, ... in your settings.py.
Just subclass PayPalPaymentsForm
and override get_image
.
精彩评论