Esempio n. 1
0
def export():
  year,month,fmt = utils.parseExportParamFromQuery(request.query.decode())
  try:
    iyear = int(year)
    imonth = int(month)
    result = arrange('./upload-'+year+'-'+month, iyear, imonth)
  except IllegalMonthError:
    abort(404,"Request file is not found.")
  except IOError as e:
    if e.errno is not 2:
      abort(404,"IOError {0}:{1}".format(e.errno, e.strerror))
    else:
      abort(404,"Request file is not found.")
  except:
    abort(500,"Internal error.")
  else:
    buf = exportSchedule(result, iyear, imonth, fmt)
    if buf == None:
      print 'exportSchedule return result None.'
      abort(500, "Internal error.")

    print '[INFO] export schedule of ', year, '-',month, ' in ', fmt , ' format.'
    #print buf
    if fmt == 'csv':
      response.headers['Content-Type'] = 'text/csv; charset=UTF-8'
      response.headers['Content-Disposition'] = 'attachment; filename="schedule' + year + '' + month + '.csv"'
    elif fmt == 'excel':
      response.headers['Content-Type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8'
      response.headers['Content-Disposition'] = 'attachment; filename="schedule' + year + '' + month + '.xlsx"' 
    return buf
Esempio n. 2
0
def export():
    year, month, fmt = utils.parseExportParamFromQuery(request.query.decode())
    try:
        iyear = int(year)
        imonth = int(month)
        result = arrange('./upload-' + year + '-' + month, iyear, imonth)
    except IllegalMonthError:
        abort(404, "Request file is not found.")
    except IOError as e:
        if e.errno is not 2:
            abort(404, "IOError {0}:{1}".format(e.errno, e.strerror))
        else:
            abort(404, "Request file is not found.")
    except:
        abort(500, "Internal error.")
    else:
        buf = exportSchedule(result, iyear, imonth, fmt)
        if buf == None:
            print 'exportSchedule return result None.'
            abort(500, "Internal error.")

        print '[INFO] export schedule of ', year, '-', month, ' in ', fmt, ' format.'
        #print buf
        if fmt == 'csv':
            response.headers['Content-Type'] = 'text/csv; charset=UTF-8'
            response.headers[
                'Content-Disposition'] = 'attachment; filename="schedule' + year + '' + month + '.csv"'
        elif fmt == 'excel':
            response.headers[
                'Content-Type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8'
            response.headers[
                'Content-Disposition'] = 'attachment; filename="schedule' + year + '' + month + '.xlsx"'
        return buf
Esempio n. 3
0
def tbl_layout(year, month):
  try:
    result = arrange('./upload-'+year+'-'+month, int(year), int(month))
    return template('tpl/mentholatum-tbl', result_json = json.dumps(result["人班表"]), m_year = year, m_month = month)
  except IllegalMonthError:
    abort(404,"Request month is not found.")
  except IOError as e:
    if e.errno is not 2:
      abort(404, "IOError {0}:{1}".format(e.errno, e.strerror))
    return template('tpl/mentholatum-tbl', result_json = json.dumps(dict()), m_year = year, m_month = month)
  except :
    abort(500,"Sorry for internel error.\n error:" + sys.exc_info()[0].__name__)
Esempio n. 4
0
def tbl_layout(year, month):
    try:
        result = arrange('./upload-' + year + '-' + month, int(year),
                         int(month))
        return template('tpl/mentholatum-tbl',
                        result_json=json.dumps(result["人班表"]),
                        m_year=year,
                        m_month=month)
    except IllegalMonthError:
        abort(404, "Request month is not found.")
    except IOError as e:
        if e.errno is not 2:
            abort(404, "IOError {0}:{1}".format(e.errno, e.strerror))
        return template('tpl/mentholatum-tbl',
                        result_json=json.dumps(dict()),
                        m_year=year,
                        m_month=month)
    except:
        abort(
            500,
            "Sorry for internel error.\n error:" + sys.exc_info()[0].__name__)