|
7 | 7 | from django.views.generic import FormView, ListView, TemplateView
|
8 | 8 |
|
9 | 9 | from crowdsourcer.forms import SessionPropertyForm
|
| 10 | +from crowdsourcer.marking import get_assignment_progress, get_cached_assignment_progress |
10 | 11 | from crowdsourcer.models import (
|
11 | 12 | Assigned,
|
12 | 13 | MarkingSession,
|
13 | 14 | PublicAuthority,
|
14 |
| - Question, |
15 | 15 | ResponseType,
|
16 | 16 | SessionProperties,
|
17 | 17 | SessionPropertyValues,
|
@@ -157,89 +157,17 @@ def get_context_data(self, **kwargs):
|
157 | 157 |
|
158 | 158 | return context
|
159 | 159 |
|
160 |
| - assignments = ( |
161 |
| - context["assignments"] |
162 |
| - .distinct("user_id", "section_id", "response_type_id") |
163 |
| - .select_related("section", "response_type") |
164 |
| - ) |
165 |
| - |
166 |
| - types = Question.VOLUNTEER_TYPES |
167 |
| - if self.request.current_stage.type == "Audit": |
168 |
| - types = ["volunteer", "national_volunteer", "foi"] |
169 |
| - |
170 |
| - first_mark = ResponseType.objects.get(type="First Mark") |
171 |
| - |
172 |
| - progress = [] |
173 |
| - question_cache = {} |
174 |
| - for assignment in assignments: |
175 |
| - assignment_user = assignment.user |
176 |
| - if hasattr(assignment_user, "marker"): |
177 |
| - stage = assignment_user.marker.response_type |
178 |
| - else: |
179 |
| - stage = first_mark |
| 160 | + progress = None |
| 161 | + if user.has_perm("crowdsourcer.can_view_all_responses"): |
| 162 | + progress = get_cached_assignment_progress( |
| 163 | + f"{self.request.current_session.label} {self.request.current_stage.type}" |
| 164 | + ) |
180 | 165 |
|
181 |
| - if question_cache.get(assignment.section_id, None) is not None: |
182 |
| - question_list = question_cache[assignment.section_id] |
183 |
| - else: |
184 |
| - questions = Question.objects.filter( |
185 |
| - section=assignment.section, how_marked__in=types |
186 |
| - ) |
187 |
| - question_list = list(questions.values_list("id", flat=True)) |
188 |
| - question_cache[assignment.section_id] = question_list |
189 |
| - |
190 |
| - total = 0 |
191 |
| - complete = 0 |
192 |
| - started = 0 |
193 |
| - |
194 |
| - if assignment.section is not None: |
195 |
| - args = [ |
196 |
| - question_list, |
197 |
| - assignment.section.title, |
198 |
| - assignment.user, |
199 |
| - self.request.current_session, |
200 |
| - ] |
201 |
| - if assignment.authority_id is not None: |
202 |
| - authorities = Assigned.objects.filter( |
203 |
| - active=True, |
204 |
| - user=assignment.user_id, |
205 |
| - section=assignment.section_id, |
206 |
| - response_type=stage, |
207 |
| - ).values_list("authority_id", flat=True) |
208 |
| - args.append(authorities) |
209 |
| - |
210 |
| - # we pass the question list but we want to ignore it because there could be different types of council |
211 |
| - # included in assignments which throws the count off |
212 |
| - response_counts = PublicAuthority.response_counts( |
213 |
| - *args, |
214 |
| - question_types=types, |
215 |
| - response_type=assignment.response_type, |
216 |
| - ignore_question_list=True, |
217 |
| - ).distinct() |
218 |
| - |
219 |
| - for count in response_counts: |
220 |
| - total += 1 |
221 |
| - if count.num_responses is not None and count.num_responses > 0: |
222 |
| - started += 1 |
223 |
| - if count.num_responses == count.num_questions: |
224 |
| - complete += 1 |
225 |
| - |
226 |
| - if assignment.response_type is None: |
227 |
| - section_link = "home" |
228 |
| - elif assignment.response_type.type == "First Mark": |
229 |
| - section_link = "section_authorities" |
230 |
| - elif assignment.response_type.type == "Right of Reply": |
231 |
| - section_link = "authority_ror_authorities" |
232 |
| - elif assignment.response_type.type == "Audit": |
233 |
| - section_link = "audit_section_authorities" |
234 |
| - |
235 |
| - progress.append( |
236 |
| - { |
237 |
| - "assignment": assignment, |
238 |
| - "complete": complete, |
239 |
| - "started": started, |
240 |
| - "total": total, |
241 |
| - "section_link": section_link, |
242 |
| - } |
| 166 | + if progress is None: |
| 167 | + progress = get_assignment_progress( |
| 168 | + context["assignments"], |
| 169 | + self.request.current_session.label, |
| 170 | + self.request.current_stage.type, |
243 | 171 | )
|
244 | 172 |
|
245 | 173 | context["sessions"] = MarkingSession.objects.filter(active=True)
|
|
0 commit comments