Skip to main content

Django REST framework - redux-form connector

Project description

drfrf

CircleCI PyPI

Django REST framework - redux-form connector

Installation

$ pipenv install drfrf

Usage

Import and use one of ValidateCreateMixin or ValidateUpdateMixin:

from drfrf import ValidateCreateMixin, ValidateUpdateMixin
from rest_framework import viewsets
from rest_framework.decorators import detail_route, list_route
from shop.models import CartItem
from shop.serializers import CartItemSerializer


class CartItemViewSet(ValidateCreateMixin, ValidateUpdateMixin, viewsets.ModelViewSet):
    queryset = CartItem.objects.all()
    serializer_class = CartItemSerializer

    @list_route(methods=["post"], url_path="validate")
    def validate_list(self, request):
        return self.validate_create(request)

    @detail_route(methods=["post"], url_path="validate")
    def validate_detail(self, request, **kwargs):
        return self.validate_update(request, **kwargs)

Posting invalidate data to /items/validate would return error messages:

HTTP/1.1 400 Bad Request
Content-Length: 99
Content-Type: application/json

{
    "amount": [
        "Your current credit is 36€, please top-up your account before adding to your cart."
    ]
}

Browse the complete example here: https://github.com/Theodo-UK/drfrf/tree/master/example/backend/shop

API

ValidateCreateMixin

Exposes one method: validate_create takes Request, validates the input data against the provided serializer and returns a Response.

ValidateUpdateMixin

Exposes one method: validate_update takes Request with kwargs, validates the input data against the provided serializer and returns a Response.

Frontend integration

If you're using redux-form in your frontend, check out drfrf for the front.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drfrf-0.0.2.tar.gz (3.1 kB view hashes)

Uploaded Source

Built Distribution

drfrf-0.0.2-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page