Skip to content

Commit

Permalink
Fix download bug
Browse files Browse the repository at this point in the history
  • Loading branch information
severinsimmler committed Apr 26, 2018
1 parent 294589d commit 07701cb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
7 changes: 5 additions & 2 deletions application/gui.py
Expand Up @@ -29,10 +29,13 @@ def home(self):
self.load(PyQt5.QtCore.QUrl(self.root_url))

def acceptNavigationRequest(self, url, kind, is_main_frame):
"""Open external links in browser and internal links in the webview"""
"""
Open external links in browser and internal links in the webview.
"""
ready_url = url.toEncoded().data().decode()
is_clicked = kind == self.NavigationTypeLinkClicked
if is_clicked and self.root_url not in ready_url:

if is_clicked and (self.root_url not in ready_url or 'download' in ready_url):
PyQt5.QtGui.QDesktopServices.openUrl(url)
return False
return super(WebPage, self).acceptNavigationRequest(url, kind, is_main_frame)
Expand Down
32 changes: 16 additions & 16 deletions application/templates/layout.html
Expand Up @@ -8,26 +8,26 @@
<meta name="author" content="DARIAH-DE">
<meta name="description" content="Topics Explorer">

<link rel="stylesheet" href="{{url_for('static', filename='css/bootstrap.css')}}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{url_for('static', filename='css/bootstrap-responsive.css')}}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{url_for('static', filename='css/application.css')}}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{url_for('static', filename='css/bootstrap-customization.css')}}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{url_for('static', filename='css/bootstrap-modal.css')}}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{url_for('static', filename='css/font-awesome.css')}}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.css') }}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-responsive.css') }}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/application.css') }}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-customization.css') }}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-modal.css') }}" type="text/css" media="screen, projection"/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/font-awesome.css') }}">

<script type="text/javascript" src="{{url_for('static', filename='js/jquery-1.8.2.js')}}"></script>
<script type="text/javascript" src="{{url_for('static', filename='js/bootstrap.js')}}"></script>
<script type="text/javascript" src="{{url_for('static', filename='js/globalmenu.js')}}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery-1.8.2.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/bootstrap.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/globalmenu.js') }}"></script>

{% if bokeh_resources|safe == "include" %}
<link rel="stylesheet" href="{{url_for('static', filename='css/bokeh-min.css')}}">
<link rel="stylesheet" href="{{url_for('static', filename='css/bokeh-tables-min.css')}}">
<link rel="stylesheet" href="{{url_for('static', filename='css/bokeh-widgets-min.css')}}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bokeh-min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bokeh-tables-min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bokeh-widgets-min.css') }}">

<script type="text/javascript" src="{{url_for('static', filename='js/bokeh.min.js')}}"></script>
<script type="text/javascript" src="{{url_for('static', filename='js/bokeh-gl.min.js')}}"></script>
<script type="text/javascript" src="{{url_for('static', filename='js/bokeh-tables.min.js')}}"></script>
<script type="text/javascript" src="{{url_for('static', filename='js/bokeh-widgets.min.js')}}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/bokeh.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/bokeh-gl.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/bokeh-tables.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/bokeh-widgets.min.js') }}"></script>

{% block bokeh_scripts%}
{% endblock %}
Expand Down
2 changes: 1 addition & 1 deletion application/templates/model.html
Expand Up @@ -9,7 +9,7 @@
<a href="{{ url_for('help') }}"> <i class="icon-question-sign icon-white"></i> Help</a>
</li>
<li>
<a href="http://127.0.0.1:5000/model/download"> <i class="icon-download icon-white"></i> Save Graphics and Tables</a>
<a href="{{url_for('static', filename='topicmodeling.zip')}}"> <i class="icon-download icon-white"></i> Save Graphics and Tables</a>
</li>
</ul>
{% endblock %}
Expand Down
26 changes: 9 additions & 17 deletions application/web.py
Expand Up @@ -18,15 +18,19 @@ def index():
global ARCHIVEDIR

TEMPDIR = tempfile.mkdtemp() # Dumping the logfile, temporary data, etc.
ARCHIVEDIR = tempfile.mkdtemp() # Dumping the ZIP archive

def unlink_content(directory):
for p in pathlib.Path(directory).rglob('*'):
ARCHIVEDIR = app.static_folder # Dumping the ZIP archive

def unlink_content(directory, only_zip=False):
if only_zip:
pattern = '*.zip'
else:
pattern = '*'
for p in pathlib.Path(directory).rglob(pattern):
if p.is_file():
p.unlink()

unlink_content(TEMPDIR)
unlink_content(ARCHIVEDIR)
unlink_content(ARCHIVEDIR, only_zip=True)

if application.utils.is_connected():
return flask.render_template('index.html')
Expand Down Expand Up @@ -67,18 +71,6 @@ def model():
return flask.render_template('model.html', **data)


@app.route('/model/download')
def download_model_output():
"""
Sends the generated data as ZIP archive to the user.
"""
zip_archive = str(pathlib.Path(ARCHIVEDIR, 'topicmodeling.zip'))
return flask.send_file(filename_or_fp=zip_archive,
mimetype='application/zip',
attachment_filename='topicmodeling.zip',
as_attachment=True)


@app.errorhandler(werkzeug.exceptions.HTTPException)
def handle_http_exception(e):
"""
Expand Down

0 comments on commit 07701cb

Please sign in to comment.