你可以通过传入你自己的函数来更改/重定向 django 表单的函数吗?
我正在处理 django-paypal 并想要更改按钮 src 图像。所以我进入源中的conf.py 文件并编辑了src 目标。但是,我真的想不去管源,并且我注意到它
class PayPalPaymentsForm(forms.Form):
可以
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]
处理所有图像 src 目的地。由于在源代码中更改此定义比更改conf更糟糕,我想知道是否有一种方法可以传递您所做的自定义定义,例如在表单中传递初始参数?这样就不会更改源代码,并且我可以根据需要自定义 get_image def。
传递 def 这样的东西?
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)
谢谢!
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 worse 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如下所示: https://github.com/dcramer /django-paypal/blob/master/paypal/standard/conf.py
您必须在 settings.py 中更改 PAYPAL_IMAGE 或 PAYPAL_SUBSCRIPTION_IMAGE...。
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.
只需子类
PayPalPaymentsForm
并覆盖get_image
即可。Just subclass
PayPalPaymentsForm
and overrideget_image
.