Exemple #1
0
    def get_object(self, pk, reset):
        try:
            if reset:
                raise Project.DoesNotExist
            return Project.objects.get(pk=pk)

        except Project.DoesNotExist:
            try:
                project = Project(rcn=pk)
                project.parse_cordis()
                project.save()
                return project
            except:
                raise Http404
Exemple #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)
#     })