Example #1
0
def create_feedback(request, model, object_id, template_name):

    decision = get_object_or_404(model, id = object_id)
    
    if request.method == "POST":
        if request.POST.get('submit', None) == "Cancel":
            return HttpResponseRedirect(reverse('publicweb_item_detail', args=[unicode(decision.id)]))
        else:
            form = FeedbackForm(request.POST)
            if form.is_valid():
                feedback = form.save(commit=False)
                feedback.decision = decision
                feedback.author = request.user
                feedback.save()
                return HttpResponseRedirect(reverse('publicweb_item_detail', args=[unicode(decision.id)]))
        
        data = dict(form=form)
        context = RequestContext(request, data)
        return render_to_response(template_name, context)

    else:
        form = FeedbackForm()
        
    data = dict(form=form)
    context = RequestContext(request, data)
    return render_to_response(template_name, context)
Example #2
0
 def test_feedback_author_is_assigned_on_feedback_create(self):
     decision = DecisionFactory()
     user = UserFactory()
     request = RequestFactory()
     request.user = user
     feedback_create_view = FeedbackCreate()
     feedback_create_view.request = request
     feedback_create_view.kwargs = {'parent_pk': decision.id}
     form = FeedbackForm()
     form.cleaned_data = {}
     feedback_create_view.form_valid(form)
     feedback = decision.feedback_set.get()
     self.assertEqual(feedback.author, user)
Example #3
0
 def test_feedback_author_is_assigned_on_feedback_create(self):
     decision = DecisionFactory()
     user = UserFactory()
     request = RequestFactory()
     request.user = user
     feedback_create_view = FeedbackCreate()
     feedback_create_view.request = request
     feedback_create_view.kwargs = {'parent_pk': decision.id}
     form = FeedbackForm()
     form.cleaned_data = {}
     feedback_create_view.form_valid(form)
     feedback = decision.feedback_set.get()
     self.assertEqual(feedback.author, user)
Example #4
0
    def test_no_email_sent_when_feedback_edited_by_author(self):
        decision = self.create_and_return_example_decision_with_feedback()

        feedback = decision.feedback_set.all()[0]
        self.assertEqual(feedback.author, self.betty)
        # edit feedback
        self.login(self.betty)
        form = FeedbackForm(instance=feedback)
        form.fields["description"] = "New Updated description."
        form.fields["rating"] = 4
        form.fields["resolved"] = False
        # Empty the test outbox
        mail.outbox = []
        response = self.client.post(reverse("publicweb_feedback_update", args=[feedback.id]), form.fields)
        self.assertEqual(302, response.status_code)
        self.assertEqual(0, len(mail.outbox))
Example #5
0
    def test_email_sent_when_feedback_edited(self):
        decision = self.create_and_return_example_decision_with_feedback()

        settings = NotificationSettings.objects.get(
            user=self.betty,
            organization=decision.organization
        )
        settings.notification_level = FEEDBACK_MAJOR_CHANGES
        settings.save()
        feedback = decision.feedback_set.all()[0]
        self.assertEqual(feedback.author, self.betty)

        # edit feedback, not as author
        self.login(self.charlie)
        assign_perm('edit_decisions_feedback', self.user, self.bettysorg)
        form = FeedbackForm(instance=feedback)
        form.fields['description'] = "New Updated description."
        form.fields['rating'] = 4
        form.fields['resolved'] = False
        form.fields['minor_edit'] = False
        form.fields['watch'] = False
        # Empty the test outbox
        mail.outbox = []

        response = self.client.post(reverse('publicweb_feedback_update',
            args=[feedback.id]), form.fields)

        self.assertEqual(302, response.status_code)
        self.assertEqual([user.email for user in decision.organization.users.filter(is_active=True)], [to for email in mail.outbox for to in email.to])
Example #6
0
    def test_no_email_sent_when_feedback_edited_by_author(self):
        decision = self.create_and_return_example_decision_with_feedback()

        feedback = decision.feedback_set.all()[0]
        self.assertEqual(feedback.author, self.betty)
        # edit feedback
        self.login(self.betty)
        form = FeedbackForm(instance=feedback)
        form.fields['description'] = "New Updated description."
        form.fields['rating'] = 4
        form.fields['resolved'] = False
        # Empty the test outbox
        mail.outbox = []
        response = self.client.post(
            reverse('publicweb_feedback_update', args=[feedback.id]),
            form.fields)
        self.assertEqual(302, response.status_code)
        self.assertEqual(0, len(mail.outbox))
Example #7
0
    def test_email_sent_when_feedback_edited(self):
        decision = self.create_and_return_example_decision_with_feedback()

        feedback = decision.feedback_set.all()[0]
        self.assertEqual(feedback.author, self.betty)
        # edit feedback, not as author
        self.login(self.charlie)
        assign("edit_decisions_feedback", self.user, self.bettysorg)
        form = FeedbackForm(instance=feedback)
        form.fields["description"] = "New Updated description."
        form.fields["rating"] = 4
        form.fields["resolved"] = False
        # Empty the test outbox
        mail.outbox = []
        response = self.client.post(reverse("publicweb_feedback_update", args=[feedback.id]), form.fields)
        ##import pdb; pdb.set_trace()
        self.assertEqual(302, response.status_code)
        self.assertEqual(1, len(mail.outbox))
Example #8
0
    def test_email_sent_when_feedback_edited(self):
        decision = self.create_and_return_example_decision_with_feedback()

        feedback = decision.feedback_set.all()[0]
        self.assertEqual(feedback.author, self.betty)
        # edit feedback, not as author
        self.login(self.charlie)
        assign('edit_decisions_feedback', self.user, self.bettysorg)
        form = FeedbackForm(instance=feedback)
        form.fields['description'] = "New Updated description."
        form.fields['rating'] = 4
        form.fields['resolved'] = False
        # Empty the test outbox
        mail.outbox = []
        response = self.client.post(
            reverse('publicweb_feedback_update', args=[feedback.id]),
            form.fields)
        ##import pdb; pdb.set_trace()
        self.assertEqual(302, response.status_code)
        self.assertEqual(1, len(mail.outbox))
Example #9
0
def update_feedback(request, model, object_id, template_name):

    feedback = get_object_or_404(model, id = object_id)

    if request.method == "POST":
        if request.POST.get('submit', None) == "Cancel":
            return HttpResponseRedirect(feedback.get_parent_url())
        else:
            form = FeedbackForm(request.POST, instance=feedback)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(feedback.get_parent_url())
        
        data = dict(form=form)
        context = RequestContext(request, data)
        return render_to_response(template_name, context)

    else:
        form = FeedbackForm(instance=feedback)
        
    data = dict(form=form)
    context = RequestContext(request, data)
    return render_to_response(template_name, context)
Example #10
0
 def test_feedback_form_has_watch_field(self):
     form = FeedbackForm()
     self.assertIn('watch', form.fields)