enabled custom serializers in my_ endpoints
This commit is contained in:
@@ -8,7 +8,7 @@ from utils.tag_serializers import TagListSerializerField, TaggitSerializer
|
|||||||
class CompanySerializer(TaggitSerializer, serializers.ModelSerializer):
|
class CompanySerializer(TaggitSerializer, serializers.ModelSerializer):
|
||||||
|
|
||||||
tags = TagListSerializerField(required=False)
|
tags = TagListSerializerField(required=False)
|
||||||
geo = PointField(required=False)
|
geo = PointField(required=False, allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Company
|
model = Company
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.core import serializers
|
|
||||||
from django.core.mail import EmailMessage
|
from django.core.mail import EmailMessage
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
User = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
class CustomUserSerializer(serializers.ModelSerializer):
|
class CustomUserSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.CustomUser
|
model = User
|
||||||
fields = ('email', 'full_name', 'role', 'is_active')
|
fields = ('email', 'full_name', 'role', 'is_active')
|
||||||
|
|
||||||
|
|
||||||
class CustomUserReadSerializer(serializers.ModelSerializer):
|
class CustomUserReadSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.CustomUser
|
model = User
|
||||||
fields = ('id', 'email', 'full_name', 'role', 'is_active', 'provider', 'notify')
|
fields = ('id', 'email', 'full_name', 'role', 'is_active', 'provider', 'notify')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import datetime
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.core import serializers
|
|
||||||
from django.utils.http import urlsafe_base64_decode
|
from django.utils.http import urlsafe_base64_decode
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
|
|
||||||
@@ -108,8 +107,9 @@ class UpdateUserView(UpdateAPIView):
|
|||||||
@permission_classes([IsAuthenticated,])
|
@permission_classes([IsAuthenticated,])
|
||||||
def my_user(request):
|
def my_user(request):
|
||||||
qs = User.objects.filter(email=request.user.email)
|
qs = User.objects.filter(email=request.user.email)
|
||||||
data = serializers.serialize('json', qs)
|
user_serializer = core_serializers.CustomUserReadSerializer(qs, many=True)
|
||||||
return Response(data=data)
|
return Response(data=user_serializer.data)
|
||||||
|
|
||||||
|
|
||||||
@api_view(['POST',])
|
@api_view(['POST',])
|
||||||
@permission_classes([IsAdminUser,])
|
@permission_classes([IsAdminUser,])
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.core import serializers
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|||||||
@@ -390,12 +390,11 @@ class ProductSearchTest(TestCase):
|
|||||||
url = f"{self.endpoint}?query_string={query_string}"
|
url = f"{self.endpoint}?query_string={query_string}"
|
||||||
# send in request
|
# send in request
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
|
# import ipdb; ipdb.set_trace()
|
||||||
# check re sponse
|
# check re sponse
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
# check for object creation
|
# check for object creation
|
||||||
data = json.loads(response.data)
|
self.assertEquals(len(response.data), len(expected_instances))
|
||||||
self.assertEquals(len(data), len(expected_instances))
|
|
||||||
|
|
||||||
|
|
||||||
class MyProductsViewTest(APITestCase):
|
class MyProductsViewTest(APITestCase):
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from functools import reduce
|
|||||||
|
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core import serializers
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
@@ -46,8 +45,8 @@ class ProductViewSet(viewsets.ModelViewSet):
|
|||||||
@permission_classes([IsAuthenticated,])
|
@permission_classes([IsAuthenticated,])
|
||||||
def my_products(request):
|
def my_products(request):
|
||||||
qs = Product.objects.filter(creator=request.user)
|
qs = Product.objects.filter(creator=request.user)
|
||||||
data = serializers.serialize('json', qs)
|
product_serializer = ProductSerializer(qs)
|
||||||
return Response(data=data)
|
return Response(data=product_serializer.data)
|
||||||
|
|
||||||
|
|
||||||
@api_view(['POST',])
|
@api_view(['POST',])
|
||||||
@@ -167,7 +166,7 @@ def product_search(request):
|
|||||||
result_set.add(item)
|
result_set.add(item)
|
||||||
|
|
||||||
# serialize and respond
|
# serialize and respond
|
||||||
data = serializers.serialize('json', result_set)
|
product_serializer = ProductSerializer(result_set)
|
||||||
return Response(data=data)
|
return Response(data=product_serializer.data)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Response({"errors": {"details": str(type(e))}})
|
return Response({"errors": {"details": str(type(e))}})
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.core import serializers
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|||||||
Reference in New Issue
Block a user