Skip to content

contract_view#

ContractFilter#

Bases: FilterSet

Source code in src/apps/core/views/contract_view.py
class ContractFilter(filters.FilterSet):
    title = filters.CharFilter(
        field_name="title__values",
        max_length=512,
        lookup_expr="icontains",
        label="title",
    )
    id = filters.CharFilter(max_length=255, lookup_expr="icontains")

ContractViewSet#

Bases: CommonModelViewSet

Source code in src/apps/core/views/contract_view.py
@method_decorator(
    name="list", decorator=swagger_auto_schema(operation_description="List Contracts")
)
class ContractViewSet(CommonModelViewSet):
    serializer_class = ContractModelSerializer
    queryset = Contract.objects.all()
    filterset_class = ContractFilter
    access_policy = ContractAccessPolicy

    @swagger_auto_schema(
        request_body=LegacyContractSerializer(),
        responses={200: ContractModelSerializer(), 201: ContractModelSerializer},
    )
    @action(detail=False, methods=["post"], url_path="from-legacy")
    def from_legacy(self, request):
        contract, created = Contract.create_or_update_from_legacy(request.data)
        rep = ContractModelSerializer(instance=contract).data
        return Response(rep, status=201 if created else 200)