Exemplo n.º 1
0
def get_file(filename):
    import songwei as sw
    import StringIO
    names = [s['name'] for s in sw.sqls]
    if filename not in names:
        return u'非法文件名.'
    idx = names.index(filename)
    sql = sw.sqls[idx]
    user = request.environ['user']
    channel_id = user.user_info['channel_id']
    charge_departs = user.user_info['charge_departs']
    args = {'channel_id': channel_id, 'charge_departs': charge_departs}
    rows = sw.get_datas(sql['sql'], args)
    xls = StringIO.StringIO()
    if not excel_write(xls, rows):
        return u'生成失败.'
    response = Response()
    response.status_code = 200
    response.data = xls.getvalue()
    response.headers.set('Content-Type', 'application/vnd.ms-excel')
    d = dt.now().strftime('%Y%m%d-%H%M%S')
    filename = u'%s-%s.xlsx' % (filename, d)
    response.headers.set('Content-Disposition',
                         'attachment',
                         filename=filename.encode('gbk'))
    return response
Exemplo n.º 2
0
def plan_export():
    import StringIO
    from libs.file_helper import excel_write
    args = request.args
    if request.method == 'POST':
        args = request.form
    user = request.environ['user']
    channel_id = user.user_info['channel_id']
    charge_departs = user.user_info['charge_departs']
    sales_dates = args.get('sales_dates')
    sales_dates = None if not sales_dates else sales_dates.encode().split(',')
    status_id = args.get('status_id')
    status_id = status_id if status_id else None
    sales_depart_id = args.get('sales_depart_id')
    sales_depart_id = sales_depart_id if sales_depart_id else None
    rows = plansvc.plan_export(channel_id=channel_id,
                               charge_departs=charge_departs,
                               sales_dates=sales_dates,
                               status_id=status_id,
                               sales_depart_id=sales_depart_id)
    xls = StringIO.StringIO()
    if not excel_write(xls, rows):
        return u'生成失败'
    response = Response()
    response.status_code = 200
    response.data = xls.getvalue()
    response.headers.set('Content-Type', 'application/vnd.ms-excel')
    d = dt.now().strftime('%Y%m%d-%H%M%S')
    filename = u'排产导出.xlsx'
    response.headers.set('Content-Disposition',
                         'attachment',
                         filename=filename.encode('gbk'))
    return response
Exemplo n.º 3
0
def write(sqls=sqls):
    for i, items in enumerate(sqls):
        sql = items['sql']
        name = items['name']
        rows = get_datas(sql)
        if not rows:
            logger.info(u' get data none. return. sql%s' % i)
            return 
        _d = dt.now() 

        _name = u'%s%s.xls' % (name,str(_d), )
        path = os.path.join(webapp, 'static', 'files')
        file_name = os.path.join(path, _name)
        if not excel_write(file_name, rows):
            logger.error(u' write to data to excel failed. sql%s' % i)
        else:
            logger.info(u' write excel success[%s].'%(_name,))
Exemplo n.º 4
0
def get_file():
    user = request.environ['user']
    channel_id = user.user_info['channel_id']
    charge_departs = user.user_info['charge_departs']
    rows, _ = possvc.get_pos_list(channel_id=channel_id,
                                  sales_depart_ids=charge_departs,
                                  deleted=0)
    xls = StringIO.StringIO()
    if not excel_write(xls, rows):
        return u'生成失败.'
    response = Response()
    response.status_code = 200
    response.data = xls.getvalue()
    response.headers.set('Content-Type', 'application/vnd.ms-excel')
    d = dt.now().strftime('%Y%m%d')
    response.headers.set('Content-Disposition',
                         'attachment',
                         filename='pos-%s.xls' % d)
    return response