def compliances_external(self, request, *args, **kwargs): """ Paginated serializer for datatables - used by the external dashboard To test: http://localhost:8000/api/compliance_paginated/compliances_external/?format=datatables&draw=1&length=2 """ #import ipdb; ipdb.set_trace() qs = self.get_queryset().exclude(processing_status='future') #qs = ProposalFilterBackend().filter_queryset(self.request, qs, self) qs = self.filter_queryset(qs) #qs = qs.order_by('lodgement_number', '-issue_date').distinct('lodgement_number') # on the internal organisations dashboard, filter the Proposal/Approval/Compliance datatables by applicant/organisation applicant_id = request.GET.get('org_id') if applicant_id: qs = qs.filter(proposal__applicant_id=applicant_id) self.paginator.page_size = qs.count() result_page = self.paginator.paginate_queryset(qs, request) serializer = ComplianceSerializer(result_page, context={'request': request}, many=True) return self.paginator.get_paginated_response(serializer.data)
def accept(self, request, *args, **kwargs): try: instance = self.get_object() instance.accept(request) serializer = ComplianceSerializer(instance) return Response(serializer.data) except serializers.ValidationError: print(traceback.print_exc()) raise except ValidationError as e: print(traceback.print_exc()) raise serializers.ValidationError(repr(e.error_dict)) except Exception as e: print(traceback.print_exc()) raise serializers.ValidationError(str(e))
def delete_document(self, request, *args, **kwargs): try: instance = self.get_object() doc = request.data.get('document') instance.delete_document(request, doc) serializer = ComplianceSerializer(instance) return Response(serializer.data) except serializers.ValidationError: print(traceback.print_exc()) raise except ValidationError as e: print(traceback.print_exc()) raise serializers.ValidationError(repr(e[0].encode('utf-8'))) except Exception as e: print(traceback.print_exc()) raise serializers.ValidationError(str(e))
def user_list(self, request, *args, **kwargs): user_orgs = [ org.id for org in request.user.disturbance_organisations.all() ] qs = [] qs.extend( list(self.get_queryset().filter( proposal__submitter=request.user).exclude( processing_status='future'))) #Remove filter to include 'Apporved Proposals in external dashboard .exclude(processing_status=Proposal.PROCESSING_STATUS_CHOICES[13][0]) qs.extend( list(self.get_queryset().filter( proposal__applicant_id__in=user_orgs).exclude( processing_status='future'))) #Remove filter to include 'Apporved Proposals in external dashboard .exclude(processing_status=Proposal.PROCESSING_STATUS_CHOICES[13][0]) queryset = list(set(qs)) serializer = ComplianceSerializer(queryset, many=True) return Response(serializer.data)
def compliances_external(self, request, *args, **kwargs): #import ipdb; ipdb.set_trace() """ Paginated serializer for datatables - used by the external dashboard To test: http://localhost:8000/api/compliance_paginated/compliances_external/?format=datatables&draw=1&length=2 """ web_url = request.META.get('HTTP_HOST', None) template_group = None if web_url in settings.APIARY_URL: template_group = 'apiary' else: template_group = 'das' #import ipdb; ipdb.set_trace() if template_group == 'apiary': #qs = self.get_queryset().filter(application_type__apiary_group_application_type=True).exclude(processing_status='discarded') qs = self.get_queryset().filter(apiary_compliance=True) else: qs = self.get_queryset().exclude(apiary_compliance=True) #qs = self.get_queryset().exclude(processing_status='future') #qs = ProposalFilterBackend().filter_queryset(self.request, qs, self) qs = self.filter_queryset(qs) #qs = qs.order_by('lodgement_number', '-issue_date').distinct('lodgement_number') # on the internal organisations dashboard, filter the Proposal/Approval/Compliance datatables by applicant/organisation applicant_id = request.GET.get('org_id') if applicant_id: if template_group == 'apiary': qs = qs.filter(approval__applicant_id=applicant_id) else: qs = qs.filter(proposal__applicant_id=applicant_id) self.paginator.page_size = qs.count() result_page = self.paginator.paginate_queryset(qs, request) serializer = ComplianceSerializer(result_page, context={'request': request}, many=True) return self.paginator.get_paginated_response(serializer.data)
def assign_to(self, request, *args, **kwargs): try: instance = self.get_object() user_id = request.data.get('user_id', None) user = None if not user_id: raise serializers.ValiationError('A user id is required') try: user = EmailUser.objects.get(id=user_id) except EmailUser.DoesNotExist: raise serializers.ValidationError( 'A user with the id passed in does not exist') instance.assign_to(user, request) serializer = ComplianceSerializer(instance) return Response(serializer.data) except serializers.ValidationError: print(traceback.print_exc()) raise except ValidationError as e: print(traceback.print_exc()) raise serializers.ValidationError(repr(e.error_dict)) except Exception as e: print(traceback.print_exc()) raise serializers.ValidationError(str(e))