From 4fc494783dd178bda6c912c0771480b8bff154e6 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Mon, 9 Jan 2017 19:27:47 +1100 Subject: [PATCH] Refactors the email form into an InvoicesWithProductAndStatus form --- registrasion/forms.py | 47 +++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/registrasion/forms.py b/registrasion/forms.py index 25a54768..684f7550 100644 --- a/registrasion/forms.py +++ b/registrasion/forms.py @@ -413,31 +413,11 @@ def staff_products_formset_factory(user): return forms.formset_factory(form_type) -class InvoiceEmailForm(forms.Form): - - ACTION_PREVIEW = 1 - ACTION_SEND = 2 - - ACTION_CHOICES = ( - (ACTION_PREVIEW, "Preview"), - (ACTION_SEND, "Send emails"), - ) - +class InvoicesWithProductAndStatusForm(forms.Form): invoice = forms.ModelMultipleChoiceField( widget=forms.CheckboxSelectMultiple, queryset=commerce.Invoice.objects.all(), ) - from_email = forms.CharField() - subject = forms.CharField() - body = forms.CharField( - widget=forms.Textarea, - ) - action = forms.TypedChoiceField( - widget=forms.RadioSelect, - coerce=int, - choices=ACTION_CHOICES, - initial=ACTION_PREVIEW, - ) def __init__(self, *a, **k): category = k.pop('category', None) or [] @@ -447,7 +427,7 @@ class InvoiceEmailForm(forms.Form): category = [int(i) for i in category] product = [int(i) for i in product] - super(InvoiceEmailForm, self).__init__(*a, **k) + super(InvoicesWithProductAndStatusForm, self).__init__(*a, **k) print status qs = commerce.Invoice.objects.filter( @@ -464,3 +444,26 @@ class InvoiceEmailForm(forms.Form): self.fields['invoice'].queryset = qs self.fields['invoice'].initial = [i.id for i in qs] + + +class InvoiceEmailForm(InvoicesWithProductAndStatusForm): + + ACTION_PREVIEW = 1 + ACTION_SEND = 2 + + ACTION_CHOICES = ( + (ACTION_PREVIEW, "Preview"), + (ACTION_SEND, "Send emails"), + ) + + from_email = forms.CharField() + subject = forms.CharField() + body = forms.CharField( + widget=forms.Textarea, + ) + action = forms.TypedChoiceField( + widget=forms.RadioSelect, + coerce=int, + choices=ACTION_CHOICES, + initial=ACTION_PREVIEW, + )