Ejemplo n.º 1
0
    def get(self, request, *args, **kwargs):
        cat_id = kwargs.get('pk')

        try:
            cat_id = int(cat_id)
        except Exception as e:
            return Response(
                {
                    "statusType": "failed",
                    "message": 'Invalid Id',
                    "status": 400
                },
                status=status.HTTP_400_BAD_REQUEST)

        category = Category.objects.filter(id=int(cat_id)).first()

        if not category:
            return Response(
                {
                    "statusType": "success",
                    "message": 'Category not Found',
                    "status": 200
                },
                status=status.HTTP_200_OK)
        else:
            serializer = serializers.CategorySerializer(instance=category)

            return Response(
                {
                    "statusType": "success",
                    "data": serializer.data,
                    "status": 200
                },
                status=status.HTTP_200_OK)
Ejemplo n.º 2
0
    def get(self, request, *args, **kwargs):
        categories = Category.objects.all()
        serializer = serializers.CategorySerializer(categories, many=True)

        return Response(
            {
                "statusType": "success",
                "data": serializer.data,
                "status": 200
            },
            status=status.HTTP_200_OK)
Ejemplo n.º 3
0
    def list(self, request):
        language = request.GET.get('lang')
        if language is None or language.lower() == 'en':
            categories = models.Category.objects.all()
            serializer = serializers.CategorySerializer(categories, many=True)
            return Response(serializer.data)

        else:
            categories = models.CategoryTranslation.objects.filter(
                language__code=language.upper())
            serializer = serializers.CategoryTranslationSerializer(categories,
                                                                   many=True)
            return Response(serializer.data)
Ejemplo n.º 4
0
    def post(self, request, *args, **kwargs):
        cat_name = request.data.get('cat_name')
        if not cat_name:
            return Response(
                {
                    "statusType": "failed",
                    "message": 'Please Provide Category Name',
                    "status": 400
                },
                status=status.HTTP_400_BAD_REQUEST)

        cat_image = request.data.get('cat_image')
        is_active = request.data.get('is_active')
        if is_active == 'true' or is_active == 'True':
            is_active = True
        elif is_active == 'false' or is_active == 'False':
            is_active = False
        elif is_active is None:
            is_active = True
        else:
            return Response(
                {
                    "statusType": "failed",
                    "message":
                    'Invalid value for is_active. Please provide true or false or leave blank.',
                    "status": 400
                },
                status=status.HTTP_400_BAD_REQUEST)

        cat_obj = Category.objects.create(cat_name=cat_name,
                                          is_active=is_active,
                                          cat_image=cat_image)
        serializer = serializers.CategorySerializer(cat_obj)

        return Response(
            {
                "statusType": "success",
                "data": serializer.data,
                "status": 200
            },
            status=status.HTTP_200_OK)
Ejemplo n.º 5
0
 def get(self, request, version):
     categories = CoreModels.Category.objects.all()
     return Response(serializers.CategorySerializer(categories,
                                                    many=True).data,
                     status=status.HTTP_200_OK)
Ejemplo n.º 6
0
 def get(self, request, format = None):
     context = {}
     categories = Categories.objects.all()
     serializer = serializers.CategorySerializer(categories, many = True)
     context = serializer.data
     return Response(context)