def get_all_status(): args = args_parser.parse_all() activity_payments = pay_base.get_all_activity_stats(args) # set restaurant name restaurants = rst_base.mget( [pay.get('restaurant_id') for pay in activity_payments]) for index, payments in enumerate(activity_payments): payments['restaurant_name'] = restaurants[index].name if not restaurants[index].is_valid: payments['restaurant_name'] += u'(餐厅已无效)' activity_payments = pay_base.set_activity_names(activity_payments) activity_payments = pay_base.set_bank_card_exist_or_not(activity_payments) visible_city_ids = city_base.get_city_id_name_pairs_by_user() no_subsidy_indication, pay_fail_indication = pay_base.\ get_failed_status_indication(args) return { 'payments': activity_payments, 'city_ids': visible_city_ids, 'no_subsidy_indication': no_subsidy_indication, 'pay_fail_indication': pay_fail_indication, 'total_num': 0 }
def export_excel(): args = args_parser.parse_all() activity_payments = pay_base.get_all_activity_stats(args) # set restaurant name restaurants = rst_base.mget( [pay.get('restaurant_id') for pay in activity_payments]) for index, payments in enumerate(activity_payments): payments['restaurant_name'] = restaurants[index].name activity_payments = pay_base.set_activity_names(activity_payments) activity_payments = pay_base.set_act_category_names(activity_payments) temp_file = tempfile.TemporaryFile() workbook = generate_excel(activity_payments, u'活动打款审核记录', ( ('restaurant_id', u'餐厅id'), ('restaurant_name', u'餐厅名称'), ('activity_name', u'活动名称'), ('activity_id', u'活动id'), ('first_date', u'起始日期'), ('last_date', u'结束日期'), ('activity_category_id', u'活动类别'), ('total_subsidy', u'打款总额'), ('quantity', u'数量'), )) workbook.save(temp_file) temp_file.seek(0) response = send_file(temp_file, as_attachment=True, mimetype='application/vnd.ms-excel', attachment_filename='活动打款审核记录.xls', add_etags=False) temp_file.seek(0, os.SEEK_END) size = temp_file.tell() temp_file.seek(0) response.headers.extend({ 'Content-Length': size, 'Cache-Control': 'no-cache' }) return response