def update_allegation_document(self, id, link, document_type): documentcloud_service = DocumentcloudService() parsed_link = documentcloud_service.process_link( link, document_type=document_type) if not parsed_link: return HttpResponseBadRequest( content={'errors': ['Invalid document link']}) try: if id: document = Document.objects.get(pk=id) else: document = Document.objects.get( allegation__crid=parsed_link['allegation_crid'], type=document_type) except Document.DoesNotExist: return HttpResponseBadRequest( content={'errors': ['Document not exist']}) document_params = { 'documentcloud_id': parsed_link['documentcloud_id'], 'normalized_title': parsed_link['normalized_title'], 'title': parsed_link['title'] } document.update(**document_params) return JsonResponse({'status': 200, 'crid': document.allegation.crid})
def get(self, request): officer_allegations = self.get_officer_allegations( ignore_filters=['final_outcome', 'final_finding', 'final_finding_text', 'outcome_text']) return JsonResponse({ 'sunburst': SunburstSerializer(officer_allegations).data })
def post(self, request): form = DocumentRequestStatusForm(request.POST) if not form.is_valid(): return HttpResponseBadRequest(form=form) form.process() return JsonResponse()
def get(self, request): query = request.GET.get('query', '') limit = 10 types = Story.objects.distinct('story_type').filter(story_type__icontains=query)\ .values_list('story_type', flat=True)[:limit] return JsonResponse(data={ 'data': list(types), })
def get(self, request): investigator_id = request.GET.get('pk', 0) investigator = get_object_or_404(Investigator, pk=investigator_id) details = InvestigatorDetailsService.get_details(investigator) return JsonResponse(data={ 'investigator': investigator, 'num_disciplined': details['num_disciplined'], 'num_allegations': details['num_allegations'], 'allegations': details['allegations'], 'timeline': details['timeline'], 'has_map': details['has_map'] }, safe=False)
def get(self, request): officer_allegations = self.get_officer_allegations() officer_list = Officer.objects.filter( id__in=officer_allegations.values('officer').distinct()) count_by_officer = officer_list.values_list('allegations_count', flat=True) try: max_allegation_count = max(count_by_officer) except ValueError: count_summary = [0] else: count_summary = [0] * (max_allegation_count + 1) for count in count_by_officer: count_summary[count] += 1 return JsonResponse(count_summary, safe=False)
def get(self, request): try: page = int(request.GET.get('page', 0)) start = page * self.PER_PAGE end = start + self.PER_PAGE order_by = request.GET.get('order_by') or '-updated_at' if order_by.replace('-', '') not in self.SUPPORTED_SORT_ORDER: raise Exception('Unknown sort order') aliases = Alias.objects.all() if 'q' in request.GET: aliases = aliases.filter(alias__istartswith=request.GET.get('q')) aliases = aliases.order_by(order_by)[start:end] return JsonResponse({ 'data': aliases, }) except Exception as e: return HttpResponse(json.dumps({ 'error': str(e), }))
def crawl_stats(request): docs = DocumentCrawler.objects.all().values( 'timestamp', 'num_documents').order_by('-timestamp') return JsonResponse({'status': 200, 'docs': docs})
def get(self, request): download = get_object_or_404(Download, pk=request.GET.get('id')) return JsonResponse({'download': download})
def post(self, request): query_string = request.META['QUERY_STRING'] download = Download.objects.create(query=query_string) download_allegations.delay(download.id) return JsonResponse({'download': download})