예제 #1
0
    def flag(self, request, pk):
        try:
            placename = PlaceName.objects.get(pk=int(pk))
            if placename.status == PlaceName.VERIFIED:
                return Response(
                    {"message": "PlaceName has already been verified"})
            else:
                if 'status_reason' in request.data.keys():
                    PlaceName.flag(int(pk), request.data["status_reason"])

                    #Notifying Administrators
                    try:
                        inform_placename_to_be_verified(int(pk))
                    except Exception as e:
                        pass

                    #Notifying the creator
                    try:
                        inform_placename_rejected_or_flagged(
                            int(pk), request.data["status_reason"],
                            PlaceName.FLAGGED)
                    except Exception as e:
                        pass

                    return Response({"message": "Flagged!"})
                else:
                    return Response({"message": "Reason must be provided"})
        except PlaceName.DoesNotExist:
            return Response(
                {"message": "No PlaceName with the given id was found"})
 def flag(self, request, pk):
     try:
         placename = PlaceName.objects.get(pk=int(pk))
         if placename.status == PlaceName.VERIFIED:
             return Response(
                 {"message": "PlaceName has already been verified"})
         else:
             if 'status_reason' in request.data.keys():
                 PlaceName.flag(int(pk), request.data["status_reason"])
                 return Response({"message": "Flagged!"})
             else:
                 return Response({"message": "Reason must be provided"})
     except PlaceName.DoesNotExist:
         return Response(
             {"message": "No PlaceName with the given id was found"})