handle umlaute in association emails

v1-0-stable
Christian Merten 6 years ago
parent 12b92c3e35
commit 728936052f

@ -1,6 +1,5 @@
from django.core.management.base import BaseCommand
from members.models import Member
from django.db.models import Q
import re
@ -19,10 +18,10 @@ class Command(BaseCommand):
prename, lastname = match.groups()
try:
jugendleiter = Member.objects.filter(group__name='Jugendleiter')
matching = [jl.email for jl in jugendleiter if matches(jl.prename.lower(),
jl.lastname.lower(),
prename.lower(),
lastname.lower())]
matching = [jl.email for jl in jugendleiter if matches(simplify(jl.prename),
simplify(jl.lastname),
simplify(prename),
simplify(lastname))]
if not matching:
return
self.stdout.write(" ".join(matching))
@ -30,6 +29,10 @@ class Command(BaseCommand):
pass
def simplify(name):
return name.lower().replace('ä', 'ae').replace('ö', 'oe').replace('ü', 'ue')
def matches(prename, lastname, matched_pre, matched_last):
if not matched_last and matched_pre and len(matched_pre) > 2:
return prename.startswith(matched_pre) or lastname.startswith(matched_pre)

@ -113,7 +113,8 @@ class Member(models.Model):
@property
def association_email(self):
"""Returning the association email of the member"""
return "{0}.{1}@{2}".format(self.prename.lower(), self.lastname.lower(), HOST)
raw = "{0}.{1}@{2}".format(self.prename.lower(), self.lastname.lower(), HOST)
return raw.replace('ö', 'oe').replace('ä', 'ae').replace('ü', 'ue')
def get_group(self):
"""Returns a string of groups in which the member is."""

Loading…
Cancel
Save