2018-09-16 16:52:23 +00:00
|
|
|
from rest_framework import generics, mixins
|
2018-10-11 09:18:48 +00:00
|
|
|
from postings.models import *
|
2018-09-25 20:52:38 +00:00
|
|
|
from .serializers import *
|
2018-09-16 16:52:23 +00:00
|
|
|
from django.db.models import Q
|
|
|
|
|
|
|
|
|
2018-09-25 20:52:38 +00:00
|
|
|
# The view for listing all generic Review objects.
|
|
|
|
class ReviewsView(mixins.CreateModelMixin, generics.ListAPIView):
|
|
|
|
queryset = Review.objects.all()
|
|
|
|
serializer_class = ReviewSerializer
|
|
|
|
|
|
|
|
# View for an individual Review object.
|
|
|
|
class ReviewView(generics.RetrieveUpdateDestroyAPIView):
|
|
|
|
queryset = Review.objects.all()
|
|
|
|
serializer_class = ReviewSerializer
|
|
|
|
|
2018-10-11 09:18:48 +00:00
|
|
|
class ReviewHelpfulVote(mixins.CreateModelMixin):
|
|
|
|
lookup_field = 'pk'
|
|
|
|
serializer_class = ReviewHelpfulVoteSerializer
|
2018-09-25 20:52:38 +00:00
|
|
|
|
2018-10-11 09:18:48 +00:00
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
return self.create(request, *args, **kwargs)
|
2018-10-10 14:27:04 +00:00
|
|
|
|
|
|
|
def review_helpful_vote(request, review_id):
|
|
|
|
if request.method == 'POST':
|
|
|
|
helpful = request.POST.get('helpful')
|
|
|
|
if helpful is None:
|
|
|
|
return HttpResponseBadRequest("Bad Request")
|
|
|
|
helpful = True if helpful == 'true' else False
|
|
|
|
|
|
|
|
try:
|
|
|
|
review = Review.objects.get(pk=review_id)
|
|
|
|
except Review.DoesNotExist:
|
|
|
|
raise HttpResponseBadRequest("Bad Request: Invalid review id.")
|
|
|
|
|
|
|
|
vote = ReviewHelpfulVote.objects.create(
|
|
|
|
review=review,
|
|
|
|
helpful=helpful
|
|
|
|
)
|
|
|
|
|
|
|
|
return HttpResponseBadRequest("Bad Request")
|