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 datetime import datetime
|
|
|
|
|
|
|
|
from django.http import HttpResponseRedirect
|
|
|
|
from django.shortcuts import render_to_response, get_object_or_404
|
|
|
|
from django.template import RequestContext
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
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.
|
|
|
|
return render_to_response('helpdesk/kb_index.html',
|
2008-05-21 23:16:44 +02:00
|
|
|
RequestContext(request, {
|
2011-02-06 23:51:25 +01:00
|
|
|
'kb_categories': category_list,
|
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()
|
2008-08-19 10:50:38 +02:00
|
|
|
return render_to_response('helpdesk/kb_category.html',
|
2008-05-21 23:16:44 +02:00
|
|
|
RequestContext(request, {
|
|
|
|
'category': category,
|
|
|
|
'items': items,
|
|
|
|
}))
|
|
|
|
|
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)
|
|
|
|
return render_to_response('helpdesk/kb_item.html',
|
|
|
|
RequestContext(request, {
|
|
|
|
'item': item,
|
|
|
|
}))
|
|
|
|
|
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'):
|
|
|
|
item.votes += 1
|
|
|
|
if vote == 'up':
|
|
|
|
item.recommendations += 1
|
|
|
|
item.save()
|
|
|
|
|
|
|
|
return HttpResponseRedirect(item.get_absolute_url())
|
2008-08-19 10:50:38 +02:00
|
|
|
|