Skip to content

Commit

Permalink
temp-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Aug 23, 2024
1 parent c7dfbe7 commit d75e9d5
Show file tree
Hide file tree
Showing 18 changed files with 1,544 additions and 3 deletions.
9 changes: 8 additions & 1 deletion app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from .views import home

from core.views import history
from core.views import history, ticket

from settings.views import user_settings

Expand All @@ -48,6 +48,13 @@
path("history/<str:model_name>/<int:model_pk>", history.View.as_view(), name='_history'),
re_path(r'^static/(?P<path>.*)$', serve,{'document_root': settings.STATIC_ROOT}),


path('ticket/', ticket.View.as_view(), name="_ticket"),

path('ticket/add', ticket.Add.as_view(), name="_ticket"),

path('ticket/<str:ticket_type>/add', ticket.Add.as_view(), name="_ticket"),

]


Expand Down
101 changes: 101 additions & 0 deletions app/core/forms/ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from django import forms
from django.db.models import Q

from app import settings

from core.forms.common import CommonModelForm

from core.models.ticket.ticket import Ticket


class TicketForm(CommonModelForm):

prefix = 'ticket'

class Meta:
model = Ticket
fields = '__all__'


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

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

self.fields['planned_start_date'].widget = forms.widgets.DateTimeInput(attrs={'type': 'datetime-local', 'format': "%Y-%m-%dT%H:%M"})
self.fields['planned_start_date'].input_formats = settings.DATETIME_FORMAT
self.fields['planned_start_date'].format="%Y-%m-%dT%H:%M"

self.fields['planned_finish_date'].widget = forms.widgets.DateTimeInput(attrs={'type': 'datetime-local'})
self.fields['planned_finish_date'].input_formats = settings.DATETIME_FORMAT
self.fields['planned_finish_date'].format="%Y-%m-%dT%H:%M"

self.fields['real_start_date'].widget = forms.widgets.DateTimeInput(attrs={'type': 'datetime-local'})
self.fields['real_start_date'].input_formats = settings.DATETIME_FORMAT
self.fields['real_start_date'].format="%Y-%m-%dT%H:%M"

self.fields['real_finish_date'].widget = forms.widgets.DateTimeInput(attrs={'type': 'datetime-local'})
self.fields['real_finish_date'].input_formats = settings.DATETIME_FORMAT
self.fields['real_finish_date'].format="%Y-%m-%dT%H:%M"

self.fields['description'].widget.attrs = {'style': "height: 800px; width: 900px"}

# choices = kwargs.pop('camp_dates_choices', ())


self.fields['opened_by'].initial = kwargs['user'].pk


original_fields = self.fields.copy()
ticket_type = []

if kwargs['initial']['ticket_type'] == 'request':

ticket_type = self.Meta.model.fields_itsm_request

self.fields['status'].choices = self.Meta.model.TicketStatus.Request

elif kwargs['initial']['ticket_type'] == 'incident':

ticket_type = self.Meta.model.fields_itsm_incident

self.fields['status'].choices = self.Meta.model.TicketStatus.Incident

elif kwargs['initial']['ticket_type'] == 'problem':

ticket_type = self.Meta.model.fields_itsm_problem

self.fields['status'].choices = self.Meta.model.TicketStatus.Problem

elif kwargs['initial']['ticket_type'] == 'change':

ticket_type = self.Meta.model.fields_itsm_change

self.fields['status'].choices = self.Meta.model.TicketStatus.Change

elif kwargs['initial']['ticket_type'] == 'issue':

ticket_type = self.Meta.model.fields_git_issue

self.fields['status'].choices = self.Meta.model.TicketStatus.Git

elif kwargs['initial']['ticket_type'] == 'merge':

ticket_type = self.Meta.model.fields_git_merge

self.fields['status'].choices = self.Meta.model.TicketStatus.Git


if kwargs['user'].is_superuser:

ticket_type += self.Meta.model.tech_fields

# else

# self.fields['opened_by'].widget = self.fields['opened_by'].hidden_widget()


for field in original_fields:

if field not in ticket_type:

del self.fields[field]
Empty file added app/core/models/__init__.py
Empty file.
174 changes: 174 additions & 0 deletions app/core/models/comment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
from django.contrib.auth.models import User
from django.db import models
from django.forms import ValidationError

from access.models import TenancyObject

from change_ticket import ChangeTicket
from ticket.markdown import TicketMarkdown
from ticket.ticket import Ticket



class CommentCommonFields(models.Model):
Expand All @@ -26,8 +32,11 @@ class Meta:
class Comment(
TenancyObject,
CommentCommonFields,
TicketMarkdown,
):

# Validate comment organization is the same as the ticket.


class Meta:

Expand All @@ -36,3 +45,168 @@ class Meta:
'created',
'id',
]

verbose_name = "Comment"

verbose_name_plural = "Comments"



class Comment_ExternalSystem(models.TextChoices): # <null|github|gitlab>
GITHUB = '1', 'Github'
GITLAB = '2', 'Gitlab'


class CommentStatus(models.TextChoices): # <draft|open|closed|in progress|assigned|solved|invalid>
""" Comment Status
Status of the Comment. By design, not all statuses are available for ALL comment types.
## Tasks
"""

TODO = '1', 'Draft'
DONE = '2', 'New'




class CommentType(models.TextChoices):
"""Type of the ticket"""

COMMENT = '1', 'Comment'
TASK = '2', 'Task'
SOLUTION = '3', 'Solution'


parent = models.ForeignKey(
'self',
blank= True,
default = None,
help_text = 'Parent comment this comment creates a discussion with',
null = True,
on_delete=models.CASCADE,
verbose_name = 'Parent Comment',
)


comment_type = models.IntegerField(
blank = False,
choices=CommentType,
default=None,
help_text = 'The type of comment this is',
null=True,
verbose_name = 'Type',
)


ticket = models.ForeignKey(
Ticket,
blank= True,
default = None,
help_text = 'Parent comment this comment creates a discussion with',
null = True,
on_delete=models.CASCADE,
verbose_name = 'Parent Comment',
)


external_ref = models.IntegerField(
blank = True,
default=None,
help_text = 'External System reference',
null=True,
verbose_name = 'Reference Number',
) # external reference or null. i.e. github comment number


external_system = models.IntegerField(
blank = True,
choices=Comment_ExternalSystem,
default=None,
help_text = 'External system this item derives',
null=True,
verbose_name = 'External System',
)


# user


body = models.TextField(
blank = True,
default = None,
help_text = 'Body of Comment',
null = False,
verbose_name = 'Body',
) # text, markdown. validate to ensure a saved comment that does nothing creates nothing


# Duration


# is_private


status = models.IntegerField( # will require validation by ticket type as status for types will be different
blank = False,
choices=CommentStatus,
default=None,
help_text = 'Status of Comment',
null=True,
verbose_name = 'Status',
)


date_closed = models.DateTimeField(
blank = True,
help_text = 'Date closed',
null = True,
verbose_name = 'Closed Date',
)



#
# ITSM Fields
#


# Category

# is_template

# source # helpdesk|direct|phone|email

# responsible_user # user who task is for

# scheduled task # when the task is scheduled for



#
# Project Management fields
#

# planned start date

# planned finish date

# planned duration

# actual start date

# actual finish date



# def __str__(self): # ??????????? what will this need to be

# return self.name


@property
def markdown_comment(self) -> str:

return self.render_markdown(self.body)
1 change: 1 addition & 0 deletions app/core/models/ticket/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import *
14 changes: 14 additions & 0 deletions app/core/models/ticket/change_ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.forms import ValidationError


class ChangeTicket:


@property
def validate_change_ticket(self):

# check status

# check type

pass
19 changes: 19 additions & 0 deletions app/core/models/ticket/markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@



class TicketMarkdown:
"""Ticket and Comment markdown functions
Intended to be used for all areas of a tickets, projects and comments.
"""


def render_markdown(self, markdown):

# Requires context of ticket for ticket markdown

# Requires context of ticket for comment

# requires context of project for project task comment

pass
14 changes: 14 additions & 0 deletions app/core/models/ticket/problem_ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.forms import ValidationError


class ProblemTicket:


@property
def validate_problem_ticket(self):

# check status

# check type

pass
14 changes: 14 additions & 0 deletions app/core/models/ticket/request_ticket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.forms import ValidationError


class RequestTicket:


@property
def validate_request_ticket(self):

# check status

# check type

pass
Loading

0 comments on commit d75e9d5

Please sign in to comment.