Beispiel #1
0
 def post(self, request, *args, **kwargs):
     data_header = self.get_lang()
     files = self.request.FILES.get('file')
     if files:
         excel_type = files.name.split('.')[1]
         if excel_type in ['xlsx', 'xls', 'csv']:
             self.get_queryset().delete()
             df = pd.read_excel(files)
             df.drop_duplicates(keep='first', inplace=True)
             data_list = df.drop_duplicates(subset=[
                 data_header.get('customer_name')
             ],
                                            keep='first').values
             for d in range(len(data_list)):
                 data_validate(str(data_list[d]))
             for i in range(len(data_list)):
                 if str(data_list[i][0]) == 'nan':
                     continue
                 else:
                     if str(data_list[i][1]) == 'nan':
                         data_list[i][1] = 'N/A'
                     if str(data_list[i][2]) == 'nan':
                         data_list[i][2] = 'N/A'
                     if is_number(str(data_list[i][3])):
                         if str(data_list[i][3]) == 'nan':
                             data_list[i][3] = 0
                     else:
                         data_list[i][3] = 0
                     if str(data_list[i][4]) == 'nan':
                         data_list[i][4] = 'N/A'
                     if is_number(str(data_list[i][5])):
                         if str(data_list[i][5]) == 'nan':
                             data_list[i][5] = 0
                     else:
                         data_list[i][5] = 0
                     customer.objects.create(
                         openid=self.request.auth.openid,
                         customer_name=str(data_list[i][0]).strip(),
                         customer_city=str(data_list[i][1]).strip(),
                         customer_address=str(data_list[i][2]).strip(),
                         customer_contact=data_list[i][3],
                         customer_manager=str(data_list[i][4]).strip(),
                         customer_level=data_list[i][5],
                         creater=self.request.auth.name)
         else:
             raise APIException(
                 {"detail": "Can Not Support This File Type"})
     else:
         raise APIException({"detail": "Please Select One File"})
     return Response({"detail": "success"})
Beispiel #2
0
 def post(self, request, *args, **kwargs):
     files = self.request.FILES.get('file')
     if files:
         excel_type = files.name.split('.')[1]
         if excel_type in ['xlsx', 'xls', 'csv']:
             self.get_queryset().delete()
             df = pd.read_excel(files)
             data_list = df.drop_duplicates(keep='first',
                                            inplace=True).values
             for d in range(len(data_list)):
                 data_validate(str(data_list[d]))
             for i in range(len(data_list)):
                 if str(data_list[i][0]) == 'nan':
                     data_list[i][0] = 'N/A'
                 if str(data_list[i][1]) == 'nan':
                     data_list[i][1] = 'N/A'
                 if is_number(str(data_list[i][2])):
                     if str(data_list[i][2]) == 'nan':
                         data_list[i][2] = 0
                 else:
                     data_list[i][2] = 0
                 if is_number(str(data_list[i][3])):
                     if str(data_list[i][3]) == 'nan':
                         data_list[i][3] = 0
                 else:
                     data_list[i][3] = 0
                 if is_number(str(data_list[i][4])):
                     if str(data_list[i][4]) == 'nan':
                         data_list[i][4] = 0
                 else:
                     data_list[i][4] = 0
                 if str(data_list[i][5]) == 'nan':
                     data_list[i][5] = 'N/A'
                 freight.objects.create(
                     openid=self.request.auth.openid,
                     send_city=str(data_list[i][0]).strip(),
                     receiver_city=str(data_list[i][1]).strip(),
                     weight_fee=data_list[i][2],
                     volume_fee=data_list[i][3],
                     min_payment=data_list[i][4],
                     transportation_supplier=str(data_list[i][5]).strip(),
                     creater=self.request.auth.name)
         else:
             raise APIException(
                 {"detail": "Can Not Support This File Type"})
     else:
         raise APIException({"detail": "Please Select One File"})
     return Response({"detail": "success"})
Beispiel #3
0
 def post(self, request, *args, **kwargs):
     files = self.request.FILES.get('file')
     if files:
         excel_type = files.name.split('.')[1]
         if excel_type in ['xlsx', 'xls', 'csv']:
             self.get_queryset().delete()
             df = pd.read_excel(files)
             data_list = df.drop_duplicates(keep='first', inplace=True)
             for d in range(len(data_list)):
                 data_validate(str(data_list[d]))
             for i in range(len(data_list)):
                 if str(data_list[i][0]) == 'nan':
                     continue
                 else:
                     if is_number(str(data_list[i][1])):
                         if str(data_list[i][1]) == 'nan':
                             data_list[i][1] = 0
                     else:
                         data_list[i][1] = 0
                     if is_number(str(data_list[i][2])):
                         if str(data_list[i][2]) == 'nan':
                             data_list[i][2] = 0
                     else:
                         data_list[i][2] = 0
                     capital.objects.create(openid=self.request.auth.openid,
                                            capital_name=str(
                                                data_list[i][0]).strip(),
                                            capital_qty=data_list[i][1],
                                            capital_cost=data_list[i][2],
                                            creater=self.request.auth.name)
         else:
             raise APIException(
                 {"detail": "Can Not Support This File Type"})
     else:
         raise APIException({"detail": "Please Select One File"})
     return Response({"detail": "success"})
Beispiel #4
0
 def create(self, request, *args, **kwargs):
     data_header = self.get_lang()
     files = self.request.FILES.get('file')
     if files:
         excel_type = files.name.split('.')[1]
         if excel_type in ['xlsx', 'xls', 'csv']:
             self.get_queryset().delete()
             goodsunit.objects.all().delete()
             goodsclass.objects.all().delete()
             goodsbrand.objects.all().delete()
             goodscolor.objects.all().delete()
             goodsshape.objects.all().delete()
             goodsspecs.objects.all().delete()
             goodsorigin.objects.all().delete()
             df = pd.read_excel(files)
             df.drop_duplicates(keep='first', inplace=True)
             data_list = df.drop_duplicates(subset=[data_header.get('goods_code')], keep='first').values
             for d in range(len(data_list)):
                 data_validate(str(data_list[d]))
             for i in range(len(data_list)):
                 if str(data_list[i][0]) == 'nan':
                     continue
                 else:
                     if str(data_list[i][1]) == 'nan':
                         data_list[i][1] = 'None'
                     if str(data_list[i][2]) == 'nan':
                         data_list[i][2] = 'None'
                     if is_number(str(data_list[i][3])):
                         if str(data_list[i][3]) == 'nan':
                             data_list[i][3] = 0
                     else:
                         data_list[i][3] = 0
                     if is_number(str(data_list[i][4])):
                         if str(data_list[i][4]) == 'nan':
                             data_list[i][4] = 0
                     else:
                         data_list[i][4] = 0
                     if is_number(str(data_list[i][5])):
                         if str(data_list[i][5]) == 'nan':
                             data_list[i][5] = 0
                     else:
                         data_list[i][5] = 0
                     if is_number(str(data_list[i][6])):
                         if str(data_list[i][6]) == 'nan':
                             data_list[i][6] = 0
                     else:
                         data_list[i][6] = 0
                     if is_number(str(data_list[i][7])):
                         if str(data_list[i][7]) == 'nan':
                             data_list[i][7] = 0
                     else:
                         data_list[i][7] = 0
                     if str(data_list[i][8]) == 'nan':
                         data_list[i][8] = 'None'
                     if str(data_list[i][9]) == 'nan':
                         data_list[i][9] = 'None'
                     if str(data_list[i][10]) == 'nan':
                         data_list[i][10] = 'None'
                     if str(data_list[i][11]) == 'nan':
                         data_list[i][11] = 'None'
                     if str(data_list[i][12]) == 'nan':
                         data_list[i][12] = 'None'
                     if str(data_list[i][13]) == 'nan':
                         data_list[i][13] = 'None'
                     if str(data_list[i][14]) == 'nan':
                         data_list[i][14] = 'None'
                     if is_number(str(data_list[i][15])):
                         if str(data_list[i][15]) == 'nan':
                             data_list[i][15] = 0
                     else:
                         data_list[i][15] = 0
                     if is_number(str(data_list[i][16])):
                         if str(data_list[i][16]) == 'nan':
                             data_list[i][16] = 0
                     else:
                         data_list[i][16] = 0
                     goodslist.objects.create(openid=self.request.auth.openid,
                                              goods_code=str(data_list[i][0]).strip(),
                                              goods_desc=str(data_list[i][1]).strip(),
                                              goods_supplier=str(data_list[i][2]).strip(),
                                              goods_weight=data_list[i][3],
                                              goods_w=data_list[i][4],
                                              goods_d=data_list[i][5],
                                              goods_h=data_list[i][6],
                                              unit_volume=data_list[i][7],
                                              goods_unit=str(data_list[i][8]).strip(),
                                              goods_class=str(data_list[i][9]).strip(),
                                              goods_brand=str(data_list[i][10]).strip(),
                                              goods_color=str(data_list[i][11]).strip(),
                                              goods_shape=str(data_list[i][12]).strip(),
                                              goods_specs=str(data_list[i][13]).strip(),
                                              goods_origin=str(data_list[i][14]).strip(),
                                              goods_cost=data_list[i][15],
                                              goods_price=data_list[i][16],
                                              creater=self.request.auth.name
                                              )
             goods_unit_list = df.drop_duplicates(subset=[data_header.get('goods_unit')], keep='first').loc[:,
                                 data_header.get('goods_unit')].values
             for i in goods_unit_list:
                 if str(i) == 'nan':
                     i = 'None'
                 goodsunit.objects.create(openid=self.request.auth.openid,
                                          goods_unit=str(i).strip(),
                                          creater=self.request.auth.name
                                          )
             goods_class_list = df.drop_duplicates(subset=[data_header.get('goods_class')], keep='first').loc[:,
                                 data_header.get('goods_class')].values
             for i in goods_class_list:
                 if str(i) == 'nan':
                     i = 'None'
                 goodsclass.objects.create(openid=self.request.auth.openid,
                                           goods_class=str(i).strip(),
                                           creater=self.request.auth.name
                                           )
             goods_brand_list = df.drop_duplicates(subset=[data_header.get('goods_brand')], keep='first').loc[:,
                                 data_header.get('goods_brand')].values
             for i in goods_brand_list:
                 if str(i) == 'nan':
                     i = 'None'
                 goodsbrand.objects.create(openid=self.request.auth.openid,
                                           goods_brand=str(i).strip(),
                                           creater=self.request.auth.name
                                           )
             goods_color_list = df.drop_duplicates(subset=[data_header.get('goods_color')], keep='first').loc[:,
                                 data_header.get('goods_color')].values
             for i in goods_color_list:
                 if str(i) == 'nan':
                     i = 'None'
                 goodscolor.objects.create(openid=self.request.auth.openid,
                                           goods_color=str(i).strip(),
                                           creater=self.request.auth.name
                                           )
             goods_shape_list = df.drop_duplicates(subset=[data_header.get('goods_shape')], keep='first').loc[:,
                                 data_header.get('goods_shape')].values
             for i in goods_shape_list:
                 if str(i) == 'nan':
                     i = 'None'
                 goodsshape.objects.create(openid=self.request.auth.openid,
                                           goods_shape=str(i).strip(),
                                           creater=self.request.auth.name
                                           )
             goods_specs_list = df.drop_duplicates(subset=[data_header.get('goods_specs')], keep='first').loc[:,
                                 data_header.get('goods_specs')].values
             for i in goods_specs_list:
                 if str(i) == 'nan':
                     i = 'None'
                 goodsspecs.objects.create(openid=self.request.auth.openid,
                                           goods_specs=str(i).strip(),
                                           creater=self.request.auth.name
                                           )
             goods_origin_list = df.drop_duplicates(subset=[data_header.get('goods_origin')], keep='first').loc[:,
                                 data_header.get('goods_origin')].values
             for i in goods_origin_list:
                 if str(i) == 'nan':
                     i = 'None'
                 goodsorigin.objects.create(openid=self.request.auth.openid,
                                            goods_origin=str(i).strip(),
                                            creater=self.request.auth.name
                                            )
         else:
             raise APIException({"detail": "Can Not Support This File Type"})
     else:
         raise APIException({"detail": "Please Select One File"})
     return Response({"detail": "Success"})