Example #1
0
 def post(self, request, format=None):
     user_serializer = UserSerializer(
         data={
             'username': request.data.get('username'),
             'email': request.data.get('email'),
             'password': request.data.get('password')
         })
     user_serializer.is_valid(raise_exception=True)
     group_name = request.data.get('type')
     if group_name == 'seller':
         SellerClient.register_seller(request.data.get('company'),
                                      request.data.get('industry'),
                                      request.data.get('product'))
     elif group_name == 'buyer':
         BuyerClient.register_buyer(request.data.get('company'),
                                    request.data.get('industry'))
     else:
         return Response(status=400,
                         data={'errors': user_serializer.errors})
     group = Group.objects.get(name=group_name)
     user = user_serializer.save()
     group.user_set.add(user)
     return Response(user_serializer.data)
Example #2
0
 def post(self, request, *args, **kwargs):
     filename = None
     quantity = request.data.get('quantity')
     units = request.data.get('units')
     source = request.data.get('source')
     destination = request.data.get('destination')
     if not (quantity and units and source and destination):
         return Response(status=400)
     timestamp = int(time.time())
     filename = str(request.user.id) + str(timestamp)
     if request.FILES:
         key, val = request.FILES.popitem()
         img_url = img_store.upload_file(val[0], filename)
     shipment = models.Shipment.objects.create(
         seller=request.user,
         primary_img_url=img_url
     )
     resp = SellerClient.create_shipment(
         request.user.pk, quantity, units, source, destination, img_url)
     if resp.status != 200:
         img_store.delete_file(filename)
         shipment.delete()
     return Response(resp.json(), status=resp.status_code)
Example #3
0
 def get(self, request, *args, **kwargs):
     resp = SellerClient.get_pending_offers(request.user.pk)
     return Response(resp.json().get('offers'), status=resp.status_code)
Example #4
0
 def post(self, request, *args, **kwargs):
     contract_id = request.data('contractId')
     if contract_id is None:
         return Response(status=400)
     resp = SellerClient.view_contract(contract_id)
     return Response(resp.json(), status=resp.status_code)
Example #5
0
 def post(self, request, *args, **kwargs):
     contract_id = request.data.get('contractId')
     if contract_id is None:
         return Response(status=400)
     resp = SellerClient.decline_offer(contract_id)
     return Response(resp.json(), resp.status_code)
Example #6
0
 def post(self, request, *args, **kwargs):
     offer_id = request.data.get('offerId')
     if offer_id is None:
         return Response(status=400)
     resp = SellerClient.accept_contract(request.user.pk, offer_id)
     return Response(resp.json(), status=resp.status_code)
Example #7
0
 def post(self, request, *args, **kwargs):
     resp = SellerClient.get_shipments_by_seller(request.user.pk)
     print(request.user.pk)
     print(resp.text)
     data = resp.json().get('shipments')
     return Response([zipAllReadings(ship) for ship in data], status=resp.status_code)
Example #8
0
 def post(self, request, *args, **kwargs):
     shipment_id = request.data.get('shipmentId')
     if not shipment_id:
         return Response(status=400)
     resp = SellerClient.get_shipment(shipment_id)
     return Response(zipAllReadings(resp.json().get('shipment')), status=resp.status_code)