Skip to content

Commit cc1069d

Browse files
committed
Implement Draft SentEmail
1 parent 29c9381 commit cc1069d

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

backend/notifications/admin/admins.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
from notifications.models import EmailTemplate, SentEmail, SentEmailEvent
1717
from django.forms import Textarea
18+
from django.db.models import QuerySet
19+
from notifications.tasks import send_pending_email
1820

1921

2022
class SentEmailEventInline(admin.TabularInline):
@@ -146,6 +148,7 @@ class SentEmailAdmin(admin.ModelAdmin):
146148
ordering = ["-sent_at"]
147149
autocomplete_fields = ["recipient"]
148150
inlines = [SentEmailEventInline]
151+
actions = ["send_email"]
149152

150153
def email_template_display_name(self, obj):
151154
if obj.email_template.is_custom:
@@ -182,3 +185,14 @@ def get_queryset(self, request: HttpRequest) -> Any:
182185
qs = qs.filter(email_template__is_system_template=False)
183186

184187
return qs
188+
189+
def send_email(self, request: HttpRequest, queryset: QuerySet[SentEmail]):
190+
affected_emails = queryset.filter(status=SentEmail.Status.draft)
191+
for sent_email in affected_emails:
192+
sent_email.status = SentEmail.Status.pending
193+
sent_email.save(update_fields=["status"])
194+
send_pending_email.delay(sent_email.id)
195+
196+
self.message_user(
197+
request, f"Emails sent successfully: {affected_emails.count()}"
198+
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.2.8 on 2026-08-15 10:04
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('notifications', '0022_remove_grant_voucher_code_template_identifier'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='sentemail',
15+
name='status',
16+
field=models.CharField(choices=[('draft', 'Draft'), ('pending', 'Pending'), ('sent', 'Sent'), ('failed', 'Failed')], db_index=True, default='pending', max_length=200, verbose_name='status'),
17+
),
18+
]

backend/notifications/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ class Meta:
284284

285285
class SentEmail(TimeStampedModel):
286286
class Status(models.TextChoices):
287+
draft = "draft", _("Draft")
287288
pending = "pending", _("Pending")
288289
sent = "sent", _("Sent")
289290
failed = "failed", _("Failed")

0 commit comments

Comments
 (0)