diff --git a/jdav_web/members/management/commands/get_forward_addrs.py b/jdav_web/members/management/commands/get_forward_addrs.py new file mode 100644 index 0000000..618c654 --- /dev/null +++ b/jdav_web/members/management/commands/get_forward_addrs.py @@ -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 diff --git a/jdav_web/members/models.py b/jdav_web/members/models.py index 80ec5a8..9c17607 100644 --- a/jdav_web/members/models.py +++ b/jdav_web/members/models.py @@ -4,10 +4,12 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ from django.utils import timezone from utils import RestrictedFileField +import os GEMEINSCHAFTS_TOUR = 0 FUEHRUNGS_TOUR = 1 AUSBILDUNGS_TOUR = 2 +HOST = os.environ.get('DJANGO_ALLOWED_HOST', 'localhost:8000').split(",")[0] class ActivityCategory(models.Model): @@ -108,6 +110,11 @@ class Member(models.Model): """Returning the whole place (plz + 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): """Returns a string of groups in which the member is.""" groupstring = ''.join(g.name + ',\n' for g in self.group.all())