Skip to content

Commit

Permalink
feat(core): Add ticket comment categories
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Sep 13, 2024
1 parent 1161bf7 commit 11948c9
Show file tree
Hide file tree
Showing 12 changed files with 508 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/core/forms/ticket_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class DetailForm(TicketCategoryForm):
"name": "Ticket Types",
"left": [
'change',
'problem'
'problem',
'request'
],
"right": [
Expand Down
119 changes: 119 additions & 0 deletions app/core/forms/ticket_comment_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from django import forms
from django.forms import ValidationError
from django.urls import reverse

from app import settings

from core.forms.common import CommonModelForm
from core.models.ticket.ticket_comment_category import TicketCommentCategory



class TicketCommentCategoryForm(CommonModelForm):


class Meta:

fields = '__all__'

model = TicketCommentCategory

prefix = 'ticket_comment_category'

def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

self.fields['parent'].queryset = self.fields['parent'].queryset.exclude(
id=self.instance.pk
)


def clean(self):

cleaned_data = super().clean()

pk = self.instance.id

parent = cleaned_data.get("parent")

if pk:

if parent == pk:

raise ValidationError("Category can't have itself as its parent category")

return cleaned_data



class DetailForm(TicketCommentCategoryForm):


tabs: dict = {
"details": {
"name": "Details",
"slug": "details",
"sections": [
{
"layout": "double",
"left": [
'parent',
'name',
'runbook',
'organization',
'c_created',
'c_modified'
],
"right": [
'model_notes',
]
},
{
"layout": "double",
"name": "Comment Types",
"left": [
'comment',
'solution'
],
"right": [
'notification',
'task'
]
},
]
},
"notes": {
"name": "Notes",
"slug": "notes",
"sections": []
}
}


def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)


self.fields['c_created'] = forms.DateTimeField(
label = 'Created',
input_formats=settings.DATETIME_FORMAT,
disabled = True,
initial = self.instance.created,
)

self.fields['c_modified'] = forms.DateTimeField(
label = 'Modified',
input_formats=settings.DATETIME_FORMAT,
disabled = True,
initial = self.instance.modified,
)


self.tabs['details'].update({
"edit_url": reverse('Settings:_ticket_comment_category_change', kwargs={'pk': self.instance.pk})
})

self.url_index_view = reverse('Settings:_ticket_comment_categories')

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.8 on 2024-09-13 01:31
# Generated by Django 5.0.8 on 2024-09-13 03:43

import access.fields
import access.models
Expand Down Expand Up @@ -99,6 +99,29 @@ class Migration(migrations.Migration):
name='category',
field=models.ForeignKey(blank=True, help_text='Category for this ticket', null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.ticketcategory', verbose_name='Category'),
),
migrations.CreateModel(
name='TicketCommentCategory',
fields=[
('is_global', models.BooleanField(default=False)),
('model_notes', models.TextField(blank=True, default=None, null=True, verbose_name='Notes')),
('id', models.AutoField(help_text='Category ID Number', primary_key=True, serialize=False, unique=True, verbose_name='Number')),
('created', access.fields.AutoCreatedField(default=django.utils.timezone.now, editable=False)),
('modified', access.fields.AutoLastModifiedField(default=django.utils.timezone.now, editable=False)),
('name', models.CharField(help_text='Category Name', max_length=50, verbose_name='Name')),
('comment', models.BooleanField(default=True, help_text='Use category for standard comment', verbose_name='Change Comment')),
('notification', models.BooleanField(default=True, help_text='Use category for notification comment', verbose_name='Incident Comment')),
('solution', models.BooleanField(default=True, help_text='Use category for solution comment', verbose_name='Problem Comment')),
('task', models.BooleanField(default=True, help_text='Use category for task comment', verbose_name='Project Comment')),
('organization', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='access.organization', validators=[access.models.TenancyObject.validatate_organization_exists])),
('parent', models.ForeignKey(blank=True, help_text='The Parent Category', null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.ticketcommentcategory', verbose_name='Parent Category')),
('runbook', models.ForeignKey(blank=True, help_text='The runbook for this category', null=True, on_delete=django.db.models.deletion.SET_NULL, to='assistance.knowledgebase', verbose_name='Runbook')),
],
options={
'verbose_name': 'Ticket Comment Category',
'verbose_name_plural': 'Ticket Comment Categories',
'ordering': ['name'],
},
),
migrations.AlterUniqueTogether(
name='ticket',
unique_together={('external_system', 'external_ref')},
Expand Down
103 changes: 103 additions & 0 deletions app/core/models/ticket/ticket_comment_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
from django.db import models

from access.fields import AutoCreatedField, AutoLastModifiedField
from access.models import TenancyObject, Team

from assistance.models.knowledge_base import KnowledgeBase



class TicketCommentCategoryCommonFields(TenancyObject):

class Meta:
abstract = True

id = models.AutoField(
blank=False,
help_text = 'Category ID Number',
primary_key=True,
unique=True,
verbose_name = 'Number',
)

created = AutoCreatedField()

modified = AutoLastModifiedField()



class TicketCommentCategory(TicketCommentCategoryCommonFields):


class Meta:

ordering = [
'name'
]

verbose_name = "Ticket Comment Category"

verbose_name_plural = "Ticket Comment Categories"


parent = models.ForeignKey(
'self',
blank= True,
help_text = 'The Parent Category',
null = True,
on_delete = models.SET_NULL,
verbose_name = 'Parent Category',
)

name = models.CharField(
blank = False,
help_text = "Category Name",
max_length = 50,
verbose_name = 'Name',
)

runbook = models.ForeignKey(
KnowledgeBase,
blank= True,
help_text = 'The runbook for this category',
null = True,
on_delete = models.SET_NULL,
verbose_name = 'Runbook',
)

comment = models.BooleanField(
blank = False,
default = True,
help_text = 'Use category for standard comment',
null = False,
verbose_name = 'Change Comment',
)

notification = models.BooleanField(
blank = False,
default = True,
help_text = 'Use category for notification comment',
null = False,
verbose_name = 'Incident Comment',
)

solution = models.BooleanField(
blank = False,
default = True,
help_text = 'Use category for solution comment',
null = False,
verbose_name = 'Problem Comment',
)

task = models.BooleanField(
blank = False,
default = True,
help_text = 'Use category for task comment',
null = False,
verbose_name = 'Project Comment',
)


def __str__(self):

return self.name
1 change: 1 addition & 0 deletions app/core/templates/core/index_ticket_categories.html.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends 'base.html.j2' %}

{% block content %}
<input type="button" value="<< Back to settings" onclick="window.location='{% url 'Settings:Settings' %}';">
<input type="button" value="New Category" onclick="window.location='{% url 'Settings:_ticket_category_add' %}';">

<table style="max-width: 100%;">
Expand Down
30 changes: 30 additions & 0 deletions app/core/templates/core/index_ticket_comment_categories.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends 'base.html.j2' %}

{% block content %}
<input type="button" value="<< Back to settings" onclick="window.location='{% url 'Settings:Settings' %}';">
<input type="button" value="New Category" onclick="window.location='{% url 'Settings:_ticket_comment_category_add' %}';">

<table style="max-width: 100%;">
<thead>
<th>Name</th>
<th>Organization</th>
<th>created</th>
<th>modified</th>
<th>&nbsp;</th>
</thead>
{% if items %}
{% for category in items %}
<tr>
<td><a href="{% url 'Settings:_ticket_comment_category_view' pk=category.id %}">{{ category.name }}</a></td>
<td>{{ category.organization }}</td>
<td>{{ category.created }}</td>
<td>{{ category.modified }}</td>
<td>&nbsp;</td>
</tr>
{% endfor %}
{% else %}
<tr><td colspan="5">Nothing Found</td></tr>
{% endif%}
</table>

{% endblock %}
12 changes: 12 additions & 0 deletions app/core/templates/core/ticket_comment_category.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'detail.html.j2' %}


{% block tabs %}

<div id="details" class="content-tab">

{% include 'content/section.html.j2' with tab=form.tabs.details %}

</div>

{% endblock %}
Loading

0 comments on commit 11948c9

Please sign in to comment.