django-helpdesk/views/kb.py
Ross Poulton 5040d3d243 * Large change to clean up the codebase: Decrease excess whitespace at ends
of lines; Increase line-wrapping of commands to limit code to 80 columns 
  wherever possible
* Re-built 'en' locale to match some new strings
* Clean up import statements somewhat
2008-08-19 08:50:38 +00:00

59 lines
1.7 KiB
Python

"""
Jutda Helpdesk - A Django powered ticket tracker for small enterprise.
(c) Copyright 2008 Jutda. All Rights Reserved. See LICENSE for details.
views/kb.py - Public-facing knowledgebase views. The knowledgebase is a
simple categorised question/answer system to show common
resolutions to common problems.
"""
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
def index(request):
category_list = KBCategory.objects.all()
# TODO: It'd be great to have a list of most popular items here.
return render_to_response('helpdesk/kb_index.html',
RequestContext(request, {
'categories': category_list,
}))
def category(request, slug):
category = get_object_or_404(KBCategory, slug__iexact=slug)
items = category.kbitem_set.all()
return render_to_response('helpdesk/kb_category.html',
RequestContext(request, {
'category': category,
'items': items,
}))
def item(request, item):
item = get_object_or_404(KBItem, pk=item)
return render_to_response('helpdesk/kb_item.html',
RequestContext(request, {
'item': item,
}))
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())