add association email adresses, include parsing emails to find jugendleiters

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

@ -0,0 +1,38 @@
from django.core.management.base import BaseCommand
from members.models import Member
from django.db.models import Q
import re
class Command(BaseCommand):
help = 'Parses an email address and finds the associated jugendleiter'
requires_system_checks = False
def add_arguments(self, parser):
parser.add_argument('--name', default="")
def handle(self, *args, **options):
match = re.match('([A-Za-z0-9]*)[ ._-]*(.*)', options['name'])
if not match:
return
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())]
if not matching:
return
self.stdout.write(" ".join(matching))
except Member.DoesNotExist:
pass
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)
if matched_pre and matched_last:
return (prename.startswith(matched_pre) and lastname.startswith(matched_last)) or (prename.startswith(matched_last) and lastname.startswith(matched_pre))
return False

@ -4,10 +4,12 @@ from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils import timezone from django.utils import timezone
from utils import RestrictedFileField from utils import RestrictedFileField
import os
GEMEINSCHAFTS_TOUR = 0 GEMEINSCHAFTS_TOUR = 0
FUEHRUNGS_TOUR = 1 FUEHRUNGS_TOUR = 1
AUSBILDUNGS_TOUR = 2 AUSBILDUNGS_TOUR = 2
HOST = os.environ.get('DJANGO_ALLOWED_HOST', 'localhost:8000').split(",")[0]
class ActivityCategory(models.Model): class ActivityCategory(models.Model):
@ -108,6 +110,11 @@ class Member(models.Model):
"""Returning the whole place (plz + town)""" """Returning the whole place (plz + town)"""
return "{0} {1}".format(self.plz, self.town) return "{0} {1}".format(self.plz, self.town)
@property
def association_email(self):
"""Returning the association email of the member"""
return "{0}.{1}@{2}".format(self.prename.lower(), self.lastname.lower(), HOST)
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."""
groupstring = ''.join(g.name + ',\n' for g in self.group.all()) groupstring = ''.join(g.name + ',\n' for g in self.group.all())

Loading…
Cancel
Save