X-Git-Url: https://git.mdrn.pl/cas.git/blobdiff_plain/d7b22d05953c0f6380f44693d08d3cd92e40fb09..122f148a7c94368973e13f0d868f3e520a544d01:/src/emails/models.py?ds=inline diff --git a/src/emails/models.py b/src/emails/models.py index f44939f..b666162 100644 --- a/src/emails/models.py +++ b/src/emails/models.py @@ -1,10 +1,17 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ +from . import BASE_DOMAINS + class Alias(models.Model): source = models.EmailField(_('source'), db_index=True) destination = models.EmailField(_('destination')) + mode = models.CharField( + _('mode'), max_length=255, default='', blank=True, choices=[ + ('', _('Forward everything')), + ('@FORWARD', _('Do not forward e-mail marked as spam.')) + ]) class Meta: verbose_name = _('alias') @@ -13,3 +20,13 @@ class Alias(models.Model): def __str__(self): return '{} -> {}'.format(self.source, self.destination) + + @classmethod + def get_from_user(cls, user): + lookups = ["{}@{}".format(user.username, domain) for domain in BASE_DOMAINS] + return cls.objects.filter(source__in=lookups) + + @classmethod + def get_to_user(cls, user): + lookups = ["{}@{}".format(user.username, domain) for domain in BASE_DOMAINS] + return cls.objects.filter(destination__in=lookups)