def export(cls, request, *args, **kwargs): page_size = int(request.GET.get('limit')) offset = int(request.GET.get('offset')) filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') date = request.GET.get('date') file_type = request.GET.get('type') date = UDatetime.datetime_str_init(date).date() data, num = DataDAO.get_productopt( date=date, pagination=True, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, ) # Replace columns product_records = cls.get_products() product_records['name'] = \ product_records['short_product_name'] + ' {' + product_records['product_num'] + '}' product_map = dict(zip(product_records['product_id'], product_records['name'])) columns = ['center_id', 'center_name'] + product_records['product_id'].tolist() data = data.reindex(columns=columns) data.rename(columns=product_map, inplace=True) data['center_id'] = data['center_id'].astype(int) if file_type == 'json': response = json.dumps(data.to_dict(orient='records'), ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response['Content-Disposition'] = 'attachment; filename=export.json' elif file_type == 'csv': response = data.to_csv(index=False) response = HttpResponse(response, content_type='application/csv') response['Content-Disposition'] = 'attachment; filename=export.csv' elif file_type == 'xlsx': response = io() xlwriter = pd.ExcelWriter(response) data.to_excel(xlwriter, index=False) xlwriter.save() xlwriter.close() response.seek(0) response = HttpResponse(response.read(), content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response['Content-Disposition'] = 'attachment; filename=export.xlsx' else: response = json.dumps([], ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response['Content-Disposition'] = 'attachment; filename=export.json' return response
def export(request, *args, **kwargs): page_size = request.GET.get('limit') offset = request.GET.get('offset') filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') product = request.GET.get('product') as_of_date = request.GET.get('as_of_date') file_type = request.GET.get('type') as_of_date = UDatetime.datetime_str_init(as_of_date).date() pagination = True if page_size: page_size = int(page_size) if offset: offset = int(offset) if product == 'retail bowling': product_ids = ProductChoice.retail_bowling_ids_new_short elif product == 'retail shoe': product_ids = ProductChoice.retail_shoe_product_ids_new elif product == 'after party friday': product_ids = [ '2146481686', '2146532909', '2146507303', '2146481687' ] elif product: product_ids = [product] else: product_ids = ProductChoice.retail_bowling_ids_new_short data, num = DataDAO.get_centers(pagination=pagination, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, last_price=True, last_price_product_ids=product_ids, last_price_from_change=True, lastPriceSplit=True, columns=[ 'center_name', 'region', 'district', 'brand', 'time_zone', 'center_type' ], as_of_date=as_of_date) # data = data.where((pd.notnull(data)), "") data.columns = map(str.capitalize, data.columns) if file_type == 'json': response = json.dumps(data.to_dict(orient='records'), ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' elif file_type == 'csv': response = data.to_csv(index=False) response = HttpResponse(response, content_type='application/csv') response[ 'Content-Disposition'] = 'attachment; filename=export.csv' elif file_type == 'xlsx': response = io() xlwriter = pd.ExcelWriter(response) data.to_excel(xlwriter, index=False) xlwriter.save() xlwriter.close() response.seek(0) response = HttpResponse( response.read(), content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = 'attachment; filename=export.xlsx' # elif type == 'excel': # writer = pd.ExcelWriter('export.xlsx') # response = data.to_excel(writer) # writer.save() # response = HttpResponse(response, content_type='application/vnd.ms-excel') # response['Content-Disposition'] = 'attachment; filename=export.xlsx' else: response = json.dumps([], ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' return response
def export(request, *args, **kwargs): page_size = int(request.GET.get('limit')) offset = int(request.GET.get('offset')) filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') start = request.GET.get('start') end = request.GET.get('end') file_type = request.GET.get('type') product_list = request.GET.getlist('product[]') start = UDatetime.datetime_str_init(start).date() end = UDatetime.datetime_str_init(end, start, default_delta=DEFAULT_RANGE) if type(end) == datetime.datetime: end = end.date() # init product_list product_list_new = [] for product_ids in product_list: product_list_new += product_ids.split(',') data, num = GetEvent.get_event_price_table(start, end, product_list_new, pagination=True, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order) data = data.where((pd.notnull(data)), "") data.columns = map(str.capitalize, data.columns) if file_type == 'json': response = json.dumps(data.to_dict(orient='records'), ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=tableExport.json' elif file_type == 'csv': response = data.to_csv(index=False) response = HttpResponse(response, content_type='application/csv') response[ 'Content-Disposition'] = 'attachment; filename=tableExport.csv' elif file_type == 'xlsx': response = io() xlwriter = pd.ExcelWriter(response) data.to_excel(xlwriter, index=False) xlwriter.save() xlwriter.close() response.seek(0) response = HttpResponse( response.read(), content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = 'attachment; filename=tableExport.xlsx' # elif type == 'excel': # writer = pd.ExcelWriter('export.xlsx') # response = data.to_excel(writer) # writer.save() # response = HttpResponse(response, content_type='application/vnd.ms-excel') # response['Content-Disposition'] = 'attachment; filename=export.xlsx' else: response = json.dumps([], ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' return response
def export(request, *args, **kwargs): district = request.GET.getlist('district[]') region = request.GET.getlist('region[]') page_size = request.GET.get('limit') offset = request.GET.get('offset') filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') file_type = request.GET.get('type') pagination = True if page_size: page_size = int(page_size) if offset: offset = int(offset) columns = [ 'center_id', 'center_name', 'region', 'district', ] data, num = TestDAO.get_centers( region, district, columns, pagination=True, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, ) # data = data.where((pd.notnull(data)), "") #data.columns = map(str.capitalize, data.columns) if file_type == 'json': response = json.dumps(data.to_dict(orient='records'), ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response['Content-Disposition'] = 'attachment; filename=export.json' elif file_type == 'csv': response = data.to_csv(index=False) response = HttpResponse(response, content_type='application/csv') response['Content-Disposition'] = 'attachment; filename=export.csv' elif file_type == 'xlsx': response = io() xlwriter = pd.ExcelWriter(response) data.to_excel(xlwriter, index=False) xlwriter.save() xlwriter.close() response.seek(0) response = HttpResponse(response.read(), content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') response['Content-Disposition'] = 'attachment; filename=export.xlsx' else: response = json.dumps([], ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response['Content-Disposition'] = 'attachment; filename=export.json' return response
def export(request, *args, **kwargs): page_size = int(request.GET.get('limit')) offset = int(request.GET.get('offset')) filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') start = request.GET.get('start') end = request.GET.get('end') menu_id = request.GET.get('menu_id') file_type = request.GET.get('type') # Get all selection values category = request.GET.getlist('category') district = request.GET.getlist('district') region = request.GET.getlist('region') center_id = request.GET.getlist('center_id') # Find if all in the selections if category and 'all' in category: category = [] if district and 'all' in district: district = [] if region and 'all' in region: region = [] if center_id and 'all' in center_id: center_id = [] # Remove empty string category = [item for item in category if item] district = [item for item in district if item] region = [item for item in region if item] center_id = [item for item in center_id if item] start = UDatetime.datetime_str_init( start).date() if start else UDatetime.now_local().date() data, num = FoodDataDao.getFoodByCenter(menu_id, start, category, district, region, center_id, pagination=True, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, download=True) if file_type == 'json': response = json.dumps(data.to_dict(orient='records'), ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' elif file_type == 'csv': response = data.to_csv(index=False) response = HttpResponse(response, content_type='application/csv') response[ 'Content-Disposition'] = 'attachment; filename=export.csv' elif file_type == 'xlsx': response = io() xlwriter = pd.ExcelWriter(response) data.to_excel(xlwriter, index=False) xlwriter.save() xlwriter.close() response.seek(0) response = HttpResponse( response.read(), content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = 'attachment; filename=export.xlsx' else: response = json.dumps([], ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' return response
def export(cls, request, *args, **kwargs): page_size = int(request.GET.get('limit')) offset = int(request.GET.get('offset')) filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') date = request.GET.get('date') file_type = request.GET.get('type') date = UDatetime.datetime_str_init(date).date() # Get all selection values sale_region = request.GET.getlist('sale_region[]') territory = request.GET.getlist('territory[]') center_id = request.GET.getlist('center_id[]') center_name = request.GET.getlist('center_name[]') columns = request.GET.getlist('columns[]') # Find if all in the selections if sale_region and 'all' in sale_region: sale_region = [] if territory and 'all' in territory: territory = [] if center_id and 'all' in center_id: center_id = [] if center_name and 'all' in center_name: center_name = [] if columns and 'all' in columns: columns = [] # Remove empty string sale_region = [item for item in sale_region if item] territory = [item for item in territory if item] center_id = [item for item in center_id if item] center_name = [item for item in center_name if item] columns = [item for item in columns if item] data, num = EventDataDao.get_event_RMPS(sale_region, territory, center_id, center_name, columns, pagination=True, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order) # data, num = DataDAO.get_productopt( # date=date, # pagination=True, # page_size=page_size, # offset=offset, # filters=filters, # sort=sort, # order=order, # ) #Replace columns #event_records = cls.get_columns() RMPSObjs = RMPS.objects.filter() RMPSRecords = pd.DataFrame.from_records( RMPSObjs.values('center_id', 'attribute', 'value', 'unit', 'order')) RMPSRecords['attribute'] = \ RMPSRecords['attribute'] + ' {' + RMPSRecords['id'] + '}' #product_map = dict(zip(RMPSRecords['id'], RMPSRecords['attribute'])) #columns = ['center_id', 'center_name', 'sale_region', 'territory', 'arcade_type']\ # + RMPSRecords['id'].tolist() print(RMPSRecords['attribute']) #data = data.reindex(columns=columns) #data.rename(columns=product_map, inplace=True) #data['center_id'] = data['center_id'].astype(int) if file_type == 'json': response = json.dumps(data.to_dict(orient='records'), ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' elif file_type == 'csv': response = data.to_csv(index=False) response = HttpResponse(response, content_type='application/csv') response[ 'Content-Disposition'] = 'attachment; filename=export.csv' elif file_type == 'xlsx': response = io() xlwriter = pd.ExcelWriter(response) data.to_excel(xlwriter, index=False) xlwriter.save() xlwriter.close() response.seek(0) response = HttpResponse( response.read(), content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = 'attachment; filename=export.xlsx' else: response = json.dumps([], ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' return response
def export(request, *args, **kwargs): page_size = request.GET.get('limit') offset = request.GET.get('offset') filters = request.GET.get('filter') sort = request.GET.get('sort') order = request.GET.get('order') file_type = request.GET.get('type') pagination = True if page_size: page_size = int(page_size) if offset: offset = int(offset) columns = [ 'center_name', 'brand', 'region', 'district', 'status', 'sale_region', 'territory', 'rvp', 'time_zone', 'address', 'city', 'state', 'zipcode', 'bowling_tier', 'food_tier', 'alcohol_tier', 'food_menu', 'center_type' ] data, num = DataDAO.get_centers( pagination=pagination, page_size=page_size, offset=offset, filters=filters, sort=sort, order=order, last_price=True, last_price_product_ids=ProductChoice. retail_bowling_ids_new_short, last_price_from_change=True, lastPriceSplit=True, columns=columns, as_of_date=UDatetime.now_local().date()) # data = data.where((pd.notnull(data)), "") data.columns = map(str.capitalize, data.columns) if file_type == 'json': response = json.dumps(data.to_dict(orient='records'), ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' elif file_type == 'csv': response = data.to_csv(index=False) response = HttpResponse(response, content_type='application/csv') response[ 'Content-Disposition'] = 'attachment; filename=export.csv' elif file_type == 'xlsx': response = io() xlwriter = pd.ExcelWriter(response) data.to_excel(xlwriter, index=False) xlwriter.save() xlwriter.close() response.seek(0) response = HttpResponse( response.read(), content_type= 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) response[ 'Content-Disposition'] = 'attachment; filename=export.xlsx' else: response = json.dumps([], ensure_ascii=False) response = HttpResponse(response, content_type='application/json') response[ 'Content-Disposition'] = 'attachment; filename=export.json' return response