Skip to content

Commit

Permalink
Add dropdown for upload categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Haider8 committed Mar 2, 2019
1 parent 870e77d commit e3382df
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
Binary file not shown.
Binary file added data/uploads/GVA_sectors/281321.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 34 additions & 3 deletions index.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
import os
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output

from flask import render_template
from flask import Flask, request, redirect, url_for, render_template
from werkzeug.utils import secure_filename
from app import app, server
from apps import home, gva_sectors, agg_national_accounts, gva_time_series, agg_eco_activities, household
from apps.admin import requires_auth

UPLOAD_FOLDER = 'data/uploads'
ALLOWED_EXTENSIONS = set(['xlsx'])
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

server.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])

@server.route('/admin')
@server.route('/admin', methods=['GET', 'POST'])
@requires_auth
def admin():
return "Hello !"
if request.method == 'POST':
option = request.form.get('options')
UPLOAD_FOLDER = 'data/uploads/{}'.format(option)
server.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
#print(option)
# check if the post request has the file part
if 'file' not in request.files:
return 'No file part'
return redirect(request.url)
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
return 'No file selected'
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(server.config['UPLOAD_FOLDER'], filename))
# return redirect(url_for('uploaded_file',
# filename=filename))
return render_template('upload.html')

@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
Expand Down
17 changes: 17 additions & 0 deletions templates/upload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>

<br>
<select name="options">
<option value="" disabled="disabled" selected="selected">Please select a name</option>
<option value="Aggregate_economic_activities">Aggregate economic activities</option>
<option value="Aggregate_national_accounts">Aggregate national accounts</option>
<option value="GVA_sectors">GVA sectors</option>
<option value="GVA_time_series">GVA time series</option>
<option value="Household">Household</option>
</select>
</form>

0 comments on commit e3382df

Please sign in to comment.