-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Add ticket comment categories
- Loading branch information
Showing
12 changed files
with
508 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
app/core/templates/core/index_ticket_comment_categories.html.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> </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> </td> | ||
</tr> | ||
{% endfor %} | ||
{% else %} | ||
<tr><td colspan="5">Nothing Found</td></tr> | ||
{% endif%} | ||
</table> | ||
|
||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %} |
Oops, something went wrong.