[Fixes #26515771] Now if you hit submit on default blank campaign pledge page, we won't get an error.
parent
f9f899b3d1
commit
571e565b5e
|
@ -166,8 +166,8 @@ class ManageCampaignForm(forms.ModelForm):
|
|||
|
||||
class CampaignPledgeForm(forms.Form):
|
||||
preapproval_amount = forms.DecimalField(
|
||||
required=False,
|
||||
min_value=D('1.00'),
|
||||
required = False,
|
||||
min_value=D('1.00'),
|
||||
max_value=D('10000.00'),
|
||||
decimal_places=2,
|
||||
label="Pledge Amount",
|
||||
|
@ -175,6 +175,12 @@ class CampaignPledgeForm(forms.Form):
|
|||
anonymous = forms.BooleanField(required=False, label=_("Don't display my username in the supporters list"))
|
||||
|
||||
premium_id = forms.IntegerField(required=False)
|
||||
|
||||
def clean_preapproval_amount(self):
|
||||
data = self.cleaned_data['preapproval_amount']
|
||||
if data is None:
|
||||
raise forms.ValidationError(_("Please enter a pledge amount."))
|
||||
return data
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = self.cleaned_data
|
||||
|
@ -183,6 +189,7 @@ class CampaignPledgeForm(forms.Form):
|
|||
preapproval_amount = cleaned_data.get("preapproval_amount")
|
||||
premium_id = int(cleaned_data.get("premium_id"))
|
||||
premium_amount = Premium.objects.get(id=premium_id).amount
|
||||
logger.info("preapproval_amount: {0}, premium_id: {1}, premium_amount:{2}".format(preapproval_amount, premium_id, premium_amount))
|
||||
if preapproval_amount < premium_amount:
|
||||
raise forms.ValidationError(_("Sorry, you must pledge at least $%s to select that premium." % (premium_amount)))
|
||||
except Exception, e:
|
||||
|
|
|
@ -329,6 +329,15 @@ class PledgeView(FormView):
|
|||
form_class = CampaignPledgeForm
|
||||
embedded = False
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
# change https://code.djangoproject.com/browser/django/tags/releases/1.3.1/django/views/generic/edit.py#L129
|
||||
# don't automatically bind the data to the form on GET, only on POST
|
||||
# compare with https://code.djangoproject.com/browser/django/tags/releases/1.3.1/django/views/generic/edit.py#L34
|
||||
form_class = self.get_form_class()
|
||||
form = form_class()
|
||||
|
||||
return self.render_to_response(self.get_context_data(form=form))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(PledgeView, self).get_context_data(**kwargs)
|
||||
|
||||
|
@ -347,11 +356,18 @@ class PledgeView(FormView):
|
|||
preapproval_amount = D(models.Premium.objects.get(id=premium_id).amount)
|
||||
except:
|
||||
preapproval_amount = None
|
||||
|
||||
logger.info("preapproval_amount, premium_id: %s %s ", preapproval_amount, premium_id)
|
||||
|
||||
data = {'preapproval_amount':preapproval_amount, 'premium_id':premium_id}
|
||||
|
||||
form = CampaignPledgeForm(data)
|
||||
form_class = self.get_form_class()
|
||||
|
||||
# no validation errors, please, when we're only doing a GET
|
||||
# to avoid validation errors, don't bind the form
|
||||
|
||||
if preapproval_amount is not None:
|
||||
form = form_class(data)
|
||||
else:
|
||||
form = form_class()
|
||||
|
||||
context.update({'work':work,'campaign':campaign, 'premiums':premiums, 'form':form, 'premium_id':premium_id, 'faqmenu': 'pledge'})
|
||||
return context
|
||||
|
@ -360,7 +376,7 @@ class PledgeView(FormView):
|
|||
work_id = self.kwargs["work_id"]
|
||||
preapproval_amount = form.cleaned_data["preapproval_amount"]
|
||||
anonymous = form.cleaned_data["anonymous"]
|
||||
|
||||
|
||||
# right now, if there is a non-zero pledge amount, go with that. otherwise, do the pre_approval
|
||||
campaign = models.Work.objects.get(id=int(work_id)).last_campaign()
|
||||
|
||||
|
|
|
@ -190,10 +190,22 @@ def support_campaign():
|
|||
# click on biggest campaign list
|
||||
biggest_campaign_link = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("a[href*='/campaigns/pledged']"))
|
||||
biggest_campaign_link.click()
|
||||
time.sleep(1)
|
||||
|
||||
# pull up one of the campaigns to pledge to
|
||||
# div.book-list div.title a
|
||||
# for now, take the first book and click on the link to get to the work page
|
||||
sel.find_elements_by_css_selector("div.book-list div.title a")[0].click()
|
||||
|
||||
sel.quit()
|
||||
time.sleep(1)
|
||||
sel.find_element_by_css_selector("input[value*='Support']").click()
|
||||
|
||||
# just click Pledge without filling out amount -- should have the form validation spot the error
|
||||
pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Pledge']"))
|
||||
pledge_button.click()
|
||||
|
||||
|
||||
#sel.quit()
|
||||
|
||||
|
||||
def suites():
|
||||
|
|
Loading…
Reference in New Issue