11# Generated by Django 5.1.15 on 2026-02-27 14:38
2-
2+ from django . conf import settings
33from django .db import migrations
44from django .db .models import (
55 Subquery ,
@@ -23,6 +23,7 @@ def specialize_verbs(apps, schema_editor):
2323 Document = apps .get_model ("projects" , "Document" )
2424 Project = apps .get_model ("projects" , "Project" )
2525 Group = apps .get_model ("auth" , "Group" )
26+ Site = apps .get_model ("sites" , "Site" )
2627
2728 # Document.ADDED
2829 submitter_type_sq = Subquery (
@@ -38,18 +39,25 @@ def specialize_verbs(apps, schema_editor):
3839 )
3940 .values_list ("doc_type" , flat = True )[:1 ]
4041 )
41- query_added = Action .objects .annotate (
42- action_document_type = submitter_type_sq
43- ).filter (verb = "a ajouté un lien ou un document" )
4442
45- print ("Transforming some Document.ADDED to Document.ADDED_FILE" )
46- query_added .filter (action_document_type = "FILE" ).update (
47- verb = verbs .Document .ADDED_FILE
48- )
49- print ("Transforming some Document.ADDED to Document.ADDED_LINK" )
50- query_added .filter (action_document_type = "LINK" ).update (
51- verb = verbs .Document .ADDED_LINK
52- )
43+ for site in Site .objects .all ():
44+ with settings .SITE_ID .override (site .pk ):
45+ query_added = Action .objects .annotate (
46+ action_document_type = submitter_type_sq
47+ ).filter (verb = "a ajouté un lien ou un document" )
48+
49+ print (
50+ f"Transforming some Document.ADDED to Document.ADDED_FILE in site { site .name } "
51+ )
52+ query_added .filter (action_document_type = "FILE" ).update (
53+ verb = verbs .Document .ADDED_FILE
54+ )
55+ print (
56+ f"Transforming some Document.ADDED to Document.ADDED_LINK in site { site .name } "
57+ )
58+ query_added .filter (action_document_type = "LINK" ).update (
59+ verb = verbs .Document .ADDED_LINK
60+ )
5361
5462 # Project.SUBMITTED_BY
5563 submitted_verbs = [
@@ -74,66 +82,79 @@ def specialize_verbs(apps, schema_editor):
7482 ).values_list ("submitted_by_type" , flat = True )[:1 ]
7583 )
7684
77- query_submitted_by_advisor = (
78- Action .objects .filter (verb__in = submitted_verbs )
79- .annotate (
80- project_submitted_by = submitter_sq ,
81- project_submitted_by_type = submitter_type_sq ,
82- )
83- .filter (project_submitted_by_type = "ADVISOR" )
84- .exclude (
85- actor_object_id = Cast (F ("project_submitted_by" ), output_field = CharField ())
86- )
87- )
88-
89- print (
90- "Transforming some Project.SUBMITTED and Project.SUBMITTED_BY to Project.SUBMITTED_BY_ADVISOR"
91- )
92- query_submitted_by_advisor .update (
93- verb = verbs .Project .SUBMITTED_BY_ADVISOR ,
94- actor_object_id = Cast (F ("project_submitted_by" ), output_field = CharField ()),
95- )
85+ for site in Site .objects .all ():
86+ with settings .SITE_ID .override (site .pk ):
87+ query_submitted_by_advisor = (
88+ Action .objects .filter (verb__in = submitted_verbs )
89+ .annotate (
90+ project_submitted_by = submitter_sq ,
91+ project_submitted_by_type = submitter_type_sq ,
92+ )
93+ .filter (project_submitted_by_type = "ADVISOR" )
94+ .exclude (
95+ actor_object_id = Cast (
96+ F ("project_submitted_by" ), output_field = CharField ()
97+ )
98+ )
99+ )
96100
97- print ("Creating Project.INVITATION_OWNER" )
98- new_actions = []
99- for action in query_submitted_by_advisor :
100- new_actions .append (
101- Action (
102- verb = verbs .Project .INVITATION_OWNER ,
103- actor_object_id = action .project_submitted_by ,
104- actor_content_type_id = action .actor_content_type_id , # quick way to acces user content type id
105- action_object = action .actor ,
106- target = action .target ,
107- site = action .site ,
101+ print (
102+ f"Transforming some Project.SUBMITTED and Project.SUBMITTED_BY to Project.SUBMITTED_BY_ADVISOR in site { site .name } "
103+ )
104+ query_submitted_by_advisor .update (
105+ verb = verbs .Project .SUBMITTED_BY_ADVISOR ,
106+ actor_object_id = Cast (
107+ F ("project_submitted_by" ), output_field = CharField ()
108+ ),
108109 )
109- )
110- Action .objects .bulk_create (new_actions )
111110
112- query_submitted_by_advisor .update (
113- verb = verbs .Project .SUBMITTED_BY_ADVISOR ,
114- actor_object_id = F ("project_submitted_by" ),
115- )
111+ print ("Creating Project.INVITATION_OWNER" )
112+ new_actions = []
113+ for action in query_submitted_by_advisor :
114+ new_actions .append (
115+ Action (
116+ verb = verbs .Project .INVITATION_OWNER ,
117+ actor_object_id = action .project_submitted_by ,
118+ actor_content_type_id = action .actor_content_type_id , # quick way to acces user content type id
119+ action_object = action .actor ,
120+ target = action .target ,
121+ site = action .site ,
122+ )
123+ )
124+ Action .objects .bulk_create (new_actions )
125+
126+ query_submitted_by_advisor .update (
127+ verb = verbs .Project .SUBMITTED_BY_ADVISOR ,
128+ actor_object_id = F ("project_submitted_by" ),
129+ )
116130
117131
118132def merge_verbs (apps , schema_editor ):
119133 Action = apps .get_model ("actstream" , "Action" )
134+ Site = apps .get_model ("sites" , "Site" )
120135
121- # Document.ADDED
122- Action .objects .filter (verb = verbs .Document .ADDED_FILE ).update (
123- verb = "a ajouté un lien ou un document"
124- )
125- Action .objects .filter (verb = verbs .Document .ADDED_LINK ).update (
126- verb = "a ajouté un lien ou un document"
127- )
136+ for site in Site .objects .all ():
137+ with settings .SITE_ID .override (site .pk ):
138+ # Document.ADDED
139+ Action .objects .filter (verb = verbs .Document .ADDED_FILE ).update (
140+ verb = "a ajouté un lien ou un document"
141+ )
142+ Action .objects .filter (verb = verbs .Document .ADDED_LINK ).update (
143+ verb = "a ajouté un lien ou un document"
144+ )
128145
129- # Project.SUBMITTED_BY
130- to_update = []
131- for action in Action .objects .filter (verb = verbs .Project .SUBMITTED_BY_ADVISOR ):
132- action .verb = "a déposé un nouveau dossier, qui est en attente de validation"
133- action .actor = action .target .owner
134- to_update .append (action )
135- Action .objects .bulk_update (to_update , ["verb" , "actor_object_id" ])
136- Action .objects .filter (verb = verbs .Project .INVITATION_OWNER ).delete ()
146+ # Project.SUBMITTED_BY
147+ to_update = []
148+ for action in Action .objects .filter (
149+ verb = verbs .Project .SUBMITTED_BY_ADVISOR
150+ ):
151+ action .verb = (
152+ "a déposé un nouveau dossier, qui est en attente de validation"
153+ )
154+ action .actor = action .target .owner
155+ to_update .append (action )
156+ Action .objects .bulk_update (to_update , ["verb" , "actor_object_id" ])
157+ Action .objects .filter (verb = verbs .Project .INVITATION_OWNER ).delete ()
137158
138159
139160class Migration (migrations .Migration ):
0 commit comments