Skip to content

Commit

Permalink
Preserve filtering on POST (#6384)
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsoulas authored Dec 2, 2024
1 parent 053a597 commit 6fc273a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion kitsune/flagit/jinja2/flagit/includes/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% macro filter_dropdown(form_id, select_id, label, name, default_option, options, selected_filter) %}
<div class="filter-dropdown">
<form id="{{ form_id }}" method="get" action="">
<label for="{{ name }}">{{ label }}</label>
<label for="{{ select_id }}">{{ label }}</label>
<select name="{{ name }}" id="{{ select_id }}">
<option value="">{{ default_option }}</option>
{% for value, display in options %}
Expand Down
11 changes: 7 additions & 4 deletions kitsune/flagit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def get_flagged_objects(reason=None, exclude_reason=None, content_model=None, pr
return queryset


def set_form_action_for_objects(objects, reason=None):
def set_form_action_for_objects(objects, reason=None, product_slug=None):
"""Generate form action URLs for flagged objects."""
for obj in objects:
base_url = reverse("flagit.update", args=[obj.id])
obj.form_action = urlparams(base_url, reason=reason)
obj.form_action = urlparams(base_url, reason=reason, product=product_slug)
return objects


Expand Down Expand Up @@ -139,7 +139,9 @@ def moderate_content(request):
.select_related("content_type", "creator")
.prefetch_related("content_object__product")
)
objects = set_form_action_for_objects(objects, reason=FlaggedObject.REASON_CONTENT_MODERATION)
objects = set_form_action_for_objects(
objects, reason=FlaggedObject.REASON_CONTENT_MODERATION, product_slug=product_slug
)
available_tags = SumoTag.objects.segmentation_tags().values("id", "name")

for obj in objects:
Expand Down Expand Up @@ -171,6 +173,7 @@ def update(request, flagged_object_id):
flagged = get_object_or_404(FlaggedObject, pk=flagged_object_id)
new_status = request.POST.get("status")
reason = request.GET.get("reason")
product = request.GET.get("product")

if new_status:
ct = flagged.content_type
Expand All @@ -183,5 +186,5 @@ def update(request, flagged_object_id):
flagged.status = new_status
flagged.save()
if flagged.reason == FlaggedObject.REASON_CONTENT_MODERATION:
return HttpResponseRedirect(reverse("flagit.moderate_content"))
return HttpResponseRedirect(urlparams(reverse("flagit.moderate_content"), product=product))
return HttpResponseRedirect(urlparams(reverse("flagit.flagged_queue"), reason=reason))

0 comments on commit 6fc273a

Please sign in to comment.