summaryrefslogtreecommitdiff
path: root/members/forms.py
blob: 3124ae7b9c5c3127fde2a7b314f25bd4c9dd965b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from django import forms
from django.conf import settings
from django.core.mail import send_mail
from django.utils.translation import gettext_lazy as _

from .models import CorporateMember


class CorporateMemberSignUpForm(forms.ModelForm):
    amount = forms.IntegerField(
        label=_("Donation amount"),
        help_text=_("Enter an integer in US$ without the dollar sign."),
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.checkbox_fields = []
        self.radio_select_fields = []
        self.label_fields = []
        self.fields["logo"].required = True
        self.fields["django_usage"].required = True
        for name, field in self.fields.items():
            help_text = field.help_text
            if help_text:
                help_text = " (" + help_text + ")"
                self.fields[name].help_text = ""
            self.fields[name].widget.attrs = {"placeholder": field.label + help_text}

            if isinstance(field.widget, forms.CheckboxInput):
                self.checkbox_fields.append(name)
            elif isinstance(field.widget, forms.RadioSelect):
                self.radio_select_fields.append(name)
            elif isinstance(field.widget, (forms.FileInput, forms.Select)):
                self.label_fields.append(name)

        self.fields["billing_name"].widget.attrs["placeholder"] = _(
            "Billing name (If different from above name)."
        )
        self.fields["billing_name"].help_text = _(
            "For example, this might be your full registered company name."
        )
        self.fields["display_name"].widget.attrs["placeholder"] = _(
            "Your organization's name as you'd like it to appear on our website."
        )
        self.fields["address"].widget.attrs["placeholder"] = _("Mailing address")
        self.fields["address"].help_text = _(
            "We can send the invoice by email, but we need a contact address."
        )
        self.fields["description"].widget.attrs["placeholder"] = _(
            "A short paragraph that describes your organization and its "
            "activities, written as if the DSF were describing your company "
            "to a third party."
        )
        self.fields["description"].help_text = _(
            """We'll use this text on the
            <a href="https://www.djangoproject.com/foundation/corporate-members/">
            corporate membership page</a>; you can use the existing descriptions
            as a guide for flavor we're looking for."""
        )
        self.fields["django_usage"].widget.attrs["placeholder"] = _(
            "How does your organization use Django?"
        )
        self.fields["django_usage"].help_text = _(
            "This won't be displayed publicly but helps the DSF Board "
            "to evaluate your application."
        )
        self.fields["amount"].help_text = _(
            """Enter an amount above and the appropriate membership level will
            be automatically selected. Or select a membership level below and
            the minimum donation will be entered for you. See <a
            href="https://www.djangoproject.com/foundation/corporate-membership/#dues"
            >dues</a> for details on the levels."""
        )

    class Meta:
        fields = [
            "display_name",
            "billing_name",
            "logo",
            "url",
            "contact_name",
            "contact_email",
            "billing_email",
            "address",
            "description",
            "django_usage",
            "amount",
            "membership_level",
        ]
        model = CorporateMember

    @property
    def is_renewing(self):
        return not self.instance._state.adding

    def save(self, *args, **kwargs):
        is_renewing = self.is_renewing  # self.is_renewing changes after super()
        instance = super().save(*args, **kwargs)
        display_name = self.instance.display_name
        if is_renewing:
            subject = _("Django Corporate Membership Renewal: %s") % display_name
            content = _(
                "Thanks for renewing as a corporate member of the "
                "Django Software Foundation! "
                "Your renewal is received, and we'll follow up with an invoice soon."
            )
        else:
            subject = _("Django Corporate Membership Application: %s") % display_name
            content = _(
                "Thanks for applying to be a corporate member of the "
                "Django Software Foundation! "
                "Your application is being reviewed, and we'll follow up a "
                "response from the board after our next monthly meeting."
            )
        send_mail(
            subject,
            content,
            settings.FUNDRAISING_DEFAULT_FROM_EMAIL,
            [
                settings.FUNDRAISING_DEFAULT_FROM_EMAIL,
                self.instance.contact_email,
                "treasurer@djangoproject.com",
                "dsf-board@googlegroups.com",
            ],
        )
        instance.invoice_set.create(amount=self.cleaned_data["amount"])
        return instance