17
17
"Sent by" : "Envoyé par" ,
18
18
"Sent by email" : "Envoyé par courriel" ,
19
19
"Job" : "Tâche" ,
20
+ "Row number" : "Numéro de ligne" ,
20
21
"Status" : "État" ,
21
22
"Sent Time" : "Heure d’envoi" ,
22
23
# notification types
@@ -96,6 +97,7 @@ def build_notifications_query(service_id, notification_type, language, notificat
96
97
u .name .label ("user_name" ),
97
98
u .email_address .label ("user_email" ),
98
99
j .original_file_name .label ("job_name" ),
100
+ n .job_row_number .label ("job_row_number" ),
99
101
n .status .label ("status" ),
100
102
n .created_at .label ("created_at" ),
101
103
n .feedback_subtype .label ("feedback_subtype" ),
@@ -105,7 +107,7 @@ def build_notifications_query(service_id, notification_type, language, notificat
105
107
.outerjoin (j , j .id == n .job_id )
106
108
.outerjoin (u , u .id == n .created_by_id )
107
109
.filter (* query_filters )
108
- .order_by (n .created_at .desc ())
110
+ .order_by (n .created_at .asc () if job_id else n . created_at . desc ())
109
111
.subquery ()
110
112
)
111
113
@@ -151,20 +153,38 @@ def build_notifications_query(service_id, notification_type, language, notificat
151
153
else_ = inner_query .c .notification_type ,
152
154
).label (translate ("Type" ))
153
155
154
- return db .session .query (
156
+ # Create a list of columns for the outer query
157
+ query_columns = [
155
158
inner_query .c .to .label (translate ("Recipient" )),
156
159
inner_query .c .template_name .label (translate ("Template" )),
157
160
notification_type_translated ,
158
- func .coalesce (inner_query .c .user_name , "" ).label (translate ("Sent by" )),
159
- func .coalesce (inner_query .c .user_email , "" ).label (translate ("Sent by email" )),
160
- func .coalesce (inner_query .c .job_name , "" ).label (translate ("Job" )),
161
- status_expr ,
162
- # Explicitly cast created_at to UTC, then to America/Toronto
163
- func .to_char (
164
- func .timezone ("America/Toronto" , func .timezone ("UTC" , inner_query .c .created_at )), "YYYY-MM-DD HH24:MI:SS"
165
- ).label (translate ("Sent Time" )),
161
+ ]
162
+
163
+ # Only include "Sent by" and "Sent by email" columns if job_id is None
164
+ if job_id is None :
165
+ query_columns .extend (
166
+ [
167
+ func .coalesce (inner_query .c .user_name , "" ).label (translate ("Sent by" )),
168
+ func .coalesce (inner_query .c .user_email , "" ).label (translate ("Sent by email" )),
169
+ ]
170
+ )
171
+ else :
172
+ query_columns .insert (0 , (inner_query .c .job_row_number + 1 ).label (translate ("Row number" )))
173
+
174
+ # Add the remaining columns
175
+ query_columns .extend (
176
+ [
177
+ func .coalesce (inner_query .c .job_name , "" ).label (translate ("Job" )),
178
+ status_expr ,
179
+ # Explicitly cast created_at to UTC, then to America/Toronto
180
+ func .to_char (
181
+ func .timezone ("America/Toronto" , func .timezone ("UTC" , inner_query .c .created_at )), "YYYY-MM-DD HH24:MI:SS"
182
+ ).label (translate ("Sent Time" )),
183
+ ]
166
184
)
167
185
186
+ return db .session .query (* query_columns )
187
+
168
188
169
189
def compile_query_for_copy (query ):
170
190
"""
0 commit comments