mirror of
https://gitea.mueller.network/extern/django-helpdesk.git
synced 2024-12-26 08:39:08 +01:00
Create an API endpoint to list/create/update/delete tickets (ignoring custom fields)
This commit is contained in:
parent
6b79e1499b
commit
e2cb881eb8
@ -55,6 +55,7 @@ INSTALLED_APPS = [
|
||||
'pinax.teams', # team support
|
||||
'reversion', # required by pinax-teams
|
||||
'helpdesk', # This is us!
|
||||
'rest_framework', # required for the API
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -28,4 +28,5 @@ from django.conf.urls.static import static
|
||||
urlpatterns = [
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^', include('helpdesk.urls', namespace='helpdesk')),
|
||||
url(r'^api/auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
@ -1,18 +1,15 @@
|
||||
from rest_framework import serializers
|
||||
from django.contrib.humanize.templatetags import humanize
|
||||
|
||||
from .models import Ticket
|
||||
from .lib import format_time_spent
|
||||
|
||||
from django.contrib.humanize.templatetags import humanize
|
||||
|
||||
"""
|
||||
A serializer for the Ticket model, returns data in the format as required by
|
||||
datatables for ticket_list.html. Called from staff.datatables_ticket_list.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class DatatablesTicketSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
A serializer for the Ticket model, returns data in the format as required by
|
||||
datatables for ticket_list.html. Called from staff.datatables_ticket_list.
|
||||
"""
|
||||
ticket = serializers.SerializerMethodField()
|
||||
assigned_to = serializers.SerializerMethodField()
|
||||
submitter = serializers.SerializerMethodField()
|
||||
@ -68,3 +65,12 @@ class DatatablesTicketSerializer(serializers.ModelSerializer):
|
||||
|
||||
def get_kbitem(self, obj):
|
||||
return obj.kbitem.title if obj.kbitem else ""
|
||||
|
||||
|
||||
class TicketSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = Ticket
|
||||
fields = (
|
||||
'id', 'queue', 'title', 'description', 'resolution', 'submitter_email', 'assigned_to', 'status', 'on_hold',
|
||||
'priority', 'due_date', 'last_escalation', 'merged_to'
|
||||
)
|
||||
|
@ -10,13 +10,14 @@ urls.py - Mapping of URL's to our various views. Note we always used NAMED
|
||||
from django.conf.urls import url
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.urls import include
|
||||
from django.views.generic import TemplateView
|
||||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
from helpdesk.decorators import helpdesk_staff_member_required, protect_view
|
||||
from helpdesk import settings as helpdesk_settings
|
||||
from helpdesk.views import feeds, staff, public, login
|
||||
from helpdesk import settings as helpdesk_settings
|
||||
|
||||
from helpdesk.views.api import TicketViewSet
|
||||
|
||||
if helpdesk_settings.HELPDESK_KB_ENABLED:
|
||||
from helpdesk.views import kb
|
||||
@ -218,6 +219,14 @@ urlpatterns += [
|
||||
]
|
||||
|
||||
|
||||
# API
|
||||
router = DefaultRouter()
|
||||
router.register(r'tickets', TicketViewSet, basename='ticket')
|
||||
urlpatterns += [
|
||||
url(r'^api/', include(router.urls))
|
||||
]
|
||||
|
||||
|
||||
urlpatterns += [
|
||||
url(r'^login/$',
|
||||
login.login,
|
||||
|
14
helpdesk/views/api.py
Normal file
14
helpdesk/views/api.py
Normal file
@ -0,0 +1,14 @@
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.permissions import IsAdminUser
|
||||
|
||||
from helpdesk.models import Ticket
|
||||
from helpdesk.serializers import TicketSerializer
|
||||
|
||||
|
||||
class TicketViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
A viewset that provides the standard actions to handle Ticket
|
||||
"""
|
||||
queryset = Ticket.objects.all()
|
||||
serializer_class = TicketSerializer
|
||||
permission_classes = [IsAdminUser]
|
Loading…
Reference in New Issue
Block a user