Merge pull request #1221 from samsplunks/bug_fixes

Small bug fixes (ticket and followup title display, vote function)
This commit is contained in:
Christopher Broderick 2024-12-07 00:01:22 +00:00 committed by GitHub
commit 7247682307
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 28 deletions

View File

@ -25,8 +25,10 @@
<div class="row"> <div class="row">
{% if request.user.pk %} {% if request.user.pk %}
<div class="col-sm"> <div class="col-sm">
<a href='{% url "helpdesk:kb_vote" item.pk %}?vote=up'><div class="btn btn-success btn-circle btn-xl"><i class="fa fa-thumbs-up fa-lg"></i></div></a> <form method="post" action="{% url "helpdesk:kb_vote" item.pk "up" %}" style="display: inline">{% csrf_token %}
<a href='{% url "helpdesk:kb_vote" item.pk %}?vote=down'><div class="btn btn-danger btn-circle btn-xl"><i class="fa fa-thumbs-down fa-lg"></i></div></a> <button type="submit" class="btn btn-success btn-circle btn-xl"><i class="fa fa-thumbs-up fa-lg"></i></button></form>
<form method="post" action="{% url "helpdesk:kb_vote" item.pk "down" %}" style="display: inline">{% csrf_token %}
<button type="submit" class="btn btn-danger btn-circle btn-xl"><i class="fa fa-thumbs-down fa-lg"></i></submit></form>
</div> </div>
{% endif %} {% endif %}
{% if staff %} {% if staff %}

View File

@ -35,6 +35,7 @@ window.addEventListener('load', function()
$.get(endpoint, function(data) { $.get(endpoint, function(data) {
$('#ticketsTable tbody').empty(); $('#ticketsTable tbody').empty();
data.results.forEach(function(ticket) { data.results.forEach(function(ticket) {
ticket.title = $('div').text(ticket.title).html();
$('#ticketsTable tbody').append(` $('#ticketsTable tbody').append(`
<tr> <tr>
<td> <td>

View File

@ -42,7 +42,7 @@
{% for followup in ticket.followup_set.all %} {% for followup in ticket.followup_set.all %}
<div class="list-group-item list-group-item-action"> <div class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between"> <div class="d-flex w-100 justify-content-between">
<h5 class="mb-1">{{ followup.title|num_to_link }}</h5> <h5 class="mb-1">{{ followup.title|escape|num_to_link }}</h5>
<small><i class="fas fa-clock"></i>&nbsp;<span class='byline text-info'>{% if followup.user %}by {{ followup.user }},{% endif %} <span title='{{ followup.date|date:"DATETIME_FORMAT" }}'>{{ followup.date|naturaltime }}</span>{% if helpdesk_settings.HELPDESK_ENABLE_TIME_SPENT_ON_TICKET %}{% if followup.time_spent %}{% endif %}, <span>{% trans "time spent" %}: {{ followup.time_spent_formated }}</span>{% endif %} {% if not followup.public %} <span class='private'>({% trans "Private" %})</span>{% endif %}</span></small> <small><i class="fas fa-clock"></i>&nbsp;<span class='byline text-info'>{% if followup.user %}by {{ followup.user }},{% endif %} <span title='{{ followup.date|date:"DATETIME_FORMAT" }}'>{{ followup.date|naturaltime }}</span>{% if helpdesk_settings.HELPDESK_ENABLE_TIME_SPENT_ON_TICKET %}{% if followup.time_spent %}{% endif %}, <span>{% trans "time spent" %}: {{ followup.time_spent_formated }}</span>{% endif %} {% if not followup.public %} <span class='private'>({% trans "Private" %})</span>{% endif %}</span></small>
</div> </div>
<p class="mb-1"> <p class="mb-1">

View File

@ -66,15 +66,15 @@ class KBTests(TestCase):
def test_kb_vote(self): def test_kb_vote(self):
self.client.login(username=self.user.get_username(), self.client.login(username=self.user.get_username(),
password='password') password='password')
response = self.client.get( response = self.client.post(
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk,)) + "?vote=up") reverse('helpdesk:kb_vote', args=(self.kbitem1.pk, "up")), params={})
cat_url = reverse('helpdesk:kb_category', cat_url = reverse('helpdesk:kb_category',
args=("test_cat",)) + "?kbitem=1" args=("test_cat",)) + "?kbitem=1"
self.assertRedirects(response, cat_url) self.assertRedirects(response, cat_url)
response = self.client.get(cat_url) response = self.client.get(cat_url)
self.assertContains(response, '1 people found this answer useful of 1') self.assertContains(response, '1 people found this answer useful of 1')
response = self.client.get( response = self.client.post(
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk,)) + "?vote=down") reverse('helpdesk:kb_vote', args=(self.kbitem1.pk, "down")), params={})
self.assertRedirects(response, cat_url) self.assertRedirects(response, cat_url)
response = self.client.get(cat_url) response = self.client.get(cat_url)
self.assertContains(response, '0 people found this answer useful of 1') self.assertContains(response, '0 people found this answer useful of 1')

View File

@ -251,7 +251,7 @@ if helpdesk_settings.HELPDESK_KB_ENABLED:
path("kb/", kb.index, name="kb_index"), path("kb/", kb.index, name="kb_index"),
re_path(r"^kb/(?P<slug>[A-Za-z0-9_-]+)/$", re_path(r"^kb/(?P<slug>[A-Za-z0-9_-]+)/$",
kb.category, name="kb_category"), kb.category, name="kb_category"),
path("kb/<int:item>/vote/", kb.vote, name="kb_vote"), re_path(r"^kb/(?P<item>\d+)/vote/(?P<vote>up|down)/$", kb.vote, name="kb_vote"),
re_path( re_path(
r"^kb_iframe/(?P<slug>[A-Za-z0-9_-]+)/$", r"^kb_iframe/(?P<slug>[A-Za-z0-9_-]+)/$",
kb.category_iframe, kb.category_iframe,

View File

@ -59,9 +59,9 @@ def category_iframe(request, slug):
return category(request, slug, iframe=True) return category(request, slug, iframe=True)
def vote(request, item): def vote(request, item, vote):
item = get_object_or_404(KBItem, pk=item) item = get_object_or_404(KBItem, pk=item)
vote = request.GET.get('vote', None) if request.method == "POST":
if vote == 'up': if vote == 'up':
if not item.voted_by.filter(pk=request.user.pk): if not item.voted_by.filter(pk=request.user.pk):
item.votes += 1 item.votes += 1

View File

@ -6,7 +6,7 @@ from setuptools import find_packages, setup
import sys import sys
version = '1.2.0' version = '1.3.0'
# Provided as an attribute, so you can append to these instead # Provided as an attribute, so you can append to these instead