Skip to content

Commit

Permalink
Name formats: Allow empty salutation (#3801)
Browse files Browse the repository at this point in the history
* Name formats: Allow empty salutation

* Update src/pretix/base/forms/questions.py

Co-authored-by: Felix Rindt <felix@rindt.me>

---------

Co-authored-by: Felix Rindt <felix@rindt.me>
  • Loading branch information
raphaelm and felixrindt committed Jan 9, 2024
1 parent 2c67b82 commit 8a155d5
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/pretix/base/forms/questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(self, scheme: dict, field: forms.Field, attrs=None, titles: list=No
if fname == 'title' and self.titles:
widgets.append(Select(attrs=a, choices=[('', '')] + [(d, d) for d in self.titles[1]]))
elif fname == 'salutation':
widgets.append(Select(attrs=a, choices=[('', '---')] + PERSON_NAME_SALUTATIONS))
widgets.append(Select(attrs=a, choices=[('', '---'), ('empty', '')] + PERSON_NAME_SALUTATIONS))
else:
widgets.append(self.widget(attrs=a))
super().__init__(widgets, attrs)
Expand All @@ -136,7 +136,10 @@ def decompress(self, value):
data = []
for i, field in enumerate(self.scheme['fields']):
fname, label, size = field
data.append(value.get(fname, ""))
fval = value.get(fname, "")
if fname == "salutation" and fname in value and fval == "":
fval = "empty"
data.append(fval)
if '_legacy' in value and not data[-1]:
data[-1] = value.get('_legacy', '')
elif not any(d for d in data) and '_scheme' in value:
Expand Down Expand Up @@ -190,7 +193,8 @@ def compress(self, data_list) -> dict:
data = {}
data['_scheme'] = self.scheme_name
for i, value in enumerate(data_list):
data[self.scheme['fields'][i][0]] = value or ''
key = self.scheme['fields'][i][0]
data[key] = value or ''
return data

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -239,7 +243,7 @@ def __init__(self, *args, **kwargs):
d.pop('validators', None)
field = forms.ChoiceField(
**d,
choices=[('', '---')] + PERSON_NAME_SALUTATIONS
choices=[('', '---'), ('empty', '')] + PERSON_NAME_SALUTATIONS
)
else:
field = forms.CharField(**defaults)
Expand All @@ -265,6 +269,9 @@ def clean(self, value) -> dict:
if sum(len(v) for v in value.values() if v) > 250:
raise forms.ValidationError(_('Please enter a shorter name.'), code='max_length')

if value.get("salutation") == "empty":
value["salutation"] = ""

return value


Expand Down

0 comments on commit 8a155d5

Please sign in to comment.