Skip to content

Commit

Permalink
Hierarchically structure topics for moderation (#6368)
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsoulas authored Nov 21, 2024
1 parent 4f4206c commit ce74630
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
18 changes: 10 additions & 8 deletions kitsune/flagit/jinja2/flagit/includes/flagged_question.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@ <h3 class="flagged-content__subheading">{{ _('Take Action:') }}</h3>

<form id="topic-update-form-{{ object.content_object.id }}" method="POST">
{% csrf_token %}
<label for="topic">{{ _('Change Topic:') }}</label>
<select id="topic-dropdown-{{ object.content_object.id }}" class="topic-dropdown" name="topic" data-question-id="{{ object.content_object.id }}">
{% for topic in object.available_topics %}
<option value="{{ topic.id }}" {% if topic.id == object.content_object.topic.id %}selected{% endif %}>{{ topic.title }}</option>
{% endfor %}
</select>

<div class="dropdown-wrapper">
<label for="topic-dropdown-{{ object.content_object.id }}">{{ _('Change Topic:') }}</label>
<select id="topic-dropdown-{{ object.content_object.id }}" class="topic-dropdown" name="topic" data-question-id="{{ object.content_object.id }}">
{% for topic in object.available_topics %}
<option value="{{ topic.id }}" {% if topic.id == object.content_object.topic.id %}selected{% endif %}>
{{ topic.title|safe}}
</option>
{% endfor %}
</select>
</div>
<div class="flagged-content__tag-select">
<label for="tag-select-{{ object.content_object.id }}">{{ _('Assign Tags:') }}</label>
<select id="tag-select-{{ object.content_object.id }}" name="tags" multiple class="tag-select" data-question-id="{{ object.content_object.id }}">
{% for tag in object.available_tags %}
<option value="{{ tag.id }}" {% if tag.get('id') in object.saved_tags %}selected{% endif %}>{{ tag.name }}</option>
{% endfor %}

</select>
</div>
</form>
Expand Down
13 changes: 12 additions & 1 deletion kitsune/flagit/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ def flagged_queue(request):
)


def get_hierarchical_topics(topics, parent=None, level=0):
"""Recursively build hierarchical topics."""
hierarchical = []
for topic in topics.filter(parent=parent).order_by("title"):
spaces = "&nbsp;" * (level * 4)
hierarchical.append({"id": topic.id, "title": f"{spaces}{topic.title}"})
hierarchical.extend(get_hierarchical_topics(topics, parent=topic, level=level + 1))
return hierarchical


@login_required
@permission_required("flagit.can_moderate")
def moderate_content(request):
Expand All @@ -123,7 +133,8 @@ def moderate_content(request):

for obj in objects:
question = obj.content_object
obj.available_topics = Topic.active.filter(products=question.product, is_archived=False)
all_topics = Topic.active.filter(is_archived=False, products=question.product)
obj.available_topics = get_hierarchical_topics(all_topics)
obj.available_tags = available_tags
obj.saved_tags = question.tags.values_list("id", flat=True)
return render(
Expand Down

0 comments on commit ce74630

Please sign in to comment.