Exemplo n.º 1
0
    def get(self, request, pk, count=10, format=None):
        from parse_cordis import listing
        data = listing.parse(pk, count)
        logging.debug(data)
        l = ProjectList(data=data)

        logging.debug(l)
        serializer = ProjectListSerializer(l)
        return Response(serializer.data)
Exemplo n.º 2
0
    def get(self, request, pk, count=10, format=None):
        # try:
        from parse_cordis import listing
        reset = request.GET.get('reset', None)

        data = listing.parse(pk, count)

        projects = list()

        # loop through data and save new project
        for rcn in data:

            # get from cache first
            try:
                if reset:
                    raise Project.DoesNotExist

                project = Project.objects.get(pk=rcn)
            except Project.DoesNotExist:

                try:
                    project = Project(rcn=rcn)
                    project.parse_cordis()
                    project.save()
                except:
                    # save erroneous project anyways, we don't want to block on them always
                    project.save()
                    pass

            projects.append(project)
        
        serializer = ProjectSerializer(projects, many=True)
        return Response(serializer.data)


        # logging.debug(data)

        # listingObj = Listing(data=data)
        # serializer = ListingSerializer(listingObj)
        # return Response(serializer.data)
            # return l
        # except:
            # raise Http404

# @api_view(('GET',))
# def api_root(request, format=None):
#     return Response({
#         'projects': reverse('projects.views.ProjectList', request=request, format=format)
#     })