def delete(self, request, user_id, hpc=None, project_name=None):

        if hpc:
            hpc = hpc.upper()
            if hpc_exists(hpc):

                if project_name:
                    try:
                        project = Project.objects.get(hpc=hpc,
                                                      name=project_name)
                        quota = Quota.objects.get(user=user_id,
                                                  project=project)
                        quota.delete()
                        return Response('Quota deleted',
                                        status=status.HTTP_204_NO_CONTENT)
                    except Project.DoesNotExist:
                        return Response('Project not found!',
                                        status=status.HTTP_404_NOT_FOUND)
                    except Quota.DoesNotExist:
                        return Response('Quota not found!',
                                        status=status.HTTP_404_NOT_FOUND)

                projects = Project.objects.filter(hpc=hpc)
                quotas = Quota.objects.filter(user=user_id, project=projects)
                quotas.delete()
                return Response('Quotas deleted',
                                status=status.HTTP_204_NO_CONTENT)

            return Response('HPC not found!', status=status.HTTP_404_NOT_FOUND)

        quota = Quota.objects.filter(user=user_id)
        quota.delete()
        return Response('Quotas deleted!', status=status.HTTP_204_NO_CONTENT)
    def get(self, request, user_id, hpc=None, project_name=None):

        if hpc:
            hpc = hpc.upper()
            if hpc_exists(hpc):

                if project_name:
                    try:
                        project = Project.objects.get(hpc=hpc,
                                                      name=project_name)
                        quota = Quota.objects.get(user=user_id,
                                                  project=project)
                        serializer = QuotaSerializer(quota)
                        return Response(serializer.data,
                                        status=status.HTTP_200_OK)
                    except Project.DoesNotExist:
                        return Response('Project not found!',
                                        status=status.HTTP_404_NOT_FOUND)
                    except Quota.DoesNotExist:
                        return Response('Quota not found!',
                                        status=status.HTTP_404_NOT_FOUND)

                projects = Project.objects.filter(hpc=hpc)
                quotas = Quota.objects.filter(project=projects, user=user_id)
                serializer = QuotaSerializer(quotas, many=True)
                return Response(serializer.data, status=status.HTTP_200_OK)

            return Response('HPC not found!', status=status.HTTP_404_NOT_FOUND)

        else:
            quotas = Quota.objects.filter(user=user_id)
            serializer = QuotaSerializer(quotas, many=True)
            return Response(serializer.data, status=status.HTTP_200_OK)
    def get(self, request, hpc=None, project_name=None):

        if hpc and hpc_exists(hpc):
            hpc = hpc.upper()

            if project_name:
                try:
                    project = Project.objects.get(hpc=hpc, name=project_name)
                    quotas = Quota.objects.filter(project=project)
                    serializer = QuotaSerializer(quotas, many=True)
                    return Response(serializer.data, status=status.HTTP_200_OK)
                except Quota.DoesNotExist:
                    return Response('Quota not found!',
                                    status=status.HTTP_404_NOT_FOUND)

            try:
                projects = Project.objects.filter(hpc=hpc)
                quotas = Quota.objects.filter(project=projects)
                serializer = QuotaSerializer(quotas, many=True)
                return Response(serializer.data, status=status.HTTP_200_OK)
            except Project.DoesNotFound:
                return Response('No quotas found!',
                                status=status.HTTP_404_NOT_FOUND)

        try:
            quotas = Quota.objects.all()
            serializer = QuotaSerializer(quotas, many=True)
            return Response(serializer.data, status=status.HTTP_200_OK)
        except Quota.DoesNotExist:
            return Response('No quotas found!',
                            status=status.HTTP_404_NOT_FOUND)
 def delete(self, request, hpc, project_name):
     hpc = hpc.upper()
     if hpc_exists(hpc):
         try:
             project = Project.objects.get(hpc=hpc, name=project_name)
             project.delete()
             return Response('Project deleted!',
                             status=status.HTTP_204_NO_CONTENT)
         except Project.DoesNotExist:
             return Response('Project not found!',
                             status=status.HTTP_404_NOT_FOUND)
     else:
         return Response('HPC not found!', status=status.HTTP_404_NOT_FOUND)
    def post(self, request, hpc, project_name):

        if hpc_exists(hpc):
            hpc = hpc.upper()

            if project_name:
                try:
                    project = Project.objects.get(hpc=hpc, name=project_name)
                    quota = Quota(project=project, user=request.data['user'])
                    serializer = QuotaSerializer(instance=quota)
                    if serializer.is_valid():
                        serializer.save()
                        return Response(serializer.data,
                                        status=status.HTTP_201_CREATED)
                    return Response(serializer.errors,
                                    status=status.HTTP_404_NOT_FOUND)
                except Project.DoesNotExist:
                    return Response('Project not found!',
                                    status=status.HTTP_404_NOT_FOUND)

        return Response('HPC not found!', status=status.HTTP_404_NOT_FOUND)
 def get(self, request, hpc=None, project_name=None):
     if hpc:
         if hpc_exists(hpc):
             hpc = hpc.upper()
             if project_name:
                 try:
                     print(hpc, project_name)
                     project = Project.objects.get(hpc=hpc,
                                                   name=project_name)
                     serializer = ProjectSerializer(project)
                     return Response(serializer.data,
                                     status=status.HTTP_200_OK)
                 except Project.DoesNotExist:
                     return Response('Project not found!',
                                     status=status.HTTP_404_NOT_FOUND)
             projects = Project.objects.filter(hpc=hpc)
             serializer = ProjectSerializer(projects, many=True)
             return Response(serializer.data, status=status.HTTP_200_OK)
         return Response('HPC not exists!',
                         status=status.HTTP_400_BAD_REQUEST)
     projects = Project.objects.all()
     serializer = ProjectSerializer(projects, many=True)
     return Response(serializer.data, status=status.HTTP_200_OK)