Beispiel #1
0
def query():
    # 设置数据
    period = range(1978, 2014)
    db = ProvinceStatisticsDatabase()
    if request.method == 'POST':
        form_data = request.form
        print(form_data)
        period_chosen = form_data.getlist('period')
        region_chosen = re.split(',', form_data.getlist('hregion')[0])
        variables_chosen = form_data.getlist('variable')
        print(period_chosen)
        print(region_chosen)
        print(variables_chosen)
        conds = {'region': region_chosen, 'year': period_chosen, 'variable': variables_chosen}
        mdata = db.find(conds)
        header = mdata['header']
        data = mdata['data']
        print(mdata)
        fdata = [header]
        fdata.extend(data)
        print(fdata)
        filename = str(uuid.uuid1()) + '.xlsx'
        session['filename'] = filename
        outfile = ''.join([TEMP_FILE_FOLDER, filename])
        print(url_for('myapp.index'))
        moutexcel = Excel(outfile)
        moutexcel.new().append(fdata, 'mysheet')
        moutexcel.close()
        return render_template("queryresult.html", header=header, data=data)
    return render_template("query.html", period=period)
Beispiel #2
0
def ajaxtwo():
    db = AQIDatabase()

    if request.method == 'POST':
        form_data = request.form
        cities = form_data.getlist('city')
        start_date = form_data.get('startpick')
        end_date = form_data.get('endpick')
        conds = {'region': cities, 'sdate': start_date, 'edate': end_date}
        mdata = db.find(conds)
        header = mdata['header']
        data = mdata['data']
        print(mdata)
        fdata = [header]
        fdata.extend(data)
        print(fdata)
        filename = str(uuid.uuid1()) + '.xlsx'
        session['filename'] = filename
        outfile = 'E:\\gitwork\\application\\webapp\\static\\file\\' + filename
        moutexcel = Excel(outfile)
        moutexcel.new().append(fdata, 'mysheet')
        moutexcel.close()
        return render_template("queryresult.html", header=header, data=data)
    return render_template('ajaxtwo.html', cities=db.city)