From a8ac3655d4de8bc71f292a69e3b45782e5d5aa12 Mon Sep 17 00:00:00 2001 From: jefer94 Date: Wed, 18 Sep 2024 13:22:46 -0500 Subject: [PATCH] add admin --- breathecode/notify/admin.py | 20 +++++- .../notify/migrations/0013_notification.py | 65 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 breathecode/notify/migrations/0013_notification.py diff --git a/breathecode/notify/admin.py b/breathecode/notify/admin.py index 662cbef2a..640a0982e 100644 --- a/breathecode/notify/admin.py +++ b/breathecode/notify/admin.py @@ -11,7 +11,17 @@ from breathecode.utils import AdminExportCsvMixin from .actions import send_slack, sync_slack_team_channel -from .models import CohortProxy, Device, HookError, SlackChannel, SlackTeam, SlackUser, SlackUserTeam, UserProxy +from .models import ( + CohortProxy, + Device, + HookError, + Notification, + SlackChannel, + SlackTeam, + SlackUser, + SlackUserTeam, + UserProxy, +) from .tasks import async_slack_team_users from .utils.hook_manager import HookManager @@ -181,3 +191,11 @@ class HookErrorAdmin(admin.ModelAdmin): list_display = ["event", "message", "created_at", "updated_at"] search_fields = ["message", "event"] list_filter = ["event"] + + +@admin.register(Notification) +class NotificationAdmin(admin.ModelAdmin): + list_display = ("operation_code", "status", "type", "user", "academy", "done_at", "sent_at", "seen_at") + search_fields = ("operation_code", "message", "user__username", "user__email", "academy__name") + list_filter = ("status", "type") + raw_id_fields = ("user", "academy") diff --git a/breathecode/notify/migrations/0013_notification.py b/breathecode/notify/migrations/0013_notification.py new file mode 100644 index 000000000..5519dedd4 --- /dev/null +++ b/breathecode/notify/migrations/0013_notification.py @@ -0,0 +1,65 @@ +# Generated by Django 5.1.1 on 2024-09-18 18:22 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("admissions", "0064_academy_legal_name"), + ("notify", "0012_hookerror"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name="Notification", + fields=[ + ("id", models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), + ("operation_code", models.CharField(max_length=20)), + ("message", models.TextField(blank=True, default=None, null=True)), + ("meta", models.JSONField(blank=True, default=None, null=True)), + ( + "status", + models.CharField( + choices=[("PENDING", "Pending"), ("DONE", "Done"), ("SENT", "Sent"), ("SEEN", "Seen")], + default="PENDING", + max_length=10, + ), + ), + ( + "type", + models.CharField( + choices=[("INFO", "Info"), ("WARNING", "Warning"), ("ERROR", "Error")], + default="INFO", + max_length=10, + ), + ), + ("done_at", models.DateTimeField(blank=True, default=None, null=True)), + ("sent_at", models.DateTimeField(blank=True, default=None, null=True)), + ("seen_at", models.DateTimeField(blank=True, default=None, null=True)), + ( + "academy", + models.ForeignKey( + blank=True, + default=None, + null=True, + on_delete=django.db.models.deletion.CASCADE, + to="admissions.academy", + ), + ), + ( + "user", + models.ForeignKey( + blank=True, + default=None, + null=True, + on_delete=django.db.models.deletion.CASCADE, + to=settings.AUTH_USER_MODEL, + ), + ), + ], + ), + ]