@@ -205,3 +205,70 @@ def get_context_data(self, **kwargs):
205
205
context = super ().get_context_data (** kwargs )
206
206
context ["ror_user" ] = True
207
207
return context
208
+
209
+ def AuthorityRoRCSVView (ListView ):
210
+ context_object_name = "responses"
211
+
212
+ def get_queryset (self ):
213
+ authority = self .request .user .marker .authority
214
+
215
+ if authority is not None :
216
+ return (
217
+ Response .objects .filter (
218
+ question__section__marking_session = self .request .current_session
219
+ authority = authority
220
+ )
221
+ .select_related ("question" , "question__section" )
222
+ .order_by (
223
+ "question__section__title" ,
224
+ "question__number" ,
225
+ "question__number_part" ,
226
+ )
227
+ )
228
+
229
+ return None
230
+
231
+ def get_context_data (self , ** kwargs ):
232
+ context = super ().get_context_data (** kwargs )
233
+ rows = []
234
+ rows .append (
235
+ [
236
+ "section" ,
237
+ "No" ,
238
+ "question" ,
239
+ "first_mark_response" ,
240
+ "agree_with_mark" ,
241
+ "council_response" ,
242
+ "council_evidence" ,
243
+ "council_page_mumber" ,
244
+ "council_notes" ,
245
+ ]
246
+ )
247
+
248
+ for response in context ["responses" ]:
249
+ rows .append ([
250
+ response .question .section .title ,
251
+ response .question .number_and_part ,
252
+ response .question .text ,
253
+ "" ,
254
+ response .agree_with_response ,
255
+ response .evidence_links ,
256
+ response .page_number ,
257
+ response .public_notes ,
258
+ ])
259
+
260
+ context ["rows" ] = rows
261
+
262
+ return context
263
+
264
+ def render_to_response (self , context , ** response_kwargs ):
265
+ response = HttpResponse (
266
+ content_type = "text/csv" ,
267
+ headers = {
268
+ "Content-Disposition" : 'attachment; filename="questions_with_max_scores.csv"'
269
+ },
270
+ )
271
+ writer = csv .writer (response )
272
+ for row in context ["rows" ]:
273
+ writer .writerow (row )
274
+ return response
0 commit comments