From 473b80d171eacfb7cc4ff943d3702fed54f0721c Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 15 Jun 2024 18:04:43 +0200 Subject: [PATCH] stash --- core/tickets/api_v2.py | 10 ++++++++-- core/tickets/models.py | 11 +++++++++++ core/tickets/serializers.py | 9 ++++++++- web/src/components/CollapsableCards.vue | 25 +++++++++++++++++++++++++ web/src/store.js | 2 +- 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/core/tickets/api_v2.py b/core/tickets/api_v2.py index cd9cd3e..c32f7b3 100644 --- a/core/tickets/api_v2.py +++ b/core/tickets/api_v2.py @@ -13,8 +13,8 @@ from core.settings import MAIL_DOMAIN from mail.models import Email from mail.protocol import send_smtp, make_reply, collect_references from notify_sessions.models import SystemEvent -from tickets.models import IssueThread, Comment, STATE_CHOICES -from tickets.serializers import IssueSerializer, CommentSerializer +from tickets.models import IssueThread, Comment, STATE_CHOICES, ShippingCode +from tickets.serializers import IssueSerializer, CommentSerializer, ShippingCodeSerializer class IssueViewSet(viewsets.ModelViewSet): @@ -22,6 +22,11 @@ class IssueViewSet(viewsets.ModelViewSet): queryset = IssueThread.objects.all() +class ShippingCodeViewSet(viewsets.ModelViewSet): + serializer_class = ShippingCodeSerializer + queryset = ShippingCode.objects.all() + + @api_view(['POST']) @permission_classes([IsAuthenticated]) @permission_required('tickets.add_issuethread', raise_exception=True) @@ -113,6 +118,7 @@ def add_comment(request, pk): router = routers.SimpleRouter() router.register(r'tickets', IssueViewSet, basename='issues') +router.register(r'shipping_codes', ShippingCodeViewSet, basename='shipping_codes') urlpatterns = ([ re_path(r'^tickets/(?P\d+)/reply/$', reply, name='reply'), diff --git a/core/tickets/models.py b/core/tickets/models.py index 49fb335..6eb84ed 100644 --- a/core/tickets/models.py +++ b/core/tickets/models.py @@ -136,3 +136,14 @@ class ItemRelation(models.Model): def __str__(self): return str(self.issue_thread) + ' related to ' + str(self.item) + + +class ShippingCode(models.Model): + id = models.AutoField(primary_key=True) + issue_thread = models.ForeignKey(IssueThread, on_delete=models.CASCADE, related_name='shipping_codes', null=True) + code = models.CharField(max_length=255) + timestamp = models.DateTimeField(auto_now_add=True) + used_at = models.DateTimeField(null=True) + + def __str__(self): + return str(self.issue_thread) + ' shipping code ' + self.code \ No newline at end of file diff --git a/core/tickets/serializers.py b/core/tickets/serializers.py index 1236283..6625a81 100644 --- a/core/tickets/serializers.py +++ b/core/tickets/serializers.py @@ -2,7 +2,7 @@ from rest_framework import serializers from authentication.models import ExtendedUser from mail.api_v2 import AttachmentSerializer -from tickets.models import IssueThread, Comment, STATE_CHOICES +from tickets.models import IssueThread, Comment, STATE_CHOICES, ShippingCode from inventory.serializers import ItemSerializer @@ -29,6 +29,13 @@ class StateSerializer(serializers.Serializer): return obj['value'] +class ShippingCodeSerializer(serializers.Serializer): + class Meta: + model = ShippingCode + fields = ('id', 'code', 'timestamp', 'issue_thread', 'used_at') + read_only_fields = ('id', 'timestamp', 'used_at') + + class IssueSerializer(serializers.ModelSerializer): timeline = serializers.SerializerMethodField() last_activity = serializers.SerializerMethodField() diff --git a/web/src/components/CollapsableCards.vue b/web/src/components/CollapsableCards.vue index d1edab7..a982e3a 100644 --- a/web/src/components/CollapsableCards.vue +++ b/web/src/components/CollapsableCards.vue @@ -1,6 +1,31 @@