SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 5422470f authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Add model apimail.ComposedMessage

parent 1d70652a
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ from django.contrib import admin ...@@ -6,6 +6,7 @@ from django.contrib import admin
from .models import ( from .models import (
EmailAccount, EmailAccountAccess, EmailAccount, EmailAccountAccess,
ComposedMessage,
Event, Event,
StoredMessage, StoredMessageAttachment, StoredMessage, StoredMessageAttachment,
UserTag) UserTag)
...@@ -23,6 +24,12 @@ class EmailAccountAdmin(admin.ModelAdmin): ...@@ -23,6 +24,12 @@ class EmailAccountAdmin(admin.ModelAdmin):
admin.site.register(EmailAccount, EmailAccountAdmin) admin.site.register(EmailAccount, EmailAccountAdmin)
class ComposedMessageAdmin(admin.ModelAdmin):
pass
admin.site.register(ComposedMessage, ComposedMessageAdmin)
class EventAdmin(admin.ModelAdmin): class EventAdmin(admin.ModelAdmin):
pass pass
......
# Generated by Django 2.1.8 on 2020-01-26 15:09
from django.conf import settings
import django.contrib.postgres.fields
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import uuid
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('apimail', '0011_auto_20200118_0843'),
]
operations = [
migrations.CreateModel(
name='ComposedMessage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False)),
('created_on', models.DateTimeField(default=django.utils.timezone.now)),
('status', models.CharField(choices=[('draft', 'Draft'), ('ready', 'Ready for sending'), ('rendered', 'Rendered'), ('sent', 'Sent')], default='draft', max_length=8)),
('to_recipient', models.EmailField(max_length=254)),
('cc_recipients', django.contrib.postgres.fields.ArrayField(base_field=models.EmailField(max_length=254), blank=True, null=True, size=None)),
('bcc_recipients', django.contrib.postgres.fields.ArrayField(base_field=models.EmailField(max_length=254), blank=True, null=True, size=None)),
('subject', models.CharField(max_length=256)),
('body_text', models.TextField()),
('body_html', models.TextField(blank=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
('from_account', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='apimail.EmailAccount')),
],
),
]
...@@ -4,6 +4,8 @@ __license__ = "AGPL v3" ...@@ -4,6 +4,8 @@ __license__ = "AGPL v3"
from .account import EmailAccount, EmailAccountAccess from .account import EmailAccount, EmailAccountAccess
from .composed_message import ComposedMessage
from .event import Event from .event import Event
from .stored_message import StoredMessage, StoredMessageAttachment from .stored_message import StoredMessage, StoredMessageAttachment
......
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
import uuid as uuid_lib
from django.conf import settings
from django.contrib.postgres.fields import ArrayField
from django.db import models
from django.utils import timezone
class ComposedMessage(models.Model):
"""
An outgoing email message.
"""
STATUS_DRAFT = 'draft'
STATUS_READY = 'ready'
STATUS_RENDERED = 'rendered'
STATUS_SENT = 'sent'
STATUS_CHOICES = (
(STATUS_DRAFT, 'Draft'),
(STATUS_READY, 'Ready for sending'),
(STATUS_RENDERED, 'Rendered'),
(STATUS_SENT, 'Sent'),
)
uuid = models.UUIDField( # Used by the API to look up the record
db_index=True,
default=uuid_lib.uuid4,
editable=False)
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.PROTECT)
created_on = models.DateTimeField(default=timezone.now)
status = models.CharField(
max_length=8,
choices=STATUS_CHOICES,
default=STATUS_DRAFT)
from_account = models.ForeignKey(
'apimail.EmailAccount',
on_delete=models.PROTECT)
to_recipient = models.EmailField()
cc_recipients = ArrayField(
models.EmailField(),
blank=True, null=True)
bcc_recipients = ArrayField(
models.EmailField(),
blank=True, null=True)
subject = models.CharField(max_length=256)
body_text = models.TextField()
body_html = models.TextField(blank=True)
def __str__(self):
return '%s: %s (from %s to %s) [%s]' % (
self.created_on,
self.subject[:20],
self.from_account.email,
self.to_recipient,
self.get_status_display())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment