From 8f4ca1248326a30430140f1aa9e41deba5866814 Mon Sep 17 00:00:00 2001 From: eric Date: Sun, 24 Jul 2016 18:50:48 -0400 Subject: [PATCH] fixed premium editing as validation is triggered by data --- frontend/forms.py | 3 +++ frontend/views.py | 10 ++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/frontend/forms.py b/frontend/forms.py index 2dcc7b70..310da3e9 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -495,6 +495,9 @@ class CustomPremiumForm(forms.ModelForm): 'type': forms.HiddenInput(attrs={'value':'XX'}), 'limit': forms.TextInput(attrs={'value':'0'}), } + def clean_type(self): + return 'CU' + class OfferForm(forms.ModelForm): class Meta: diff --git a/frontend/views.py b/frontend/views.py index 01b7bc87..c04d42dd 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -714,13 +714,11 @@ def manage_campaign(request, id, action='manage'): if request.method == 'POST' : if request.POST.has_key('add_premium') : - postcopy=request.POST.copy() - postcopy['type']='CU' - new_premium_form = CustomPremiumForm(data=postcopy) + new_premium_form = CustomPremiumForm(data=request.POST) if new_premium_form.is_valid(): new_premium_form.save() alerts.append(_('New premium has been added')) - new_premium_form = CustomPremiumForm(data={'campaign': campaign}) + new_premium_form = CustomPremiumForm(initial={'campaign': campaign}) else: alerts.append(_('New premium has not been added')) form = getManageCampaignForm(instance=campaign) @@ -764,7 +762,7 @@ def manage_campaign(request, id, action='manage'): selected_premium.save() alerts.append(_('Premium %s has been inactivated'% premium_to_stop)) form = getManageCampaignForm(instance=campaign) - new_premium_form = CustomPremiumForm(data={'campaign': campaign}) + new_premium_form = CustomPremiumForm(initial={'campaign': campaign}) elif request.POST.has_key('change_offer'): for offer in offers : if request.POST.has_key('offer_%d-work' % offer.id) : @@ -786,7 +784,7 @@ def manage_campaign(request, id, action='manage'): elif action =='mademobi': alerts.append('A MOBI file is being generated') form = getManageCampaignForm(instance=campaign, initial={'work_description':campaign.work.description}) - new_premium_form = CustomPremiumForm(data={'campaign': campaign}) + new_premium_form = CustomPremiumForm(initial={'campaign': campaign}) return render(request, 'manage_campaign.html', { 'campaign': campaign,