mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-12-26 08:39:08 +01:00
fix(kb): no db
This commit is contained in:
parent
347a70e497
commit
7a3260a163
@ -1275,166 +1275,166 @@ 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
|
||||
listing of questions & answers.
|
||||
"""
|
||||
|
||||
name = models.CharField(
|
||||
_('Name of the category'),
|
||||
max_length=100,
|
||||
)
|
||||
class KBCategory(models.Model):
|
||||
"""
|
||||
Lets help users help themselves: the Knowledge Base is a categorised
|
||||
listing of questions & answers.
|
||||
"""
|
||||
|
||||
title = models.CharField(
|
||||
_('Title on knowledgebase page'),
|
||||
max_length=100,
|
||||
)
|
||||
name = models.CharField(
|
||||
_('Name of the category'),
|
||||
max_length=100,
|
||||
)
|
||||
|
||||
slug = models.SlugField(
|
||||
_('Slug'),
|
||||
)
|
||||
title = models.CharField(
|
||||
_('Title on knowledgebase page'),
|
||||
max_length=100,
|
||||
)
|
||||
|
||||
description = models.TextField(
|
||||
_('Description'),
|
||||
)
|
||||
slug = models.SlugField(
|
||||
_('Slug'),
|
||||
)
|
||||
|
||||
queue = models.ForeignKey(
|
||||
Queue,
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_('Default queue when creating a ticket after viewing this category.'),
|
||||
)
|
||||
description = models.TextField(
|
||||
_('Description'),
|
||||
)
|
||||
|
||||
public = models.BooleanField(
|
||||
default=True,
|
||||
verbose_name=_("Is KBCategory publicly visible?")
|
||||
)
|
||||
queue = models.ForeignKey(
|
||||
Queue,
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_('Default queue when creating a ticket after viewing this category.'),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return '%s' % self.name
|
||||
public = models.BooleanField(
|
||||
default=True,
|
||||
verbose_name=_("Is KBCategory publicly visible?")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ('title',)
|
||||
verbose_name = _('Knowledge base category')
|
||||
verbose_name_plural = _('Knowledge base categories')
|
||||
def __str__(self):
|
||||
return '%s' % self.name
|
||||
|
||||
def get_absolute_url(self):
|
||||
from django.urls import reverse
|
||||
return reverse('helpdesk:kb_category', kwargs={'slug': self.slug})
|
||||
class Meta:
|
||||
ordering = ('title',)
|
||||
verbose_name = _('Knowledge base category')
|
||||
verbose_name_plural = _('Knowledge base categories')
|
||||
|
||||
def get_absolute_url(self):
|
||||
from django.urls import reverse
|
||||
return reverse('helpdesk:kb_category', kwargs={'slug': self.slug})
|
||||
|
||||
|
||||
class KBItem(models.Model):
|
||||
"""
|
||||
An item within the knowledgebase. Very straightforward question/answer
|
||||
style system.
|
||||
"""
|
||||
voted_by = models.ManyToManyField(
|
||||
settings.AUTH_USER_MODEL,
|
||||
related_name='votes',
|
||||
)
|
||||
downvoted_by = models.ManyToManyField(
|
||||
settings.AUTH_USER_MODEL,
|
||||
related_name='downvotes',
|
||||
)
|
||||
category = models.ForeignKey(
|
||||
KBCategory,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_('Category'),
|
||||
)
|
||||
class KBItem(models.Model):
|
||||
"""
|
||||
An item within the knowledgebase. Very straightforward question/answer
|
||||
style system.
|
||||
"""
|
||||
voted_by = models.ManyToManyField(
|
||||
settings.AUTH_USER_MODEL,
|
||||
related_name='votes',
|
||||
)
|
||||
downvoted_by = models.ManyToManyField(
|
||||
settings.AUTH_USER_MODEL,
|
||||
related_name='downvotes',
|
||||
)
|
||||
category = models.ForeignKey(
|
||||
KBCategory,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_('Category'),
|
||||
)
|
||||
|
||||
title = models.CharField(
|
||||
_('Title'),
|
||||
max_length=100,
|
||||
)
|
||||
title = models.CharField(
|
||||
_('Title'),
|
||||
max_length=100,
|
||||
)
|
||||
|
||||
question = models.TextField(
|
||||
_('Question'),
|
||||
)
|
||||
question = models.TextField(
|
||||
_('Question'),
|
||||
)
|
||||
|
||||
answer = models.TextField(
|
||||
_('Answer'),
|
||||
)
|
||||
answer = models.TextField(
|
||||
_('Answer'),
|
||||
)
|
||||
|
||||
votes = models.IntegerField(
|
||||
_('Votes'),
|
||||
help_text=_('Total number of votes cast for this item'),
|
||||
default=0,
|
||||
)
|
||||
votes = models.IntegerField(
|
||||
_('Votes'),
|
||||
help_text=_('Total number of votes cast for this item'),
|
||||
default=0,
|
||||
)
|
||||
|
||||
recommendations = models.IntegerField(
|
||||
_('Positive Votes'),
|
||||
help_text=_('Number of votes for this item which were POSITIVE.'),
|
||||
default=0,
|
||||
)
|
||||
recommendations = models.IntegerField(
|
||||
_('Positive Votes'),
|
||||
help_text=_('Number of votes for this item which were POSITIVE.'),
|
||||
default=0,
|
||||
)
|
||||
|
||||
last_updated = models.DateTimeField(
|
||||
_('Last Updated'),
|
||||
help_text=_('The date on which this question was most recently changed.'),
|
||||
blank=True,
|
||||
)
|
||||
last_updated = models.DateTimeField(
|
||||
_('Last Updated'),
|
||||
help_text=_('The date on which this question was most recently changed.'),
|
||||
blank=True,
|
||||
)
|
||||
|
||||
team = models.ForeignKey(
|
||||
helpdesk_settings.HELPDESK_TEAMS_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_('Team'),
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
team = models.ForeignKey(
|
||||
helpdesk_settings.HELPDESK_TEAMS_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
verbose_name=_('Team'),
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
|
||||
order = models.PositiveIntegerField(
|
||||
_('Order'),
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
order = models.PositiveIntegerField(
|
||||
_('Order'),
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
|
||||
enabled = models.BooleanField(
|
||||
_('Enabled to display to users'),
|
||||
default=True,
|
||||
)
|
||||
enabled = models.BooleanField(
|
||||
_('Enabled to display to users'),
|
||||
default=True,
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.last_updated:
|
||||
self.last_updated = timezone.now()
|
||||
return super(KBItem, self).save(*args, **kwargs)
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.last_updated:
|
||||
self.last_updated = timezone.now()
|
||||
return super(KBItem, self).save(*args, **kwargs)
|
||||
|
||||
def get_team(self):
|
||||
return helpdesk_settings.HELPDESK_KBITEM_TEAM_GETTER(self)
|
||||
def get_team(self):
|
||||
return helpdesk_settings.HELPDESK_KBITEM_TEAM_GETTER(self)
|
||||
|
||||
def _score(self):
|
||||
""" Return a score out of 10 or Unrated if no votes """
|
||||
if self.votes > 0:
|
||||
return (self.recommendations / self.votes) * 10
|
||||
else:
|
||||
return _('Unrated')
|
||||
score = property(_score)
|
||||
def _score(self):
|
||||
""" Return a score out of 10 or Unrated if no votes """
|
||||
if self.votes > 0:
|
||||
return (self.recommendations / self.votes) * 10
|
||||
else:
|
||||
return _('Unrated')
|
||||
score = property(_score)
|
||||
|
||||
def __str__(self):
|
||||
return '%s: %s' % (self.category.title, self.title)
|
||||
def __str__(self):
|
||||
return '%s: %s' % (self.category.title, self.title)
|
||||
|
||||
class Meta:
|
||||
ordering = ('order', 'title',)
|
||||
verbose_name = _('Knowledge base item')
|
||||
verbose_name_plural = _('Knowledge base items')
|
||||
class Meta:
|
||||
ordering = ('order', 'title',)
|
||||
verbose_name = _('Knowledge base item')
|
||||
verbose_name_plural = _('Knowledge base items')
|
||||
|
||||
def get_absolute_url(self):
|
||||
from django.urls import reverse
|
||||
return str(reverse('helpdesk:kb_category', args=(self.category.slug,))) + "?kbitem=" + str(self.pk)
|
||||
def get_absolute_url(self):
|
||||
from django.urls import reverse
|
||||
return str(reverse('helpdesk:kb_category', args=(self.category.slug,))) + "?kbitem=" + str(self.pk)
|
||||
|
||||
def query_url(self):
|
||||
from django.urls import reverse
|
||||
return str(reverse('helpdesk:list')) + "?kbitem=" + str(self.pk)
|
||||
def query_url(self):
|
||||
from django.urls import reverse
|
||||
return str(reverse('helpdesk:list')) + "?kbitem=" + str(self.pk)
|
||||
|
||||
def num_open_tickets(self):
|
||||
return Ticket.objects.filter(kbitem=self, status__in=(1, 2)).count()
|
||||
def num_open_tickets(self):
|
||||
return Ticket.objects.filter(kbitem=self, status__in=(1, 2)).count()
|
||||
|
||||
def unassigned_tickets(self):
|
||||
return Ticket.objects.filter(kbitem=self, status__in=(1, 2), assigned_to__isnull=True)
|
||||
def unassigned_tickets(self):
|
||||
return Ticket.objects.filter(kbitem=self, status__in=(1, 2), assigned_to__isnull=True)
|
||||
|
||||
def get_markdown(self):
|
||||
return get_markdown(self.answer)
|
||||
def get_markdown(self):
|
||||
return get_markdown(self.answer)
|
||||
|
||||
|
||||
class SavedSearch(models.Model):
|
||||
|
@ -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,16 +41,18 @@ class HelpdeskUser:
|
||||
|
||||
def get_allowed_kb_categories(self):
|
||||
categories = []
|
||||
for cat in KBCategory.objects.all():
|
||||
if self.can_access_kbcategory(cat):
|
||||
categories.append(cat)
|
||||
if helpdesk_settings.HELPDESK_KB_ENABLED:
|
||||
for cat in KBCategory.objects.all():
|
||||
if self.can_access_kbcategory(cat):
|
||||
categories.append(cat)
|
||||
return categories
|
||||
|
||||
def get_assigned_kb_items(self):
|
||||
kbitems = []
|
||||
for item in KBItem.objects.all():
|
||||
if item.get_team() and item.get_team().is_member(self.user):
|
||||
kbitems.append(item)
|
||||
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)
|
||||
return kbitems
|
||||
|
||||
def get_tickets_in_queues(self):
|
||||
|
@ -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 = [(item.pk, str(item)) for item in KBItem.objects.all()]
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user