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

@ -113,7 +113,8 @@ class Member(models.Model):
@property @property
def association_email(self): def association_email(self):
"""Returning the association email of the member""" """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): def get_group(self):
"""Returns a string of groups in which the member is.""" """Returns a string of groups in which the member is."""

Loading…
Cancel
Save