Skip to content
Permalink
Browse files
Beginning of integrating ticketchange model
  • Loading branch information
Gary Martin committed Mar 14, 2022
1 parent 8cede40 commit 31087bbed0e4fd6d598b07c6d9519168b5cdaa48
Showing 5 changed files with 59 additions and 4 deletions.
@@ -3,3 +3,4 @@ __pycache__/
db.sqlite3
tags
*.log
.hypothesis/
@@ -2,7 +2,14 @@
from django.shortcuts import get_object_or_404
from rest_framework import serializers
from rest_framework.reverse import reverse
from ..models import Component, Milestone, Product, Ticket, Version
from ..models import (
Component,
Milestone,
Product,
Ticket,
TicketChange,
Version,
)
from functools import partial


@@ -12,6 +19,8 @@ def get_self_url(obj, context, obj_type):
}
if obj_type == 'ticket':
keywords['product_ticket_id'] = obj.product_ticket_id
elif obj_type == 'ticketchange':
keywords['time'] = obj.time
else:
keywords['name'] = obj.name

@@ -55,6 +64,17 @@ class Meta:
fields = ('url', 'name')


class TicketChangeSerializer(ProductChildSerializer):
url = serializers.SerializerMethodField()

class Meta:
model = TicketChange
fields = ('url', 'time', 'author', 'field', 'oldvalue', 'newvalue')

def get_url(self, obj):
return get_self_url(obj, self.context, 'ticketchange')


class TicketSerializer(ProductChildSerializer):
url = serializers.SerializerMethodField()

@@ -66,6 +86,15 @@ class Meta:
'product_ticket_id',
'summary',
'description',
'time',
'changetime',
'reporter',
'owner',
'cc',
'status',
'severity',
'priority',
'keywords',
)
extra_kwargs = {
'product_ticket_id': {'required': False},
@@ -152,6 +181,10 @@ class ProductSerializer(serializers.HyperlinkedModelSerializer):
view_name='product-versions-list',
)

ticketchanges_url = ProductHyperlinkedModelSerializer(
view_name='product-ticketchanges-list',
)

class Meta:
model = Product
fields = (
@@ -164,4 +197,5 @@ class Meta:
'components_url',
'milestones_url',
'versions_url',
'ticketchanges_url',
)
@@ -31,6 +31,7 @@
products_router.register('components', views.ComponentViewSet, basename='product-components')
products_router.register('milestones', views.MilestoneViewSet, basename='product-milestones')
products_router.register('versions', views.VersionViewSet, basename='product-versions')
products_router.register('ticketchanges', views.TicketChangeViewSet, basename='product-ticketchanges')

urlpatterns = [
path('', include(router.urls)),
@@ -49,6 +49,16 @@ class ProductViewSet(viewsets.ModelViewSet):
lookup_field = 'prefix'


class TicketChangeViewSet(viewsets.ModelViewSet):
queryset = models.TicketChange.objects.all()
serializer_class = serializers.TicketChangeSerializer
lookup_field = 'time'

def get_queryset(self, *args, **kwargs):
prefix = self.kwargs['product_prefix']
return models.TicketChange.objects.filter(product=prefix)


class TicketViewSet(viewsets.ModelViewSet):
queryset = models.Ticket.objects.all()
serializer_class = serializers.TicketSerializer
@@ -188,13 +188,22 @@ def save(self, *args, **kwargs):


class TicketChange(models.Model):
ticket = models.ForeignKey(Ticket, on_delete=models.PROTECT)
time = models.BigIntegerField()
ticket = models.ForeignKey(
Ticket,
on_delete=models.PROTECT,
db_column='ticket',
related_name='%(app_label)s_%(class)s_ticket_related',
)
time = models.BigIntegerField(blank=True, null=True)
author = models.TextField(blank=True, null=True)
field = models.TextField()
oldvalue = models.TextField(blank=True, null=True)
newvalue = models.TextField(blank=True, null=True)
product = models.ForeignKey(Product, on_delete=models.PROTECT)
product = models.ForeignKey(
Product,
db_column="product",
on_delete=models.PROTECT,
)

class Meta:
db_table = 'ticket_change'

0 comments on commit 31087bb

Please sign in to comment.