forked from CGM_Public/pretix_original
Allow to save invoice addresses and attendee profiles to customer account (#2084)
Co-authored-by: Raphael Michel <michel@rami.io> Co-authored-by: Richard Schreiber <wiffbi@gmail.com> Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
@@ -124,6 +124,22 @@ class InvoiceAddressForm(BaseInvoiceAddressForm):
|
||||
required_css_class = 'required'
|
||||
vat_warning = True
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
allow_save = kwargs.pop('allow_save', False)
|
||||
super().__init__(*args, **kwargs)
|
||||
if allow_save:
|
||||
self.fields['saved_id'] = forms.IntegerField(
|
||||
required=False,
|
||||
help_text=" ", # non-breaking-space, will be overwritten by JavaScript, needed here for HTML-output
|
||||
label=_("Save to address"),
|
||||
widget=forms.Select(choices=(("", _("Create new address")),))
|
||||
)
|
||||
self.fields['save'] = forms.BooleanField(
|
||||
label=_('Save address in my customer account for future purchases'),
|
||||
required=False,
|
||||
initial=False,
|
||||
)
|
||||
|
||||
|
||||
class InvoiceNameForm(InvoiceAddressForm):
|
||||
|
||||
@@ -142,6 +158,22 @@ class QuestionsForm(BaseQuestionsForm):
|
||||
"""
|
||||
required_css_class = 'required'
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
allow_save = kwargs.pop('allow_save', False)
|
||||
super().__init__(*args, **kwargs)
|
||||
if allow_save and self.fields:
|
||||
self.fields['save'] = forms.BooleanField(
|
||||
label=_('Save answers to my customer profiles for future purchases'),
|
||||
required=False,
|
||||
initial=False,
|
||||
)
|
||||
self.fields['saved_id'] = forms.IntegerField(
|
||||
required=False,
|
||||
help_text=" ", # non-breaking-space, will be overwritten by JavaScript, needed here for HTML-output
|
||||
label=_("Save to profile"),
|
||||
widget=forms.Select(choices=(("", _("Create new profile")),))
|
||||
)
|
||||
|
||||
|
||||
class AddOnRadioSelect(forms.RadioSelect):
|
||||
option_template_name = 'pretixpresale/forms/addon_choice_option.html'
|
||||
|
||||
@@ -29,11 +29,11 @@ from django.utils.safestring import mark_safe
|
||||
from django.utils.translation import pgettext
|
||||
|
||||
|
||||
def render_label(content, label_for=None, label_class=None, label_title='', label_id='', optional=False, is_valid=None):
|
||||
def render_label(content, label_for=None, label_class=None, label_title='', label_id='', optional=False, is_valid=None, attrs=None):
|
||||
"""
|
||||
Render a label with content
|
||||
"""
|
||||
attrs = {}
|
||||
attrs = attrs or {}
|
||||
if label_for:
|
||||
attrs['for'] = label_for
|
||||
if label_class:
|
||||
@@ -118,6 +118,7 @@ class CheckoutFieldRenderer(FieldRenderer):
|
||||
widget.attrs["aria-describedby"] = " ".join(help_ids)
|
||||
|
||||
def add_label(self, html):
|
||||
attrs = {}
|
||||
label = self.get_label()
|
||||
|
||||
if hasattr(self.field.field, '_show_required'):
|
||||
@@ -141,11 +142,15 @@ class CheckoutFieldRenderer(FieldRenderer):
|
||||
label_for = self.field.id_for_label
|
||||
label_id = ""
|
||||
|
||||
if hasattr(self.field.field, 'question') and self.field.field.question.identifier:
|
||||
attrs["data-identifier"] = self.field.field.question.identifier
|
||||
|
||||
html = render_label(
|
||||
label,
|
||||
label_for=label_for,
|
||||
label_class=self.get_label_class(),
|
||||
label_id=label_id,
|
||||
attrs=attrs,
|
||||
optional=not required and not isinstance(self.widget, CheckboxInput),
|
||||
is_valid=is_valid
|
||||
) + html
|
||||
|
||||
Reference in New Issue
Block a user