def queue_start(request): """ Given a queue will change it to started """ if request.method == 'POST': queue = JSONParser().parse(request) try: queue = Queue.objects.get(pk=queue['id']) if not queue.started: queue.started = True queue.modificationCounter += 1 queue.save() # Update all codes associated with such queue AccessCode.objects.filter(queueId=queue.id).update( status=AccessCodeStatus.WAITING.value, modificationCounter=F('modificationCounter') + 1) newSerializer = QueueSerializer(queue) # SSE notify send_event(StreamChannels.JTQ_CHANNEL.value, StreamEventType.QUEUE_STARTED.value, newSerializer.data) return JsonResponse(newSerializer.data, status=200) else: return HttpResponse(status=200) except Queue.DoesNotExist: return HttpResponse(status=404)
def image_profile(request, id): # get student detail by id try: student = Student.objects.get(pk=id) except Student.DoesNotExist: return JsonResponse({'message': 'The student does not exist'}, status=status.HTTP_404_NOT_FOUND) # if request method is POST # add new image to student if request.method == 'POST': req = JSONParser().parse(request) uploaded_file_url = req['url'] req = ImageProfile(student_id=id, url=uploaded_file_url) req.save() return JsonResponse({'message': 'image uploaded'}, status=status.HTTP_201_CREATED) # if request method is GET # get image from student elif request.method == 'GET': try: image_profile = ImageProfile.objects.get(student=student.id) except ImageProfile.DoesNotExist: return JsonResponse( {'message': 'The Image Profile does not exist'}, status=status.HTTP_404_NOT_FOUND) image_profile_serializer = ImageProfileSerializer(image_profile) return JsonResponse(image_profile_serializer.data, status=status.HTTP_200_OK) # add update and delete #### return JsonResponse({}, status=status.HTTP_200_OK)