Exemple #1
0
class Inbox(SearchableAbstract):
    """Inbox model

    Object manager has a custom create() method to generate a random local part
    and a from_string() method to grab an Inbox object from the database given
    a string "inbox@domain"
    """
    inbox = models.CharField(
        max_length=64,
        validators=[validators.ProhibitNullCharactersValidator()])
    domain = models.ForeignKey(Domain, on_delete=models.PROTECT)
    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             null=True,
                             on_delete=models.SET_NULL)
    created = models.DateTimeField('Created')
    description = models.CharField(
        max_length=256,
        null=True,
        blank=True,
        validators=[validators.ProhibitNullCharactersValidator()])

    deleted = models.BooleanField(default=False)
    new = models.BooleanField(default=False)
    exclude_from_unified = models.BooleanField(
        default=False, verbose_name=_("Exclude from Unified Inbox"))
    disabled = models.BooleanField(
        default=False,
        verbose_name=_("Disable Inbox"),
        help_text=_("This Inbox will no longer receive emails."))
    pinned = models.BooleanField(default=False,
                                 verbose_name=_("Pin Inbox to top"))

    objects = InboxQuerySet.as_manager()

    _bool_label_order = ["new", "disabled", "pinned"]

    def get_bools_for_labels(self):
        for key in self._bool_label_order:
            yield (key, getattr(self, key))

    def __str__(self):
        return u"%s@%s" % (self.inbox, self.domain.domain)

    def __repr__(self):
        u_rep = str(self)
        if self.deleted:
            u_rep = "%s (deleted)" % u_rep
        return smart_str(u'<%s: %s>' % (self.__class__.__name__, u_rep),
                         errors="replace")

    def index_search_a(self):
        return self.description or ""

    def index_search_b(self):
        return str(self)

    class Meta:
        verbose_name_plural = "Inboxes"
        unique_together = (('inbox', 'domain'), )
        indexes = [GinIndex(fields=["search_tsv"])]
Exemple #2
0
class Inbox(models.Model):
    """Inbox model

    Object manager has a custom create() method to generate a random local part
    and a from_string() method to grab an Inbox object from the database given
    a string "inbox@domain"

    `flags` are "deleted" and "new".
    * "deleted" is obvious (and should be used instead of deleting the model)
    * "new" should be set when an email is added to the inbox and unset when
      the inbox is viewed
    * "disabled" is a bit like "deleted", but incoming mail will be deffered, not rejected
    """
    inbox = models.CharField(
        max_length=64,
        validators=[validators.ProhibitNullCharactersValidator()])
    domain = models.ForeignKey(Domain, on_delete=models.PROTECT)
    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             null=True,
                             on_delete=models.SET_NULL)
    created = models.DateTimeField('Created')
    flags = BitField(flags=("deleted", "new", "exclude_from_unified",
                            "disabled", "pinned"),
                     default=0)
    description = models.CharField(
        max_length=256,
        null=True,
        blank=True,
        validators=[validators.ProhibitNullCharactersValidator()])

    deleted = models.BooleanField(default=False)
    new = models.BooleanField(default=False)
    exclude_from_unified = models.BooleanField(default=False)
    disabled = models.BooleanField(default=False)
    pinned = models.BooleanField(default=False)

    objects = InboxQuerySet.as_manager()

    def __str__(self):
        return u"%s@%s" % (self.inbox, self.domain.domain)

    def __repr__(self):
        u_rep = six.text_type(self)
        if self.flags.deleted:
            u_rep = "%s (deleted)" % u_rep
        return smart_str(u'<%s: %s>' % (self.__class__.__name__, u_rep),
                         errors="replace")

    class Meta:
        verbose_name_plural = "Inboxes"
        unique_together = (('inbox', 'domain'), )