Esempio n. 1
0
    def post(self, request):
        try:
            print "Here about to create an add request"
            user_id = request.data["id"]
            user = User.objects.get(pk=user_id)
            Contact.create_add_request(from_user=request.user, for_user = user)

            return JSONResponse([], status=200)
        except Exception as e:
            beam(e, request)
            return JSONResponse(ERROR_MESSAGE, status=400)
Esempio n. 2
0
    def post(self, request):
        try:
            from_user = request.user
            for_user = User.objects.get(pk=request.data["for_user"])
            request_type = request.data["request_type"]
            field_type = request.data["field_type"]

            print for_user.id
            print request.user.id

            is_shown = Contact.create_add_request(from_user=request.user, for_user=for_user)
            print is_shown
            profile_request = ProfileRequest.objects.filter(for_user_id=for_user.id, from_user=from_user,
                                                            request_type=request_type)

            if profile_request:
                profile_request = profile_request[0]
                if profile_request.status == "declined":
                    profile_request.status = "new"
                    profile_request.save()
                    profile_request.notify(is_shown)
                else:
                    return JSONResponse(REQUEST_ALREADY_EXISTS, status=200)
            else:
                profile_request = ProfileRequest(for_user_id=for_user.id, from_user=from_user,
                                                 request_type=request_type, field_type=field_type)
                profile_request.save()
                profile_request.notify(is_shown)

                return JSONResponse(PROFILE_REQUEST_CREATED, status=200)

        except Exception as e:
            beam(e, request)
            return JSONResponse(ERROR_MESSAGE, status=200)