Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
1.4 kB
1
Indexable
Never
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.contrib.postgres.fields import ArrayField


class User(AbstractUser):
    # Lock an account by setting obj.is_active to False.
    email_verified = models.BooleanField(default=False)
    default_workdays = models.CharField(max_length=14, default="2,3,4,5,6")
    default_workday_minutes = models.IntegerField(default=480)


class EmailAccount(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    address = models.URLField()
    category = models.ForeignKey('workdesk.Category', models.CASCADE, null=True, blank=True)
    access_token = models.CharField(max_length=256)
    refresh_token = models.CharField(max_length=256)
    prior_weeks_to_fetch = models.IntegerField(default=4)
    incoming_messages = ArrayField(models.CharField(max_length=64), blank=True, null=True)
    open_tokens = ArrayField(models.CharField(max_length=24), blank=True, null=True)
    open_query = models.CharField(max_length=48, blank=True, null=True)

    def get_open_tokens(self):
        return self.open_tokens if self.open_tokens else []

    def append_token(self, token):
        if self.open_tokens:
            self.open_tokens.append(token)
        else:
            self.open_tokens = [token]

    def get_incoming_messages(self):
        return self.incoming_messages if self.incoming_messages else []
Leave a Comment