X-Git-Url: https://git.mdrn.pl/cas.git/blobdiff_plain/53c0f2de2c0447a5b7518e1a0ac2d09461930ae8..02e4db2d5557aac2b27a4cce164adc6f22f5d0cf:/src/emails/models.py?ds=sidebyside diff --git a/src/emails/models.py b/src/emails/models.py index 988b5a1..b666162 100644 --- a/src/emails/models.py +++ b/src/emails/models.py @@ -1,5 +1,7 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ +from . import BASE_DOMAINS + class Alias(models.Model): @@ -18,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)