Exemple #1
0
def vacancy_list(request):
    if request.method == 'GET':
        vacancies = Vacancy.objects.all()
        serializer = VacancySerializer2(vacancies, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
    elif request.method == 'POST':
        serializer = VacancySerializer2(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors,
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemple #2
0
def vacancy_list(request):
    if request.method == 'GET':
        vacancies = Vacancy.objects.all()
        serializer = VacancySerializer2(vacancies, many=True)
        return JsonResponse(serializer.data, safe=False, status=200)
    elif request.method == 'POST':
        data = json.loads(request.body)
        serializer = VacancySerializer2(data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse(serializer.errors)
 def put(self, request, vacancy_id):
     vacancy = self.get_object(vacancy_id)
     serializer = VacancySerializer2(instance=vacancy, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors)
 def post(self, request):
     serializer = VacancySerializer2(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors,
                     status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemple #5
0
def company_vacancies(request, company_id):
    try:
        company = Company.objects.get(id=company_id)
    except Company.DoesNotExist as e:
        return JsonResponse({'error': str(e)})
    vacancies = company.vacancies.all()
    serializer = VacancySerializer2(vacancies, many=True)
    return JsonResponse(serializer.data, safe=False)
Exemple #6
0
def company_vacancies(request, company_id):
    try:
        company = Company.objects.get(id=company_id)
    except Company.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)
    if request.method == 'GET':
        vacancies = company.vacancies.all()
        serializer = VacancySerializer2(vacancies, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
Exemple #7
0
def vacancy_detail(request, vacancy_id):
    try:
        vacancy = Vacancy.objects.get(id=vacancy_id)
    except Company.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = VacancySerializer2(vacancy)
        return Response(serializer.data)
    elif request.method == 'PUT':
        serializer = VacancySerializer2(instance=vacancy, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors)
    elif request.method == 'DELETE':
        vacancy.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Exemple #8
0
def company_vacancies(request, company_id):
    try:
        company = Company.objects.get(id=company_id)
    except Company.DoesNotExist as e:
        return Response({'error': str(e)})

    if request.method == 'GET':
        vacancies = company.vacancy_set.all()
        serializer = VacancySerializer2(vacancies, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = VacancySerializer2(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response({'error': serializer.errors},
                        status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Exemple #9
0
def vacancy_detail(request, vacancy_id):
    try:
        vacancy = Vacancy.objects.get(id=vacancy_id)
    except Vacancy.DoesNotExist as e:
        return JsonResponse({'error': str(e)})

    if request.method == 'GET':
        serializer = VacancySerializer2(vacancy)
        return JsonResponse(serializer.data, status=200)
    elif request.method == 'PUT':
        data = json.loads(request.body)
        serializer = VacancySerializer2(instance=vacancy, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data, status=200)
        return JsonResponse(serializer.errors)
    elif request.method == 'DELETE':
        vacancy.delete()
        return JsonResponse({}, status=204)
Exemple #10
0
def vacancy_detail(request, vacancy_id):
    try:
        vacancy = Vacancy.objects.get(id=vacancy_id)
    except Vacancy.DoesNotExist as e:
        return Response({'error': str(e)})

    if request.method == 'GET':
        serializer = VacancySerializer2(vacancy)
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = VacancySerializer2(instance=vacancy, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response({'error': serializer.errors})

    elif request.method == 'DELETE':
        vacancy.delete()
        return Response({'deleted': True})
Exemple #11
0
def vacancy_from_company(request, company_id):
    if request.method == "GET":
        try:
            vacancy_list = Vacancy.objects.all()
            vacancies = []
            serializer = VacancySerializer2(vacancies, many=True)
            for vacancy in vacancy_list:
                if vacancy.company.id == company_id:
                    vacancies.append(vacancy)
        except Company.DoesNotExist as e:
            return Response({'error': 'company doesn`t exist'})
        return Response(serializer.data)
    elif request.method == "POST":
        pass
Exemple #12
0
def top_ten_vacancies(request):
    vacancies = Vacancy.objects.order_by('-salary')[:10]
    if request.method == 'GET':
        serializer = VacancySerializer2(vacancies, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
Exemple #13
0
 def get(self, request):
     vacancies = Vacancy.objects.all()
     serializer = VacancySerializer2(vacancies, many=True)
     return Response(serializer.data, status=status.HTTP_200_OK)
Exemple #14
0
def vacancy_top_ten(request):
    vacancies = Vacancy.objects.order_by('-salary')
    serializer = VacancySerializer2(vacancies, many=True)
    return Response(serializer.data[:10])
Exemple #15
0
 def get(self, request, vacancy_id):
     vacancy = self.get_object(vacancy_id)
     serializer = VacancySerializer2(vacancy)
     return Response(serializer.data)
Exemple #16
0
def top_ten_vacancies(request):
    vacancies = Vacancy.objects.order_by('-salary')[:10]
    serializer = VacancySerializer2(vacancies, many=True)
    if request.method == 'GET':
        return JsonResponse(serializer.data, safe=False, status=200)
Exemple #17
0
 def get(self, request, company_id):
     vacancies = self.get_object(company_id).vacancy_set.all()
     serializer = VacancySerializer2(vacancies, many=True)
     return Response(serializer.data)