Change notification backend
This commit is contained in:
parent
5f97491f0d
commit
7f854c40dd
15 changed files with 188 additions and 134 deletions
68
judge/migrations/0171_update_notification.py
Normal file
68
judge/migrations/0171_update_notification.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
# Generated by Django 3.2.18 on 2023-10-10 21:17
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
from django.urls import reverse
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
# Run this in shell
|
||||
def migrate_notif(apps, schema_editor):
|
||||
Notification = apps.get_model("judge", "Notification")
|
||||
Profile = apps.get_model("judge", "Profile")
|
||||
NotificationProfile = apps.get_model("judge", "NotificationProfile")
|
||||
|
||||
unread_count = defaultdict(int)
|
||||
for c in Notification.objects.all():
|
||||
if c.comment:
|
||||
c.html_link = (
|
||||
f'<a href="{c.comment.get_absolute_url()}">{c.comment.page_title}</a>'
|
||||
)
|
||||
c.author = c.comment.author
|
||||
c.save()
|
||||
if c.read is False:
|
||||
unread_count[c.author] += 1
|
||||
|
||||
for user in unread_count:
|
||||
np = NotificationProfile(user=user)
|
||||
np.unread_count = unread_count[user]
|
||||
np.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("judge", "0170_contests_summary"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterModelOptions(
|
||||
name="contestssummary",
|
||||
options={
|
||||
"verbose_name": "contests summary",
|
||||
"verbose_name_plural": "contests summaries",
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="NotificationProfile",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.AutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("unread_count", models.IntegerField(default=0)),
|
||||
(
|
||||
"user",
|
||||
models.OneToOneField(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="judge.profile"
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue