2008-05-21 23:16:44 +02:00
|
|
|
"""
|
2011-01-26 00:08:41 +01:00
|
|
|
django-helpdesk - A Django powered ticket tracker for small enterprise.
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
(c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
views/kb.py - Public-facing knowledgebase views. The knowledgebase is a
|
2008-05-21 23:16:44 +02:00
|
|
|
simple categorised question/answer system to show common
|
|
|
|
resolutions to common problems.
|
|
|
|
"""
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
from django.http import HttpResponseRedirect
|
2016-06-21 07:18:06 +02:00
|
|
|
from django.shortcuts import render, get_object_or_404
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2011-09-01 13:01:03 +02:00
|
|
|
from helpdesk import settings as helpdesk_settings
|
2008-05-21 23:16:44 +02:00
|
|
|
from helpdesk.models import KBCategory, KBItem
|
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def index(request):
|
|
|
|
category_list = KBCategory.objects.all()
|
2008-08-19 10:50:38 +02:00
|
|
|
# TODO: It'd be great to have a list of most popular items here.
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/kb_index.html', {
|
|
|
|
'kb_categories': category_list,
|
|
|
|
'helpdesk_settings': helpdesk_settings,
|
|
|
|
})
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def category(request, slug):
|
|
|
|
category = get_object_or_404(KBCategory, slug__iexact=slug)
|
|
|
|
items = category.kbitem_set.all()
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/kb_category.html', {
|
|
|
|
'category': category,
|
|
|
|
'items': items,
|
|
|
|
'helpdesk_settings': helpdesk_settings,
|
|
|
|
})
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def item(request, item):
|
|
|
|
item = get_object_or_404(KBItem, pk=item)
|
2016-10-21 17:14:12 +02:00
|
|
|
return render(request, 'helpdesk/kb_item.html', {
|
2018-09-03 05:27:39 +02:00
|
|
|
'category': item.category,
|
2016-10-21 17:14:12 +02:00
|
|
|
'item': item,
|
|
|
|
'helpdesk_settings': helpdesk_settings,
|
|
|
|
})
|
2008-05-21 23:16:44 +02:00
|
|
|
|
2008-08-19 10:50:38 +02:00
|
|
|
|
2008-05-21 23:16:44 +02:00
|
|
|
def vote(request, item):
|
|
|
|
item = get_object_or_404(KBItem, pk=item)
|
|
|
|
vote = request.GET.get('vote', None)
|
|
|
|
if vote in ('up', 'down'):
|
2018-12-21 03:30:23 +01:00
|
|
|
if request.user not in item.voted_by:
|
2018-10-17 19:39:43 +02:00
|
|
|
|
|
|
|
item.votes += 1
|
|
|
|
if vote == 'up':
|
|
|
|
item.recommendations += 1
|
|
|
|
item.save()
|
2008-05-21 23:16:44 +02:00
|
|
|
|
|
|
|
return HttpResponseRedirect(item.get_absolute_url())
|