mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
Add salutation "Mx", normalize salutations (save in English, localize on display) (#2075)
* normalize salutations and localize before use * add migration to normalize salutations * add placeholder "name_for_salutation" for emails
This commit is contained in:
committed by
GitHub
parent
cf9fd47d2b
commit
8c07fa75e4
62
src/pretix/base/migrations/0187_normalize_salutation.py
Normal file
62
src/pretix/base/migrations/0187_normalize_salutation.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# Generated by Django 3.2.2 on 2021-05-11 06:55
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations
|
||||
from django.utils.translation import pgettext
|
||||
|
||||
from pretix.base.i18n import language
|
||||
from pretix.base.settings import PERSON_NAME_SALUTATIONS
|
||||
|
||||
|
||||
def normalize_salutations(apps, schema_editor):
|
||||
models = (
|
||||
("pretixbase", "Customer", "name_parts"),
|
||||
("pretixbase", "InvoiceAddress", "name_parts"),
|
||||
("pretixbase", "Membership", "attendee_name_parts"),
|
||||
("pretixbase", "CartPosition", "attendee_name_parts"),
|
||||
("pretixbase", "OrderPosition", "attendee_name_parts"),
|
||||
("pretix_exhibitors", "Exhibitor", "contact_name_parts"),
|
||||
)
|
||||
|
||||
for salutation, value in PERSON_NAME_SALUTATIONS:
|
||||
salutations = []
|
||||
for lang in settings.LANGUAGES:
|
||||
with language(lang[0]):
|
||||
salutation_localized = pgettext("person_name_salutation", salutation)
|
||||
if (
|
||||
salutation_localized != salutation
|
||||
and salutation_localized not in salutations
|
||||
):
|
||||
salutations.append(salutation_localized)
|
||||
|
||||
for app, model, key in models:
|
||||
sort_params = {}
|
||||
sort_params["{}__salutation__in".format(key)] = salutations
|
||||
try:
|
||||
m = apps.get_model(app, model)
|
||||
except LookupError:
|
||||
continue
|
||||
try:
|
||||
qs = m.objects
|
||||
except AttributeError:
|
||||
qs = m.all
|
||||
|
||||
for o in qs.filter(**sort_params):
|
||||
val = getattr(o, key)
|
||||
val["salutation"] = salutation
|
||||
setattr(o, key, val)
|
||||
o.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("pretixbase", "0186_invoice_sent_to_organizer"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
normalize_salutations,
|
||||
migrations.RunPython.noop,
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user