示例#1
0
 def post(self, request, **kwargs):
     try:
         photo = Photo.objects.get(pk=self.kwargs.get("pk"))
     except:
         return JsonResponse({'message': 'Photo not found'})
     kudu_count = photo.kudu_count
     if kudu_count == 1:
         person_text = "Person"
     else:
         person_text = "People"
     text = "%s gave this<br />a kudu" % person_text
     if request.user.id is None:
         return JsonResponse({'message': 'You will need to sign in', 'kudus': kudu_count, 'text': text})
     else:
         if Action.objects.filter(action_type="K", user=request.user, content_type__model='photo', photo=photo).count():
             return JsonResponse(
                 {'message': 'Thanks, but you already gave a kudu', 'kudus': kudu_count, 'text': text})
         else:
             action = Action()
             action.content_type = ContentType.objects.get(model='photo')
             action.object_id = photo.id
             action.content_object = photo
             action.user = request.user
             action.action_type = 'K'
             action.save()
             photo.update_kudu_count()
             photo.check_and_send_kudu_email()
             if photo.kudu_count == 1:
                 person_text = "Person"
             else:
                 person_text = "People"
             text = "%s gave this<br />a kudu" % person_text
             message = "Thank you for giving a kudu"
             return JsonResponse({'message': message, 'kudus': photo.kudu_count, 'text': text})
示例#2
0
 def get(self, request, photo_pk):
     photo = get_object_or_404(Photo, pk=photo_pk)
     action = Action()
     action.action_type = Action.KUDU
     action.user = request.user
     action.content_object = photoaction.save()
     return Response(action)
示例#3
0
    def post(self, request, **kwargs):

        try:
            obj = TourOperatorReview.objects.filter(
                pk=self.kwargs.get("pk")).first()
        except:
            return JsonResponse({'message': 'Review not found'})
        kudu_count = obj.kudu_count
        if kudu_count == 1:
            person_text = "Person"
        else:
            person_text = "People"
        text = "%s gave this<br />a kudu" % person_text

        if request.user.id is None:
            return JsonResponse({
                'message': 'You will need to sign in',
                'kudus': kudu_count,
                'text': text
            })
        else:
            if Action.objects.filter(action_type="K",
                                     user=request.user,
                                     tour_operator_review=obj).count():
                return JsonResponse({
                    'message': 'Thanks, but you already gave a kudu',
                    'kudus': kudu_count,
                    'text': text
                })
            else:
                action = Action()
                action.content_type = ContentType.objects.get(
                    model='touroperatorreview')
                action.object_id = obj.id
                action.content_object = obj
                action.user = request.user
                action.action_type = 'K'
                action.save()

                obj.update_kudu_count()
                if obj.kudu_count == 1:
                    person_text = "Person"
                else:
                    person_text = "People"
                text = "%s gave this<br /> a kudu" % person_text
                message = "Thank you for giving a kudu"
                return JsonResponse({
                    'message': message,
                    'kudus': obj.kudu_count,
                    'text': text
                })