commit
0ddbdbc944
|
@ -645,10 +645,10 @@ class CampaignPledgeForm(forms.Form):
|
||||||
raise forms.ValidationError(_("Sorry, you must pledge at least $%s to select that premium." % (self.premium.amount)))
|
raise forms.ValidationError(_("Sorry, you must pledge at least $%s to select that premium." % (self.premium.amount)))
|
||||||
return self.cleaned_data
|
return self.cleaned_data
|
||||||
|
|
||||||
class PlainCCForm(forms.Form):
|
class TokenCCMixin(forms.Form):
|
||||||
stripe_token = forms.CharField(required=False, widget=forms.HiddenInput())
|
stripe_token = forms.CharField(required=True, widget=forms.HiddenInput())
|
||||||
|
|
||||||
class BaseCCForm(PlainCCForm):
|
class BaseCCMixin(forms.Form):
|
||||||
work_id = forms.IntegerField(required=False, widget=forms.HiddenInput())
|
work_id = forms.IntegerField(required=False, widget=forms.HiddenInput())
|
||||||
preapproval_amount= forms.DecimalField(
|
preapproval_amount= forms.DecimalField(
|
||||||
required=False,
|
required=False,
|
||||||
|
@ -657,12 +657,23 @@ class BaseCCForm(PlainCCForm):
|
||||||
decimal_places=2,
|
decimal_places=2,
|
||||||
label="Amount",
|
label="Amount",
|
||||||
)
|
)
|
||||||
|
class UserCCMixin(forms.Form):
|
||||||
|
username = forms.CharField(max_length=30, required=True, widget=forms.HiddenInput())
|
||||||
|
|
||||||
|
class PlainCCForm(TokenCCMixin, forms.Form):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class BaseCCForm(BaseCCMixin, TokenCCMixin, forms.Form):
|
||||||
|
pass
|
||||||
|
|
||||||
class AnonCCForm(BaseCCForm):
|
class AnonCCForm(BaseCCForm):
|
||||||
email = forms.CharField(max_length=30, required=False, widget=forms.TextInput())
|
email = forms.CharField(max_length=30, required=False, widget=forms.TextInput())
|
||||||
|
|
||||||
class CCForm(BaseCCForm):
|
class CCForm(UserCCMixin, BaseCCForm):
|
||||||
username = forms.CharField(max_length=30, required=True, widget=forms.HiddenInput())
|
pass
|
||||||
|
|
||||||
|
class AccountCCForm( BaseCCMixin, UserCCMixin, forms.Form):
|
||||||
|
pass
|
||||||
|
|
||||||
class DonateForm(forms.Form):
|
class DonateForm(forms.Form):
|
||||||
preapproval_amount = forms.DecimalField( widget=forms.HiddenInput() )
|
preapproval_amount = forms.DecimalField( widget=forms.HiddenInput() )
|
||||||
|
|
|
@ -108,6 +108,7 @@ from regluit.frontend.forms import (
|
||||||
getTransferCreditForm,
|
getTransferCreditForm,
|
||||||
CCForm,
|
CCForm,
|
||||||
AnonCCForm,
|
AnonCCForm,
|
||||||
|
AccountCCForm,
|
||||||
CloneCampaignForm,
|
CloneCampaignForm,
|
||||||
PlainCCForm,
|
PlainCCForm,
|
||||||
WorkForm,
|
WorkForm,
|
||||||
|
@ -1285,6 +1286,8 @@ class FundView(FormView):
|
||||||
def get_form_class(self):
|
def get_form_class(self):
|
||||||
if self.request.user.is_anonymous():
|
if self.request.user.is_anonymous():
|
||||||
return AnonCCForm
|
return AnonCCForm
|
||||||
|
elif self.request.user.profile.account:
|
||||||
|
return AccountCCForm
|
||||||
else:
|
else:
|
||||||
return CCForm
|
return CCForm
|
||||||
|
|
||||||
|
@ -1304,18 +1307,17 @@ class FundView(FormView):
|
||||||
|
|
||||||
if kwargs.has_key('data'):
|
if kwargs.has_key('data'):
|
||||||
data = kwargs['data'].copy()
|
data = kwargs['data'].copy()
|
||||||
|
kwargs['data'] = data
|
||||||
else:
|
else:
|
||||||
data = {}
|
data = {}
|
||||||
|
kwargs['initial'] = data
|
||||||
|
|
||||||
data.update(
|
data.update(
|
||||||
{'preapproval_amount':self.transaction.needed_amount,
|
{'preapproval_amount':self.transaction.needed_amount,
|
||||||
'username':self.request.user.username if self.request.user.is_authenticated else None,
|
'username':self.request.user.username if self.request.user.is_authenticated else None,
|
||||||
'work_id':self.transaction.campaign.work.id,
|
'work_id':self.transaction.campaign.work.id,
|
||||||
'title':self.transaction.campaign.work.title}
|
'title':self.transaction.campaign.work.title}
|
||||||
)
|
)
|
||||||
|
|
||||||
kwargs['data'] = data
|
|
||||||
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
@ -1336,7 +1338,7 @@ class FundView(FormView):
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
p = PaymentManager()
|
p = PaymentManager()
|
||||||
stripe_token = form.cleaned_data["stripe_token"]
|
stripe_token = form.cleaned_data.get("stripe_token", None)
|
||||||
self.transaction.host = settings.PAYMENT_PROCESSOR
|
self.transaction.host = settings.PAYMENT_PROCESSOR
|
||||||
return_url = "%s?tid=%s" % (reverse('pledge_complete'),self.transaction.id)
|
return_url = "%s?tid=%s" % (reverse('pledge_complete'),self.transaction.id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue