11# Generated by Django 5.1.15 on 2025-12-30 16:07
22
33from django .db import migrations
4- from notifications . signals import notify
4+ from django . utils import timezone
55from tqdm import tqdm
66
77from recoco import verbs
@@ -13,6 +13,8 @@ def convert_public_note_notifications(apps, schema_editor):
1313 Notification = apps .get_model ("notifications" , "Notification" )
1414 ContentType = apps .get_model ("contenttypes" , "ContentType" )
1515 Note = apps .get_model ("projects" , "Note" )
16+ User = apps .get_model ("auth" , "User" )
17+ Project = apps .get_model ("projects" , "Project" )
1618 public_note_verb = "a envoyé un message dans l'espace conversation"
1719 content_type = ContentType .objects .get_for_model (Note )
1820 for notif in tqdm (
@@ -37,20 +39,36 @@ def convert_public_note_notifications(apps, schema_editor):
3739 try :
3840 # get corresponding message to create its own notification
3941 message = Message .objects .get (
40- created = note .created_on , modified = note .updated_on , project = note .project
42+ created = note .created_on ,
43+ modified = note .updated_on ,
44+ project_id = note .project .pk ,
4145 )
42- notification = {
43- "sender" : notif .actor ,
44- "verb" : verbs .Conversation .POST_MESSAGE ,
45- "action_object" : message ,
46- "target" : notif .target ,
47- "annotations" : gather_annotations_for_message_notification (message ),
48- "emailed" : notif .emailed ,
49- }
5046
51- notify .send (recipient = notif .recipient , site = notif .site , ** notification )
47+ Notification (
48+ recipient = notif .recipient ,
49+ actor_content_type = ContentType .objects .get_for_model (User ),
50+ actor_object_id = notif .actor_object_id ,
51+ target_object_id = notif .target_object_id ,
52+ target_content_type = ContentType .objects .get_for_model (Project ),
53+ action_object_object_id = message .id ,
54+ action_object_content_type = ContentType .objects .get_for_model (Message ),
55+ verb = verbs .Conversation .POST_MESSAGE ,
56+ public = True ,
57+ description = None ,
58+ data = {
59+ "annotations" : gather_annotations_for_message_notification (message )
60+ },
61+ emailed = notif .emailed ,
62+ timestamp = timezone .now (),
63+ level = "info" ,
64+ site_id = notif .site_id ,
65+ )
66+
67+ # notify.send(recipient=notif.recipient, site_id=notif.site.id, **notification)
5268 except Message .DoesNotExist :
5369 print (f"no message found for { note } . skipped" )
70+ except User .DoesNotExist :
71+ print (f"sender not found for { note } . skipped" )
5472
5573
5674class Migration (migrations .Migration ):
0 commit comments