def labels(self, request, *args, **kwargs): http_status = status.HTTP_400_BAD_REQUEST self.object = instance = self.get_object() if request.method == 'POST': add_tags_to_instance(request, instance) http_status = status.HTTP_201_CREATED tags = instance.tags label = kwargs.get('label') if request.method == 'GET' and label: data = [tag['name'] for tag in tags.filter(name=label).values('name')] elif request.method == 'DELETE' and label: count = tags.count() tags.remove(label) # Accepted, label does not exist hence nothing removed http_status = status.HTTP_200_OK if count > tags.count() \ else status.HTTP_404_NOT_FOUND data = list(tags.names()) else: data = list(tags.names()) if request.method == 'GET': http_status = status.HTTP_200_OK self.etag_data = data return Response(data, status=http_status)
def labels(self, request, *args, **kwargs): http_status = status.HTTP_400_BAD_REQUEST self.object = instance = self.get_object() if request.method == 'POST': add_tags_to_instance(request, instance) http_status = status.HTTP_201_CREATED tags = instance.tags label = kwargs.get('label') if request.method == 'GET' and label: data = [ tag['name'] for tag in tags.filter(name=label).values('name') ] elif request.method == 'DELETE' and label: count = tags.count() tags.remove(label) # Accepted, label does not exist hence nothing removed http_status = status.HTTP_200_OK if count > tags.count() \ else status.HTTP_404_NOT_FOUND data = list(tags.names()) else: data = list(tags.names()) if request.method == 'GET': http_status = status.HTTP_200_OK self.etag_data = data return Response(data, status=http_status)
def labels(self, request, *args, **kwargs): http_status = status.HTTP_400_BAD_REQUEST instance = self.get_object() self.headers = merge_dicts( self.headers, last_modified_header(get_date(instance, 'modified'))) if request.method == 'POST': if add_tags_to_instance(request, instance): http_status = status.HTTP_201_CREATED tags = instance.tags label = kwargs.get('label', None) if request.method == 'GET' and label: data = [tag['name'] for tag in tags.filter(name=label).values('name')] elif request.method == 'DELETE' and label: count = tags.count() tags.remove(label) # Accepted, label does not exist hence nothing removed http_status = status.HTTP_200_OK if count == tags.count() \ else status.HTTP_404_NOT_FOUND data = list(tags.names()) else: data = list(tags.names()) if request.method == 'GET': http_status = status.HTTP_200_OK return Response(data, status=http_status)
def labels(self, request, *args, **kwargs): http_status = status.HTTP_400_BAD_REQUEST instance = self.get_object() if request.method == "POST": if add_tags_to_instance(request, instance): http_status = status.HTTP_201_CREATED tags = instance.tags label = kwargs.get("label", None) if request.method == "GET" and label: data = [tag["name"] for tag in tags.filter(name=label).values("name")] elif request.method == "DELETE" and label: count = tags.count() tags.remove(label) # Accepted, label does not exist hence nothing removed http_status = status.HTTP_200_OK if count == tags.count() else status.HTTP_404_NOT_FOUND data = list(tags.names()) else: data = list(tags.names()) if request.method == "GET": http_status = status.HTTP_200_OK return Response(data, status=http_status)
def labels(self, request, formid, dataid, **kwargs): self.object = self.get_object() status = 400 instance = get_object_or_404(ParsedInstance, instance__pk=int(dataid)) if request.method == 'POST': if add_tags_to_instance(request, instance.instance): status = 201 label = kwargs.get('label', None) if request.method == 'GET' and label: data = [ tag['name'] for tag in instance.instance.tags.filter(name=label).values('name')] elif request.method == 'DELETE' and label: count = instance.instance.tags.count() instance.instance.tags.remove(label) # Accepted, label does not exist hence nothing removed if count == instance.instance.tags.count(): status = 202 data = list(instance.instance.tags.names()) else: data = list(instance.instance.tags.names()) if request.method == 'GET': status = 200 return Response(data, status=status)
def labels(self, request, formid, dataid, **kwargs): self.object = self.get_object() http_status = status.HTTP_400_BAD_REQUEST instance = get_object_or_404(ParsedInstance, instance__pk=int(dataid)) if request.method == 'POST': if add_tags_to_instance(request, instance.instance): http_status = status.HTTP_201_CREATED label = kwargs.get('label', None) if request.method == 'GET' and label: data = [ tag['name'] for tag in instance.instance.tags.filter( name=label).values('name') ] elif request.method == 'DELETE' and label: count = instance.instance.tags.count() instance.instance.tags.remove(label) # Accepted, label does not exist hence nothing removed if count == instance.instance.tags.count(): http_status = status.HTTP_202_ACCEPTED data = list(instance.instance.tags.names()) else: data = list(instance.instance.tags.names()) if request.method == 'GET': http_status = status.HTPP_200_OK return Response(data, status=http_status)
def labels(self, request, *args, **kwargs): http_status = status.HTTP_400_BAD_REQUEST instance = self.get_object() self.headers = merge_dicts( self.headers, last_modified_header(get_date(instance, 'modified'))) if request.method == 'POST': if add_tags_to_instance(request, instance): http_status = status.HTTP_201_CREATED tags = instance.tags label = kwargs.get('label', None) if request.method == 'GET' and label: data = [ tag['name'] for tag in tags.filter(name=label).values('name') ] elif request.method == 'DELETE' and label: count = tags.count() tags.remove(label) # Accepted, label does not exist hence nothing removed http_status = status.HTTP_200_OK if count == tags.count() \ else status.HTTP_404_NOT_FOUND data = list(tags.names()) else: data = list(tags.names()) if request.method == 'GET': http_status = status.HTTP_200_OK return Response(data, status=http_status)