Skip to content

Commit

Permalink
refactor: Further refine reclassification to avoid redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
pselkirk committed Jul 27, 2023
1 parent 4cb0c3b commit a19fb30
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 78 deletions.
21 changes: 6 additions & 15 deletions ietf/nomcom/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand All @@ -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')
Expand Down
1 change: 0 additions & 1 deletion ietf/nomcom/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
url(r'^(?P<year>\d{4})/private/reclassify-feedback/unrelated/$', views.reclassify_feedback_unrelated),
url(r'^(?P<year>\d{4})/private/reclassify-feedback/nominee/(?P<nominee_id>\d+)$', views.reclassify_feedback_nominee),
url(r'^(?P<year>\d{4})/private/reclassify-feedback/topic/(?P<topic_id>\d+)$', views.reclassify_feedback_topic),
url(r'^(?P<year>\d{4})/private/reclassify-feedback/(?P<feedback_id>\d+)$', views.reclassify_feedback_item),
url(r'^(?P<year>\d{4})/private/edit/nominee/(?P<nominee_id>\d+)$', views.edit_nominee),
url(r'^(?P<year>\d{4})/private/merge-nominee/?$', views.private_merge_nominee),
url(r'^(?P<year>\d{4})/private/merge-person/?$', views.private_merge_person),
Expand Down
112 changes: 60 additions & 52 deletions ietf/nomcom/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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,
Expand All @@ -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)

Expand All @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions ietf/templates/nomcom/reclassify_feedback_item.html
Original file line number Diff line number Diff line change
@@ -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 %}
<h2 class="mt-3">Reclassify feedback item</h2>
<form method="post">
{% csrf_token %}
Expand Down Expand Up @@ -103,7 +98,6 @@ <h2 class="mt-3">Reclassify feedback item</h2>
</tr>
</tbody>
</table>
<input type="hidden" name="back_url" value="{{ back_url }}">
<input type="hidden" name="feedback_id" value="{{ feedback.id }}">
<button class="btn btn-primary" type="submit">Classify</button>
</form>
{% endblock %}
6 changes: 5 additions & 1 deletion ietf/templates/nomcom/reclassify_feedback_nominee.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<h2>Reclassify feedback about {{ nominee }}</h2>
<ul class="nav nav-tabs my-3" role="tablist">
{% for ft in feedback_types %}
Expand Down Expand Up @@ -101,6 +104,7 @@ <h2>Reclassify feedback about {{ nominee }}</h2>
</div>
<a class="btn btn-secondary"
href="{% url 'ietf.nomcom.views.reclassify_feedback' year %}">Back</a>
{% endif %}
{% endblock %}
{% block js %}
<script>
Expand Down
6 changes: 5 additions & 1 deletion ietf/templates/nomcom/reclassify_feedback_topic.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
{% load nomcom_tags textfilters %}
{% block subtitle %}- Reclassify feedback about {{ topic.subject }}{% endblock %}
{% block nomcom_content %}
{% origin %}
{% origin %}
{% if feedback %}
{% include "nomcom/reclassify_feedback_item.html" %}
{% else %}
<h2>Reclassify feedback about {{ topic.subject }}</h2>
<ul class="nav nav-tabs my-3" role="tablist">
{% for ft in feedback_types %}
Expand Down Expand Up @@ -64,6 +67,7 @@ <h2>Reclassify feedback about {{ topic.subject }}</h2>
</div>
<a class="btn btn-secondary"
href="{% url 'ietf.nomcom.views.reclassify_feedback' year %}">Back</a>
{% endif %}
{% endblock %}
{% block js %}
<script>
Expand Down
6 changes: 5 additions & 1 deletion ietf/templates/nomcom/reclassify_feedback_unrelated.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
{% load nomcom_tags textfilters %}
{% block subtitle %}- Reclassify unrelated feedback{% endblock %}
{% block nomcom_content %}
{% origin %}
{% origin %}
{% if feedback %}
{% include "nomcom/reclassify_feedback_item.html" %}
{% else %}
<h2>Reclassify feedback not related to nominees</h2>
<ul role="tablist" class="nav nav-tabs my-3">
{% for ft in feedback_types %}
Expand Down Expand Up @@ -65,6 +68,7 @@ <h2>Reclassify feedback not related to nominees</h2>
<a class="btn btn-secondary"
href="{% url 'ietf.nomcom.views.reclassify_feedback' year %}">Back</a>
</p>
{% endif %}
{% endblock %}
{% block js %}
<script>
Expand Down

0 comments on commit a19fb30

Please sign in to comment.