def get(self, request, **kwargs):
        id_custom_practice = kwargs['id_custom_practice']
        query_params = request.GET
        practicing = False
        if query_params.get('practicing') is not None:
            practicing = int(query_params.get('practicing'))
        practices_object_data = CustomPractices.objects.filter(practicing=practicing)
        from simulador.resources.custom_practices import CustomPracticesSerializer
        practices_serial_data = CustomPracticesSerializer(practices_object_data, many=True).data
        list_result_practice = []
        if len(practices_serial_data) > 0:
            for practice_result in practices_serial_data:
                from simulador.resources.program_practice import get_results_by_user
                tmp = get_results_by_user(practice_result['practicing'], custom_practice_id=id_custom_practice,
                                          complete=True)
                list_result_practice.append(tmp)

        context = {
            "program_practice": practices_serial_data,
            "data": list_result_practice,
            "list_not_practice": [],
            "is_total": False,
            "is_custom": True
        }
        file_data = render_to_string('report_program_practice.html', context, RequestContext(request))
        file = StringIO.StringIO()
        pisa.CreatePDF(file_data, file)
        file.seek(0)
        response = HttpResponse(file.getvalue())
        # response['Content-Disposition'] = 'attachment; filename=test.pdf'
        response['Content-Disposition'] = 'filename=Reporte de practica.pdf'
        response['Content-Type'] = 'application/pdf'
        return response
 def results(self, request, pk):
     query_params = self.request.query_params
     practices_serial_data = CustomPracticesSerializer(CustomPractices.objects.filter(id=pk), many=True).data
     response = {}
     response_status = status.HTTP_200_OK
     if len(practices_serial_data) > 0:
         list_result_practice = []
         if 'practicing' in query_params:
             response = get_results_by_user(query_params['practicing'], pk)
         else:
             for practice_result in practices_serial_data:
                 list_result_practice.append(get_results_by_user(practice_result['practicing'], pk))
             response = {'result': list_result_practice}
     else:
         response['detail'] = 'No se encontraron resultados'
         response_status = status.HTTP_204_NO_CONTENT
     return Response(response, response_status)