From 00aa880dddfa9b15e57c29025772e3b6118e5c81 Mon Sep 17 00:00:00 2001 From: jedi Date: Thu, 28 Nov 2024 19:20:36 +0100 Subject: [PATCH] stash --- core/inventory/api_v2.py | 14 +++++++++++-- core/inventory/serializers.py | 1 + core/testdata.py | 0 web/src/components/TimelineMail.vue | 19 ++++-------------- web/src/components/TimelineRelatedItem.vue | 21 +++++--------------- web/src/components/TimelineRelatedTicket.vue | 6 +----- 6 files changed, 23 insertions(+), 38 deletions(-) create mode 100644 core/testdata.py diff --git a/core/inventory/api_v2.py b/core/inventory/api_v2.py index 64f9b27..e21bf22 100644 --- a/core/inventory/api_v2.py +++ b/core/inventory/api_v2.py @@ -4,13 +4,17 @@ from rest_framework import routers, viewsets, status from rest_framework.decorators import api_view, permission_classes from rest_framework.response import Response from rest_framework.permissions import IsAuthenticated +from asgiref.sync import async_to_sync +from channels.layers import get_channel_layer from inventory.models import Event, Container, Item, Comment -from inventory.serializers import EventSerializer, ContainerSerializer, CommentSerializer, ItemSerializer, \ - SearchResultSerializer +from inventory.serializers import EventSerializer, ContainerSerializer, ItemSerializer, SearchResultSerializer, \ + CommentSerializer from base64 import b64decode +from notify_sessions.models import SystemEvent + class EventViewSet(viewsets.ModelViewSet): serializer_class = EventSerializer @@ -100,6 +104,12 @@ def add_comment(request, event_slug, id): item=item, comment=request.data['comment'], ) + systemevent = SystemEvent.objects.create(type='comment added', reference=comment.id) + channel_layer = get_channel_layer() + async_to_sync(channel_layer.group_send)( + 'general', {"type": "generic.event", "name": "send_message_to_frontend", "event_id": systemevent.id, + "message": "comment added"} + ) return Response(CommentSerializer(comment).data, status=status.HTTP_201_CREATED) diff --git a/core/inventory/serializers.py b/core/inventory/serializers.py index ac2ddd2..90a75aa 100644 --- a/core/inventory/serializers.py +++ b/core/inventory/serializers.py @@ -25,6 +25,7 @@ class EventSerializer(serializers.ModelSerializer): dict['addresses'] = [EventAddress.objects.get_or_create(address=x)[0] for x in addresses] return dict + class ContainerSerializer(serializers.ModelSerializer): itemCount = serializers.SerializerMethodField() diff --git a/core/testdata.py b/core/testdata.py new file mode 100644 index 0000000..e69de29 diff --git a/web/src/components/TimelineMail.vue b/web/src/components/TimelineMail.vue index 065d56a..6c43267 100644 --- a/web/src/components/TimelineMail.vue +++ b/web/src/components/TimelineMail.vue @@ -1,6 +1,5 @@