本文整理汇总了Python中snippets.serializers.SnippetSerializer类的典型用法代码示例。如果您正苦于以下问题:Python SnippetSerializer类的具体用法?Python SnippetSerializer怎么用?Python SnippetSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SnippetSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: snippet_detail
def snippet_detail(request, pk):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return JSONResponse(serializer.data)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
permission_classes = (permissions.IsAuthenticatedOrReadOnly,
IsOwnerOrReadOnly,)
示例2: post
def post(self, request, format=None):
data = JSONParser().parse(request)
serializer = SnippetSerializer(data=data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.data, status = status.HTTP_400_BAD_REQUEST)
示例3: post
def post(self, request, format=None):
serializer = SnippetSerializer(data=request.data)
if serializer.is_valid():
# The create() method of our serializer will now be passed an additional 'owner' field, along with the validated data from the request.
serializer.save(owner=self.request.user)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例4: post
def post(self, request, format = None):
serializer = SnippetSerializer(request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status = status.Http_201_CREATE)
return Response(serializer.errors, status = status.Http_400_BAD_REQUEST)
pass
示例5: put
def put(self, request, pk, format=None):
snippet = self.get_object(pk)
serializer = SnippetSerializer(snippet, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例6: snippet_detail
def snippet_detail(request, pk):
"""
Retrieve, update, or delete a code snippet.
:param request:
:param pk:
:rtype: JSONResponse
:return:
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return JSONResponse(serializer.data)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例7: snippet_detail_api
def snippet_detail_api(request, id):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.raw_query({'rea' : int(id)})
# print JSONResponse(snippet.data)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
if snippet:
all_avisos = snippet.values('rea')[0]
serializer = SnippetSerializer(all_avisos)
return JSONResponse(serializer.data)
else:
all_avisos = [{"Message":"No duplicated ads found."}]
return JSONResponse(all_avisos)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例8: snippet_detail
def snippet_detail(request, pk):
"""
코드 조각 조회, 업데이트, 삭제
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return JSONResponse(serializer.data)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例9: snippet_detail
def snippet_detail(request, month, year):
"""
Retrieve, update or delete a code snippet.
"""
try:
#snippet = Analysis.objects.filter(created__month=month,created__year=year,created__day=4,created__hour__gte=9)
snippet = Analysis.objects.filter(user_id__contains = 1030)
except Analysis.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet, many=True)
return JSONResponse(serializer.data)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例10: post
def post(self,request):
data = JSONParser().parse(request)
serializer = SnippetSerializer(data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data,status=201)
return JSONResponse(serializer.errors,status=400)
示例11: snippet_detail
def snippet_detail(request, pk):
"""
Retrieve, update or delete a snippet instance.
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return Response(serializer.data)
elif request.method == 'PUT':
serializer = SnippetSerializer(snippet, data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
else:
return Response(serializer.errors,
status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'DELETE':
snippet.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
示例12: snippet_detail
def snippet_detail(request, pk, format=None):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return Response(serializer.data)
elif request.method == 'PUT':
#use resquest.data repalce data
#data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=resquest.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)
示例13: snippet_detail
def snippet_detail(request, pk, format=None):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.get(pk=pk)
except Snippet.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
if request.method == 'GET':
serializer = SnippetSerializer(snippet)
return Response(serializer.data)
elif request.method == 'PUT':
# data = JSONParser().parse(request)
# serializer = SnippetSerializer(snippet, data=data)
serializer = SnippetSerializer(snippet, data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'DELETE':
snippet.delete()
return Response(status=status.HTTP_200_OK)
示例14: post
def post(self, request, format=None):
serializer = SnippetSerializer(data=request.data)
if serializer.is_valid():
#serializer.save()
self.perform_create(serializer)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
示例15: snippet_detail
def snippet_detail(request, id):
"""
Retrieve, update or delete a code snippet.
"""
try:
snippet = Snippet.objects.raw_query({'rea' : int(id)})
if not snippet:
return HttpResponse(status=404)
all_avisos = snippet.values('rea')[0]
except Snippet.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SnippetSerializer(all_avisos)
context = {'duplicateds_avisos': all_avisos['rea']}
return render(request, 'duplicateds.html', context)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SnippetSerializer(snippet, data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data)
return JSONResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
snippet.delete()
return HttpResponse(status=204)