-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
69 lines (57 loc) · 2.33 KB
/
models.py
File metadata and controls
69 lines (57 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import uuid
from django.conf import settings
from django.db import models
from .constants import get_default_mailing_schema
def get_template_path(instance, filename):
ext = filename.split(".")[-1]
filename = "%s.%s" % (uuid.uuid4(), ext)
return os.path.join("templates/mailing/emails", filename)
class MailingSchema(models.Model):
name = models.CharField(max_length=100, unique=True)
schema = models.JSONField(default=get_default_mailing_schema, null=True, blank=True)
template = models.TextField()
class Meta:
verbose_name = "Схема шаблона письма"
verbose_name_plural = "Схемы шаблонов писем"
def __str__(self):
return f"MailingSchema<{self.name}>"
class MailingScenarioLog(models.Model):
class Status(models.TextChoices):
PENDING = "pending", "Pending"
SENT = "sent", "Sent"
FAILED = "failed", "Failed"
scenario_code = models.CharField(max_length=128)
program = models.ForeignKey(
"partner_programs.PartnerProgram",
on_delete=models.CASCADE,
related_name="mailing_scenario_logs",
)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name="mailing_scenario_logs",
)
scheduled_for = models.DateField()
status = models.CharField(
max_length=16, choices=Status.choices, default=Status.PENDING
)
sent_at = models.DateTimeField(null=True, blank=True)
error = models.TextField(null=True, blank=True)
datetime_created = models.DateTimeField(auto_now_add=True)
datetime_updated = models.DateTimeField(auto_now=True)
class Meta:
verbose_name = "Лог сценария рассылки"
verbose_name_plural = "Логи сценариев рассылки"
unique_together = ("scenario_code", "program", "user", "scheduled_for")
indexes = [
models.Index(fields=["scenario_code", "scheduled_for"]),
models.Index(fields=["program", "scheduled_for"]),
models.Index(fields=["user", "scheduled_for"]),
]
def __str__(self):
return (
f"MailingScenarioLog<{self.scenario_code}> "
f"program={self.program_id} user={self.user_id} "
f"date={self.scheduled_for} status={self.status}"
)