1 from django.db import models
2 from django.utils.translation import ugettext_lazy as _
3 from . import BASE_DOMAINS
7 class Alias(models.Model):
8 source = models.EmailField(_('source'), db_index=True)
9 destination = models.EmailField(_('destination'))
10 mode = models.CharField(
11 _('mode'), max_length=255, default='', blank=True, choices=[
12 ('', _('Forward everything')),
13 ('@FORWARD', _('Do not forward e-mail marked as spam.'))
17 verbose_name = _('alias')
18 verbose_name_plural = _('aliases')
19 ordering = ('source', 'destination')
22 return '{} -> {}'.format(self.source, self.destination)
25 def get_from_user(cls, user):
26 lookups = ["{}@{}".format(user.username, domain) for domain in BASE_DOMAINS]
27 return cls.objects.filter(source__in=lookups)
30 def get_to_user(cls, user):
31 lookups = ["{}@{}".format(user.username, domain) for domain in BASE_DOMAINS]
32 return cls.objects.filter(destination__in=lookups)