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">
{% if request.user.pk %}
<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>
<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>
<form method="post" action="{% url "helpdesk:kb_vote" item.pk "up" %}" style="display: inline">{% csrf_token %}
<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>
{% endif %}
{% if staff %}

View File

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

View File

@ -42,7 +42,7 @@
{% for followup in ticket.followup_set.all %}
<div class="list-group-item list-group-item-action">
<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>
</div>
<p class="mb-1">

View File

@ -66,15 +66,15 @@ class KBTests(TestCase):
def test_kb_vote(self):
self.client.login(username=self.user.get_username(),
password='password')
response = self.client.get(
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk,)) + "?vote=up")
response = self.client.post(
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk, "up")), params={})
cat_url = reverse('helpdesk:kb_category',
args=("test_cat",)) + "?kbitem=1"
self.assertRedirects(response, cat_url)
response = self.client.get(cat_url)
self.assertContains(response, '1 people found this answer useful of 1')
response = self.client.get(
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk,)) + "?vote=down")
response = self.client.post(
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk, "down")), params={})
self.assertRedirects(response, cat_url)
response = self.client.get(cat_url)
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"),
re_path(r"^kb/(?P<slug>[A-Za-z0-9_-]+)/$",
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(
r"^kb_iframe/(?P<slug>[A-Za-z0-9_-]+)/$",
kb.category_iframe,

View File

@ -59,24 +59,24 @@ def category_iframe(request, slug):
return category(request, slug, iframe=True)
def vote(request, item):
def vote(request, item, vote):
item = get_object_or_404(KBItem, pk=item)
vote = request.GET.get('vote', None)
if vote == 'up':
if not item.voted_by.filter(pk=request.user.pk):
item.votes += 1
item.voted_by.add(request.user.pk)
item.recommendations += 1
if item.downvoted_by.filter(pk=request.user.pk):
item.votes -= 1
item.downvoted_by.remove(request.user.pk)
if vote == 'down':
if not item.downvoted_by.filter(pk=request.user.pk):
item.votes += 1
item.downvoted_by.add(request.user.pk)
item.recommendations -= 1
if item.voted_by.filter(pk=request.user.pk):
item.votes -= 1
item.voted_by.remove(request.user.pk)
item.save()
if request.method == "POST":
if vote == 'up':
if not item.voted_by.filter(pk=request.user.pk):
item.votes += 1
item.voted_by.add(request.user.pk)
item.recommendations += 1
if item.downvoted_by.filter(pk=request.user.pk):
item.votes -= 1
item.downvoted_by.remove(request.user.pk)
if vote == 'down':
if not item.downvoted_by.filter(pk=request.user.pk):
item.votes += 1
item.downvoted_by.add(request.user.pk)
item.recommendations -= 1
if item.voted_by.filter(pk=request.user.pk):
item.votes -= 1
item.voted_by.remove(request.user.pk)
item.save()
return HttpResponseRedirect(item.get_absolute_url())

View File

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