Пример #1
0
    def post(self, request, key):
        farm = sawtooth_api.get_or_404(Farm, address.for_farm(key))
        data = validate_using(AddCertSerializer, data=request.data, view=self)

        resp = sawtooth_api.submit_event(
            add_related=Events.AddRelated(
                action="farm_cert",
                object_key=key,
                related_key=data['key']
            ),
            inputs=[address.for_farm(data['key'])],  # farm  key is in the url
            outputs=[address.for_farm(key)]
        )

        return Response(data=resp)
Пример #2
0
    def get(self, request, key=None):
        farm = sawtooth_api.get_or_404(Farm, address.for_farm(key))
        data = sawtooth_api.proto_to_dict(farm)
        sawtooth_api.resolve_keys(data, 'certifications', Certification)

        return Response(
            data=data
        )
Пример #3
0
 def post(self, request, *args, **kwargs):
     data = validate_using(CreateFarmSerializer, data=request.data, view=self)
     farm = Farm(**data)
     resp = sawtooth_api.submit_event(
         farm_create=farm,
         inputs=[address.for_cert(c) for c in farm.certifications],
         outputs=[address.for_farm(data['key'])]  # this is the address we will be writing to
     )
     return Response(data=resp)
Пример #4
0
    def post(self, request):
        data = validate_using(CreateHarvestSerializer,
                              data=request.data,
                              view=self)
        harvest = Harvest(**data)

        resp = sawtooth_api.submit_event(
            harvest_create=harvest,
            inputs=([address.for_farm(f) for f in harvest.farms] +
                    [address.for_shipment(s) for s in harvest.shipments]),
            outputs=[address.for_harvest(harvest.key)],
        )

        return Response(data=resp)
Пример #5
0
    def post(self, request, key):
        harvest = sawtooth_api.get_or_404(Harvest, address.for_harvest(key))
        data = validate_using(AddFarmSerializer, data=request.data, view=self)

        resp = sawtooth_api.submit_event(
            add_related=Events.AddRelated(
                action="harvest_farm",
                object_key=key,  # key from the URL, already validated
                related_key=data[
                    'key']  # key from the post-data, already validated
            ),
            inputs=[address.for_harvest(key),
                    address.for_farm(data['key'])],
            outputs=[address.for_harvest(key)
                     ]  # this is the address we will be writing to
        )

        return Response(data=resp)