-
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.
Merge pull request #284 from nofusscomputing/ticket-categories
- Loading branch information
Showing
69 changed files
with
3,509 additions
and
102 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
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,44 @@ | ||
from django.urls import reverse | ||
|
||
from rest_framework import serializers | ||
from rest_framework.fields import empty | ||
|
||
from api.serializers.core.ticket_comment import TicketCommentSerializer | ||
|
||
from core.forms.validate_ticket import TicketValidation | ||
from core.models.ticket.ticket_category import TicketCategory | ||
|
||
|
||
|
||
class TicketCategorySerializer( | ||
serializers.ModelSerializer, | ||
): | ||
|
||
url = serializers.HyperlinkedIdentityField( | ||
view_name="API:_api_ticket_category-detail", format="html" | ||
) | ||
|
||
|
||
class Meta: | ||
|
||
model = TicketCategory | ||
|
||
fields = '__all__' | ||
|
||
read_only_fields = [ | ||
'id', | ||
'url', | ||
] | ||
|
||
|
||
def __init__(self, instance=None, data=empty, **kwargs): | ||
|
||
if instance is not None: | ||
|
||
if hasattr(instance, 'id'): | ||
|
||
self.fields.fields['parent'].queryset = self.fields.fields['parent'].queryset.exclude( | ||
id=instance.id | ||
) | ||
|
||
super().__init__(instance=instance, data=data, **kwargs) |
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,42 @@ | ||
from django.urls import reverse | ||
|
||
from rest_framework import serializers | ||
from rest_framework.fields import empty | ||
|
||
|
||
from core.models.ticket.ticket_comment_category import TicketCommentCategory | ||
|
||
|
||
|
||
class TicketCommentCategorySerializer( | ||
serializers.ModelSerializer, | ||
): | ||
|
||
url = serializers.HyperlinkedIdentityField( | ||
view_name="API:_api_ticket_comment_category-detail", format="html" | ||
) | ||
|
||
|
||
class Meta: | ||
|
||
model = TicketCommentCategory | ||
|
||
fields = '__all__' | ||
|
||
read_only_fields = [ | ||
'id', | ||
'url', | ||
] | ||
|
||
|
||
def __init__(self, instance=None, data=empty, **kwargs): | ||
|
||
if instance is not None: | ||
|
||
if hasattr(instance, 'id'): | ||
|
||
self.fields.fields['parent'].queryset = self.fields.fields['parent'].queryset.exclude( | ||
id=instance.id | ||
) | ||
|
||
super().__init__(instance=instance, data=data, **kwargs) |
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
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
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,79 @@ | ||
from django.shortcuts import get_object_or_404 | ||
|
||
from drf_spectacular.utils import extend_schema, OpenApiResponse | ||
|
||
from rest_framework import generics, viewsets | ||
|
||
from access.mixin import OrganizationMixin | ||
|
||
from api.serializers.core.ticket_category import TicketCategory, TicketCategorySerializer | ||
from api.views.mixin import OrganizationPermissionAPI | ||
|
||
|
||
|
||
class View(OrganizationMixin, viewsets.ModelViewSet): | ||
|
||
permission_classes = [ | ||
OrganizationPermissionAPI | ||
] | ||
|
||
queryset = TicketCategory.objects.all() | ||
|
||
serializer_class = TicketCategorySerializer | ||
|
||
|
||
@extend_schema( | ||
summary='Create a ticket category', | ||
request = TicketCategorySerializer, | ||
responses = { | ||
201: OpenApiResponse(description='Ticket category created', response=TicketCategorySerializer), | ||
403: OpenApiResponse(description='User tried to edit field they dont have access to'), | ||
} | ||
) | ||
def create(self, request, *args, **kwargs): | ||
|
||
return super().create(request, *args, **kwargs) | ||
|
||
|
||
@extend_schema( | ||
summary='Fetch all of a tickets category', | ||
methods=["GET"], | ||
responses = { | ||
200: OpenApiResponse(description='Success', response=TicketCategorySerializer), | ||
} | ||
) | ||
def list(self, request, *args, **kwargs): | ||
|
||
return super().list(request, *args, **kwargs) | ||
|
||
|
||
@extend_schema( | ||
summary='Fetch the selected ticket category', | ||
methods=["GET"], | ||
responses = { | ||
200: OpenApiResponse(description='Success', response=TicketCategorySerializer), | ||
} | ||
) | ||
def retrieve(self, request, *args, **kwargs): | ||
|
||
return super().retrieve(request, *args, **kwargs) | ||
|
||
|
||
@extend_schema( | ||
summary='Update a ticket category', | ||
methods=["PUT"], | ||
responses = { | ||
200: OpenApiResponse(description='Ticket comment updated', response=TicketCategorySerializer), | ||
403: OpenApiResponse(description='User tried to edit field they dont have access to'), | ||
} | ||
) | ||
def update(self, request, *args, **kwargs): | ||
|
||
return super().update(request, *args, **kwargs) | ||
|
||
|
||
def get_view_name(self): | ||
if self.detail: | ||
return "Ticket Category" | ||
|
||
return 'Ticket Categories' |
Oops, something went wrong.