Beispiel #1
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        #recipient = form.cleaned_data['referrer']
        recipient = action.referrers
        message = form.cleaned_data['message_text']
        request_type = consts.REQUEST_TYPE_MESSAGE

        sender.assert_can_send_action_message(sender, 
            recipient, 
            action
        )

        action_request = ActionRequest(
            action=action,
            sender=sender,
            request_notes=message,
            request_type=request_type 
        )
        action_request.save()
        action_request.recipient_set.add(*recipient)
        action_request.save()

        action_message_sent.send(sender=action_request)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
Beispiel #2
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        message = form.cleaned_data['request_text']
        status = form.cleaned_data['status_to_set']

        if status in (a_consts.ACTION_STATUS_VICTORY,):
            request_type = consts.REQUEST_TYPE_SET_VICTORY
        elif status in (a_consts.ACTION_STATUS_CLOSED,):
            request_type = consts.REQUEST_TYPE_SET_CLOSURE

        sender.assert_can_ask_action_status_update(
            action,
            request_type
        )

        action_request = ActionRequest(
            action=action,
            sender=sender,
            request_notes=message,
            request_type=request_type 
        )
        action_request.save()
        
        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
Beispiel #3
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        recipient = form.cleaned_data['follower']
        request_notes = form.cleaned_data['request_text']
        request_type = consts.REQUEST_TYPE_MODERATION

        sender.assert_can_request_moderation_for_action(sender, recipient, action)
        #print("RECIPIENT: %s", recipient)
        action_request = ActionRequest(
            action=action,
            sender=sender,
            request_notes=request_notes,
            request_type=request_type 
        )
        action_request.save()
        action_request.recipient_set.add(recipient)
        action_request.save()

        action_moderation_request_submitted.send(sender=action_request)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
Beispiel #4
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        message = form.cleaned_data['request_text']
        status = form.cleaned_data['status_to_set']

        if status in (a_consts.ACTION_STATUS_VICTORY, ):
            request_type = consts.REQUEST_TYPE_SET_VICTORY
        elif status in (a_consts.ACTION_STATUS_CLOSED, ):
            request_type = consts.REQUEST_TYPE_SET_CLOSURE

        sender.assert_can_ask_action_status_update(action, request_type)

        action_request = ActionRequest(action=action,
                                       sender=sender,
                                       request_notes=message,
                                       request_type=request_type)
        action_request.save()

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
Beispiel #5
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        #recipient = form.cleaned_data['referrer']
        recipient = action.referrers
        message = form.cleaned_data['message_text']
        request_type = consts.REQUEST_TYPE_MESSAGE

        sender.assert_can_send_action_message(sender, recipient, action)

        action_request = ActionRequest(action=action,
                                       sender=sender,
                                       request_notes=message,
                                       request_type=request_type)
        action_request.save()
        action_request.recipient_set.add(*recipient)
        action_request.save()

        action_message_sent.send(sender=action_request)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
Beispiel #6
0
    def form_valid(self, form):

        sender = self.request.user
        action = self.get_object()

        recipient = form.cleaned_data['follower']
        request_notes = form.cleaned_data['request_text']
        request_type = consts.REQUEST_TYPE_MODERATION

        sender.assert_can_request_moderation_for_action(
            sender, recipient, action)
        #print("RECIPIENT: %s", recipient)
        action_request = ActionRequest(action=action,
                                       sender=sender,
                                       request_notes=request_notes,
                                       request_type=request_type)
        action_request.save()
        action_request.recipient_set.add(recipient)
        action_request.save()

        action_moderation_request_submitted.send(sender=action_request)

        success_url = action.get_absolute_url()
        return views_support.response_redirect(self.request, success_url)
Beispiel #7
0
    def test_follower_user_responses(self, user=None):

        logged_in = self._login(user)
        login_user = [self._author, user][bool(user)]
        request_text = "Ti chiedo di moderare la mia action"
        request_type = ar_consts.REQUEST_TYPE_MODERATION
        action_requests = [0, 1]

        if logged_in:

            for a_r in action_requests:
                n = int(a_r)
                action_requests[n] = ActionRequest(action=self._action,
                                                   sender=login_user,
                                                   request_notes=request_text,
                                                   request_type=request_type)
                action_requests[n].save()
                action_requests[n].recipient_set.add(self.follower)
                action_requests[n].save()
        else:
            raise Exception

        #for a_r in action_requests:
        #    print("\naction_requests_created.pk=%s\n" % a_r.pk)
        #for a_r in ActionRequest.objects.all():
        #    print("\naction_requests.pk=%s\n" % a_r.pk)

        logged_in = self._login(self.follower)

        if logged_in:
            answer_text = "non mi va di moderare la tua action del cavolo"

            response = self._do_POST_process_action_moderation_request(
                action_request=action_requests[0],
                ajax=True,
                accept_request=0,
                answer_text=answer_text)

            self._check_for_redirect_response(response, is_ajax=True)

            action_request_not_accepted = ActionRequest.objects.get(
                pk=action_requests[0].pk)
            #print("\nis_accepted=%s\n" % action_request_not_accepted.is_accepted)
            self.assertTrue(action_request_not_accepted.is_processed)
            self.assertTrue(not action_request_not_accepted.is_accepted)
            self.assertTrue(
                action_request_not_accepted.answer_notes == answer_text)

            notice_obj = self._get_notice_objs(
                notice_label="answer_mod_proposal", recipient=login_user)

            self.assertTrue(notice_obj)

            #test the follower user response
            answer_text = "che figata, accetto subito!"

            response = self._do_POST_process_action_moderation_request(
                action_request=action_requests[1],
                ajax=True,
                accept_request=1,
                answer_text=answer_text)

            #print("\n\nRESPONSE-----------------------: %s" % response)
            self._check_for_error_response(
                response,
                e=action_request_exceptions.UserCannotProcessARequestTwice)

            duplicated_action_request = ActionRequest.objects.get(
                pk=action_requests[1].pk)
            answer_text = "moderation request processed and %s accepted with action_request %s" % (
                action_request_not_accepted.pk,
                ["", "not"][not action_request_not_accepted.is_accepted])

            self.assertTrue(duplicated_action_request.is_processed)
            self.assertTrue(not duplicated_action_request.is_accepted)
            self.assertTrue(
                duplicated_action_request.answer_notes == answer_text)