Example #1
0
class PersonContactBaseForm(ContactBaseFormMixin, forms.ModelForm):
    language = LanguageFormField(label=_("Language"), required=False, include_blank=True, help_text=_(
        "The primary language to be used in all communications with the contact."
    ))

    class Meta:
        model = PersonContact
        fields = list(FIELDS_BY_MODEL_NAME["PersonContact"]) + list(FIELDS_BY_MODEL_NAME["Contact"])

    def __init__(self, user=None, *args, **kwargs):
        self.user = user
        self.request = kwargs.pop("request", None)
        super(PersonContactBaseForm, self).__init__(*args, **kwargs)

    def init_fields(self):
        super(PersonContactBaseForm, self).init_fields()
        for field_name in ("first_name", "last_name"):
            self.fields[field_name].required = True
        self.initial["language"] = self.instance.language

    def save(self, commit=True):
        self.instance.name = self.cleaned_data["first_name"] + " " + self.cleaned_data["last_name"]
        self.instance.language = self.cleaned_data["language"]
        obj = super(PersonContactBaseForm, self).save(commit)
        if self.user and not getattr(obj, "user", None):  # Allow binding only once
            obj.user = self.user
            obj.save()
        return obj
Example #2
0
class PersonContactForm(forms.ModelForm):
    language = LanguageFormField(label=_("Language"), required=False)

    class Meta:
        model = PersonContact
        fields = ("first_name", "last_name", "phone", "email", "gender",
                  "language", "marketing_permission", "picture")

    def __init__(self, *args, **kwargs):
        super(PersonContactForm, self).__init__(*args, **kwargs)
        for field in ("first_name", "last_name", "email"):
            self.fields[field].required = True
        self.initial["language"] = self.instance.language

        if settings.SHUUP_CUSTOMER_INFORMATION_ALLOW_PICTURE_UPLOAD:
            self.fields["picture"].widget = PictureDnDUploaderWidget(
                clearable=True)
        else:
            self.fields.pop("picture")

        field_properties = settings.SHUUP_PERSON_CONTACT_FIELD_PROPERTIES
        for field, properties in field_properties.items():
            for prop in properties:
                setattr(self.fields[field], prop, properties[prop])

    def save(self, commit=True):
        self.instance.language = self.cleaned_data["language"]
        return super(PersonContactForm, self).save(commit)
Example #3
0
class PersonContactForm(forms.ModelForm):
    language = LanguageFormField(label=_("Language"), required=False)

    class Meta:
        model = PersonContact
        fields = ("first_name", "last_name", "phone", "email", "gender",
                  "language", "marketing_permission")

    def __init__(self, *args, **kwargs):
        super(PersonContactForm, self).__init__(*args, **kwargs)
        for field in ("first_name", "last_name", "email"):
            self.fields[field].required = True
        self.initial["language"] = self.instance.language

    def save(self, commit=True):
        self.instance.language = self.cleaned_data["language"]
        return super(PersonContactForm, self).save(commit)
Example #4
0
class PersonContactForm(forms.ModelForm):
    language = LanguageFormField(label=_("Language"), required=False)

    class Meta:
        model = PersonContact
        fields = ("first_name", "last_name", "phone", "email", "gender", "language", "marketing_permission")

    def __init__(self, *args, **kwargs):
        super(PersonContactForm, self).__init__(*args, **kwargs)
        for field in ("first_name", "last_name", "email"):
            self.fields[field].required = True
        self.initial["language"] = self.instance.language

        field_properties = settings.SHUUP_PERSON_CONTACT_FIELD_PROPERTIES
        for field, properties in field_properties.items():
            for prop in properties:
                setattr(self.fields[field], prop, properties[prop])

    def save(self, commit=True):
        self.instance.language = self.cleaned_data["language"]
        return super(PersonContactForm, self).save(commit)