コード例 #1
0
    def post(self, request):

        data = request.POST
        utils.check_tenant(data)
        serializer = self.serializer_class(data=data)
        if serializer.is_valid():
            serializer.save()
            return Response(status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_304_NOT_MODIFIED)
コード例 #2
0
 def get(self, request):
     data = request.GET
     if not utils.check_tenant(data):
         return Response('No Tenant provided',
                         status=status.HTTP_403_FORBIDDEN)
     self.create_filter(data)
     return super(DmtcSupplierInventory, self).get(request)
コード例 #3
0
 def post(self, request):
     """
     Post user data for a given tenant
     :param request: Input request form
     :return: status
     """
     data = request.POST
     utils.check_tenant(data)
     try:
         user = User()
         user.first_name = data.get('first_name', None)
         user.last_name = data.get('last_name', None)
         if 'username' not in data:
             return Response('username necessary',
                             status=status.HTTP_400_BAD_REQUEST)
         else:
             user.username = data.get('username')
         user.email = data.get('email', None)
         user.set_password(data.get('password', 'password'))
         # print(user)
         user.save()
     except Exception as e:
         print(e, 'cannot save user')
         raise e
     dmtc_user = {}
     # print("hello user", user.id)
     tenant_obj = Tenant.objects.filter(id=int(data['tenant']))
     # print(tenant_obj[0].id, "HI RAHUL")
     dmtc_user['tenant'] = tenant_obj[0].id
     dmtc_user['user'] = user.id
     if 'place' not in data:
         return Response('place necessary',
                         status=status.HTTP_400_BAD_REQUEST)
     else:
         dmtc_user['place'] = data.get('place')
     dmtc_user['address'] = data.get('address', None)
     dmtc_user['mobile_no'] = data.get('mobile_no', None)
     dmtc_user['email'] = data.get('email', None)
     dmtc_user['is_admin'] = data.get('is_admin', False)
     print(dmtc_user)
     serializer = DmtcUserSerializer(data=dmtc_user)
     if serializer.is_valid():
         print("It is valid")
         serializer.save()
         return Response(status=status.HTTP_201_CREATED)
     return Response(status=status.HTTP_304_NOT_MODIFIED)
コード例 #4
0
 def get(self, request):
     data = request.GET
     utils.check_tenant(data)
     return super(DmtcBillOrder, self).get(request)
コード例 #5
0
 def get(self, request):
     data = request.GET
     if not utils.check_tenant(data):
         return Response('No Tenant provided',
                         status=status.HTTP_403_FORBIDDEN)
     return super(DmtcSalesman, self).get(request)