Update kb vote function

This commit is contained in:
Sam Splunks 2024-12-05 09:47:23 +00:00
parent f710c07927
commit 8d2b09bb11
4 changed files with 6 additions and 7 deletions

View File

@ -25,8 +25,8 @@
<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>
<a href='{% url "helpdesk:kb_vote" item.pk "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 "down" %}'><div class="btn btn-danger btn-circle btn-xl"><i class="fa fa-thumbs-down fa-lg"></i></div></a>
</div>
{% endif %}
{% if staff %}

View File

@ -67,14 +67,14 @@ class KBTests(TestCase):
self.client.login(username=self.user.get_username(),
password='password')
response = self.client.get(
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk,)) + "?vote=up")
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk, "up")))
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")
reverse('helpdesk:kb_vote', args=(self.kbitem1.pk, "down")))
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"),
path("kb/<int:item>/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,9 +59,8 @@ 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