Skip to content
Permalink
Browse files
Add swagger for api viewing and more api endpoints
  • Loading branch information
Gary Martin committed Oct 14, 2018
1 parent 31f1b1d commit e810572d83da6650d2cbbe0367a79134d005f385
Showing 7 changed files with 159 additions and 12 deletions.
@@ -11,6 +11,7 @@ PyYAML = "*"
[packages]
django = ">=2.0.0"
djangorestframework = "*"
django-rest-swagger = "*"

[requires]
python_version = "3.6"

Some generated files are not rendered by default. Learn more.

@@ -60,6 +60,7 @@
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework_swagger',
]

MIDDLEWARE = [
@@ -24,13 +24,15 @@

logger = logging.getLogger(__name__)


class ModelCommon(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
created = models.DateTimeField(auto_now_add=True, editable=False)

class Meta:
abstract = True


class Ticket(ModelCommon):
title = models.CharField(max_length=200, null=True)
description = models.TextField(null=True)
@@ -61,10 +63,11 @@ def get_field_value(self, field):
class TicketField(ModelCommon):
name = models.CharField(max_length=32)


class ChangeEvent(ModelCommon):
ticket = models.ForeignKey(Ticket, models.CASCADE, editable=False, null=False)
field = models.ForeignKey(TicketField, models.CASCADE, editable=False, null=False)
diff = models.TextField(editable=False)
ticket = models.ForeignKey(Ticket, models.CASCADE, null=False)
field = models.ForeignKey(TicketField, models.CASCADE)
diff = models.TextField()

def value(self, which=2):
return ''.join(difflib.restore(self.diff.splitlines(keepends=True), which)).strip()
@@ -74,4 +77,3 @@ def value(self, which=2):
def __str__(self):
return "Change to: {}; Field: {}; Diff: {}".format(
self.ticket, self.field, self.diff)

@@ -1,12 +1,19 @@
from rest_framework import serializers
from trackers.models import Ticket
from trackers.models import Ticket, TicketField, ChangeEvent


class TicketSerializer(serializers.ModelSerializer):
class Meta:
model = Ticket
fields = '__all__'


class TicketFieldSerializer(serializers.ModelSerializer):
class Meta:
model = TicketField
fields = '__all__'


class ChangeEventSerializer(serializers.ModelSerializer):
class Meta:
model = ChangeEvent
@@ -20,6 +20,9 @@

urlpatterns = [
path('', views.home, name='home'),
path('schema_view/', views.schema_view),
path('field/', views.TicketFieldListCreate.as_view()),
path('ticket/', views.TicketListCreate.as_view()),
path('ticket/<uuid:id>', views.TicketViewUpdate.as_view()),
path('ticket/<uuid:id>/event/', views.ChangeEventListCreate.as_view()),
]
@@ -18,19 +18,36 @@
from django.http import HttpResponse
from django.shortcuts import render
from rest_framework import generics
from trackers.serializers import TicketSerializer
from trackers.models import Ticket
from . import serializers
from . import models

from rest_framework_swagger.views import get_swagger_view

schema_view = get_swagger_view(title='Bloodhound Core API')


def home(request):
return HttpResponse('<html><title>Bloodhound Trackers</title></html>')


class TicketListCreate(generics.ListCreateAPIView):
queryset = Ticket.objects.all()
serializer_class = TicketSerializer
queryset = models.Ticket.objects.all()
serializer_class = serializers.TicketSerializer


class TicketViewUpdate(generics.RetrieveUpdateAPIView):
queryset = Ticket.objects.all()
serializer_class = TicketSerializer
queryset = models.Ticket.objects.all()
serializer_class = serializers.TicketSerializer
lookup_field = 'id'


class TicketFieldListCreate(generics.ListCreateAPIView):
queryset = models.TicketField.objects.all()
serializer_class = serializers.TicketFieldSerializer
lookup_field = 'ticket'


class ChangeEventListCreate(generics.ListCreateAPIView):
queryset = models.ChangeEvent.objects.all()
serializer_class = serializers.ChangeEventSerializer
lookup_field = 'ticket'

0 comments on commit e810572

Please sign in to comment.