From a19fb306ee1218e909478e75f4cee8f4a69434b7 Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Thu, 27 Jul 2023 12:48:40 -0400 Subject: [PATCH] refactor: Further refine reclassification to avoid redirects --- ietf/nomcom/tests.py | 21 +--- ietf/nomcom/urls.py | 1 - ietf/nomcom/views.py | 112 ++++++++++-------- .../nomcom/reclassify_feedback_item.html | 8 +- .../nomcom/reclassify_feedback_nominee.html | 6 +- .../nomcom/reclassify_feedback_topic.html | 6 +- .../nomcom/reclassify_feedback_unrelated.html | 6 +- 7 files changed, 82 insertions(+), 78 deletions(-) diff --git a/ietf/nomcom/tests.py b/ietf/nomcom/tests.py index cf3e2be4f1..18e1abb671 100644 --- a/ietf/nomcom/tests.py +++ b/ietf/nomcom/tests.py @@ -2892,11 +2892,8 @@ def test_reclassify_feedback_nominee(self): fb.save() self.assertEqual(Feedback.objects.comments().count(), 1) - response = self.client.post(url, {'feedback_id': fb.id}) - self.assertEqual(response.status_code, 302) - response = self.client.post(response.url, {'type': 'obe', 'back_url': url}) - self.assertEqual(response.status_code, 302) - self.assertEqual(response.url, url) + response = self.client.post(url, {'feedback_id': fb.id, 'type': 'obe'}) + self.assertEqual(response.status_code, 200) fb = Feedback.objects.get(id=fb.id) self.assertEqual(fb.type_id,'obe') @@ -2913,11 +2910,8 @@ def test_reclassify_feedback_topic(self): fb.save() self.assertEqual(Feedback.objects.comments().count(), 1) - response = self.client.post(url, {'feedback_id': fb.id}) - self.assertEqual(response.status_code, 302) - response = self.client.post(response.url, {'type': 'unclassified', 'back_url': url}) - self.assertEqual(response.status_code, 302) - self.assertEqual(response.url, url) + response = self.client.post(url, {'feedback_id': fb.id, 'type': 'unclassified'}) + self.assertEqual(response.status_code, 200) fb = Feedback.objects.get(id=fb.id) self.assertEqual(fb.type_id,None) @@ -2932,11 +2926,8 @@ def test_reclassify_feedback_unrelated(self): fb = FeedbackFactory(nomcom=self.nc, type_id='read') self.assertEqual(Feedback.objects.filter(type='read').count(), 1) - response = self.client.post(url, {'feedback_id': fb.id}) - self.assertEqual(response.status_code, 302) - response = self.client.post(response.url, {'type': 'junk', 'back_url': url}) - self.assertEqual(response.status_code, 302) - self.assertEqual(response.url, url) + response = self.client.post(url, {'feedback_id': fb.id, 'type': 'junk'}) + self.assertEqual(response.status_code, 200) fb = Feedback.objects.get(id=fb.id) self.assertEqual(fb.type_id, 'junk') diff --git a/ietf/nomcom/urls.py b/ietf/nomcom/urls.py index 506284654f..69c197ded7 100644 --- a/ietf/nomcom/urls.py +++ b/ietf/nomcom/urls.py @@ -25,7 +25,6 @@ url(r'^(?P\d{4})/private/reclassify-feedback/unrelated/$', views.reclassify_feedback_unrelated), url(r'^(?P\d{4})/private/reclassify-feedback/nominee/(?P\d+)$', views.reclassify_feedback_nominee), url(r'^(?P\d{4})/private/reclassify-feedback/topic/(?P\d+)$', views.reclassify_feedback_topic), - url(r'^(?P\d{4})/private/reclassify-feedback/(?P\d+)$', views.reclassify_feedback_item), url(r'^(?P\d{4})/private/edit/nominee/(?P\d+)$', views.edit_nominee), url(r'^(?P\d{4})/private/merge-nominee/?$', views.private_merge_nominee), url(r'^(?P\d{4})/private/merge-person/?$', views.private_merge_person), diff --git a/ietf/nomcom/views.py b/ietf/nomcom/views.py index ac7b497c7c..677f4e0d3e 100644 --- a/ietf/nomcom/views.py +++ b/ietf/nomcom/views.py @@ -856,6 +856,18 @@ def nominee_staterank(nominee): }) +def type_dict(): + td = OrderedDict() + for t in FeedbackTypeName.objects.all().order_by('pk'): + rest = t.name + slug = rest[0] + rest = rest[1:] + while slug in td and rest: + slug = rest[0] + rest = rest[1] + td[slug] = t + return td + @role_required("Nomcom Chair", "Nomcom Advisor") @nomcom_private_key_required def view_feedback_pending(request, year): @@ -939,21 +951,12 @@ def view_feedback_pending(request, year): formset = FeedbackFormSet(queryset=feedback_page.object_list) for form in formset.forms: form.set_nomcom(nomcom, request.user) - type_dict = OrderedDict() - for t in FeedbackTypeName.objects.all().order_by('pk'): - rest = t.name - slug = rest[0] - rest = rest[1:] - while slug in type_dict and rest: - slug = rest[0] - rest = rest[1] - type_dict[slug] = t return render(request, 'nomcom/view_feedback_pending.html', {'year': year, 'selected': 'feedback_pending', 'formset': formset, 'extra_step': extra_step, - 'type_dict': type_dict, + 'type_dict': type_dict(), 'extra_ids': extra_ids, 'types': FeedbackTypeName.objects.all().order_by('pk'), 'nomcom': nomcom, @@ -964,50 +967,26 @@ def view_feedback_pending(request, year): @role_required("Nomcom Chair", "Nomcom Advisor") @nomcom_private_key_required -def reclassify_feedback_item(request, year, feedback_id): - nomcom = get_nomcom_by_year(year) - feedback = get_object_or_404(Feedback, id=feedback_id) - +def reclassify_feedback_unrelated(request, year): if request.method == 'POST': - type = request.POST.get('type') - if type == 'unclassified': - feedback.type = None - feedback.nominees.clear() - feedback.topics.clear() + feedback_id = request.POST.get('feedback_id', None) + feedback = get_object_or_404(Feedback, id=feedback_id) + type = request.POST.get('type', None) + if type: + if type == 'unclassified': + feedback.type = None + else: + feedback.type = FeedbackTypeName.objects.get(slug=type) + feedback.save() else: - feedback.type = FeedbackTypeName.objects.get(slug=type) - feedback.save() - back_url = request.POST.get('back_url') - return HttpResponseRedirect(back_url) - else: - back_url = request.META.get('HTTP_REFERER', None) - - type_dict = OrderedDict() - for t in FeedbackTypeName.objects.all().order_by('pk'): - rest = t.name - slug = rest[0] - rest = rest[1:] - while slug in type_dict and rest: - slug = rest[0] - rest = rest[1] - type_dict[slug] = t - return render(request, 'nomcom/reclassify_feedback_item.html', + return render(request, 'nomcom/reclassify_feedback_unrelated.html', {'year': year, - 'nomcom': nomcom, + 'nomcom': get_nomcom_by_year(year), 'feedback': feedback, - 'type_dict': type_dict, - 'types': FeedbackTypeName.objects.all().order_by('pk'), - 'back_url': back_url, + 'type_dict': type_dict(), 'is_chair_task' : True, }) -@role_required("Nomcom Chair", "Nomcom Advisor") -@nomcom_private_key_required -def reclassify_feedback_unrelated(request, year): - if request.method == 'POST': - feedback_id = request.POST.get('feedback_id', None) - return HttpResponseRedirect(reverse('ietf.nomcom.views.reclassify_feedback_item',kwargs={'year':year, 'feedback_id': feedback_id})) - return view_or_reclassify_feedback_unrelated(request, year, reclassify=True) @role_required("Nomcom") @@ -1025,7 +1004,6 @@ def view_or_reclassify_feedback_unrelated(request, year, reclassify=False): template = 'nomcom/reclassify_feedback_unrelated.html' if reclassify else 'nomcom/view_feedback_unrelated.html' return render(request, template, {'year': year, - 'selected': 'view_feedback', 'feedback_types': feedback_types, 'nomcom': nomcom, 'is_chair_task': reclassify, @@ -1036,7 +1014,23 @@ def view_or_reclassify_feedback_unrelated(request, year, reclassify=False): def reclassify_feedback_topic(request, year, topic_id): if request.method == 'POST': feedback_id = request.POST.get('feedback_id', None) - return HttpResponseRedirect(reverse('ietf.nomcom.views.reclassify_feedback_item',kwargs={'year':year, 'feedback_id': feedback_id})) + feedback = get_object_or_404(Feedback, id=feedback_id) + type = request.POST.get('type', None) + if type: + if type == 'unclassified': + feedback.type = None + feedback.topics.clear() + else: + feedback.type = FeedbackTypeName.objects.get(slug=type) + feedback.save() + else: + return render(request, 'nomcom/reclassify_feedback_topic.html', + {'year': year, + 'nomcom': get_nomcom_by_year(year), + 'feedback': feedback, + 'type_dict': type_dict(), + 'is_chair_task' : True, + }) return view_or_reclassify_feedback_topic(request, year, topic_id, reclassify=True) @@ -1060,7 +1054,6 @@ def view_or_reclassify_feedback_topic(request, year, topic_id, reclassify): template = 'nomcom/reclassify_feedback_topic.html' if reclassify else 'nomcom/view_feedback_topic.html' return render(request, template, {'year': year, - 'selected': 'view_feedback', 'topic': topic, 'feedback_types': feedback_types, 'last_seen_time' : last_seen_time, @@ -1073,7 +1066,23 @@ def view_or_reclassify_feedback_topic(request, year, topic_id, reclassify): def reclassify_feedback_nominee(request, year, nominee_id): if request.method == 'POST': feedback_id = request.POST.get('feedback_id', None) - return HttpResponseRedirect(reverse('ietf.nomcom.views.reclassify_feedback_item',kwargs={'year':year, 'feedback_id': feedback_id})) + feedback = get_object_or_404(Feedback, id=feedback_id) + type = request.POST.get('type', None) + if type: + if type == 'unclassified': + feedback.type = None + feedback.nominees.clear() + else: + feedback.type = FeedbackTypeName.objects.get(slug=type) + feedback.save() + else: + return render(request, 'nomcom/reclassify_feedback_nominee.html', + {'year': year, + 'nomcom': get_nomcom_by_year(year), + 'feedback': feedback, + 'type_dict': type_dict(), + 'is_chair_task' : True, + }) return view_or_reclassify_feedback_nominee(request, year, nominee_id, reclassify=True) @@ -1097,7 +1106,6 @@ def view_or_reclassify_feedback_nominee(request, year, nominee_id, reclassify): template = 'nomcom/reclassify_feedback_nominee.html' if reclassify else 'nomcom/view_feedback_nominee.html' return render(request, template, {'year': year, - 'selected': 'view_feedback', 'nominee': nominee, 'feedback_types': feedback_types, 'last_seen_time' : last_seen_time, diff --git a/ietf/templates/nomcom/reclassify_feedback_item.html b/ietf/templates/nomcom/reclassify_feedback_item.html index b15a3b1494..a074b57d81 100644 --- a/ietf/templates/nomcom/reclassify_feedback_item.html +++ b/ietf/templates/nomcom/reclassify_feedback_item.html @@ -1,10 +1,5 @@ -{% extends "nomcom/nomcom_private_base.html" %} {# Copyright The IETF Trust 2023, All Rights Reserved #} -{% load origin %} {% load nomcom_tags textfilters %} -{% block subtitle %}- Reclassify feedback item{% endblock %} -{% block nomcom_content %} - {% origin %}

Reclassify feedback item

{% csrf_token %} @@ -103,7 +98,6 @@

Reclassify feedback item

- +
-{% endblock %} diff --git a/ietf/templates/nomcom/reclassify_feedback_nominee.html b/ietf/templates/nomcom/reclassify_feedback_nominee.html index 4c3757f9a4..efa559c361 100644 --- a/ietf/templates/nomcom/reclassify_feedback_nominee.html +++ b/ietf/templates/nomcom/reclassify_feedback_nominee.html @@ -4,7 +4,10 @@ {% load nomcom_tags textfilters %} {% block subtitle %}- Reclassify feedback about {{ nominee.email.person.name }}{% endblock %} {% block nomcom_content %} - {% origin %} +{% origin %} +{% if feedback %} + {% include "nomcom/reclassify_feedback_item.html" %} +{% else %}

Reclassify feedback about {{ nominee }}