fix(kb): no db

This commit is contained in:
Daniele Scasciafratte 2022-03-18 19:33:31 +01:00
parent 347a70e497
commit 7a3260a163
3 changed files with 151 additions and 141 deletions

View File

@ -1275,7 +1275,7 @@ class EmailTemplate(models.Model):
verbose_name = _('e-mail template')
verbose_name_plural = _('e-mail templates')
if helpdesk_settings.HELPDESK_KB_ENABLED:
class KBCategory(models.Model):
"""
Lets help users help themselves: the Knowledge Base is a categorised

View File

@ -1,12 +1,15 @@
from helpdesk.models import (
Ticket,
Queue,
KBCategory,
KBItem,
Queue
)
from helpdesk import settings as helpdesk_settings
if helpdesk_settings.HELPDESK_KB_ENABLED:
from helpdesk.models import (
KBCategory,
KBItem
)
def huser_from_request(req):
return HelpdeskUser(req.user)
@ -38,6 +41,7 @@ class HelpdeskUser:
def get_allowed_kb_categories(self):
categories = []
if helpdesk_settings.HELPDESK_KB_ENABLED:
for cat in KBCategory.objects.all():
if self.can_access_kbcategory(cat):
categories.append(cat)
@ -45,6 +49,7 @@ class HelpdeskUser:
def get_assigned_kb_items(self):
kbitems = []
if helpdesk_settings.HELPDESK_KB_ENABLED:
for item in KBItem.objects.all():
if item.get_team() and item.get_team().is_member(self.user):
kbitems.append(item)

View File

@ -1146,13 +1146,18 @@ def ticket_list(request):
'<a href="http://docs.djangoproject.com/en/dev/ref/databases/#sqlite-string-matching">'
'Django Documentation on string matching in SQLite</a>.')
kbitem_choices = []
kbitem = []
if helpdesk_settings.HELPDESK_KB_ENABLED:
kbitem_choices = [(item.pk, str(item)) for item in KBItem.objects.all()]
kbitem = KBItem.objects.all()
return render(request, 'helpdesk/ticket_list.html', dict(
context,
default_tickets_per_page=request.user.usersettings_helpdesk.tickets_per_page,
user_choices=User.objects.filter(is_active=True, is_staff=True),
kb_items=KBItem.objects.all(),
kb_items=kbitem,
queue_choices=huser.get_queues(),
status_choices=Ticket.STATUS_CHOICES,
kbitem_choices=kbitem_choices,