-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Download All submissions (based on #1181) #1456
Changes from 8 commits
982c03c
ca1e5bc
3fb8597
405d1d8
4619c69
5056410
e0d7242
1337fbb
5c1e5c5
d56277d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -578,23 +578,37 @@ def download_unread(sid): | |
return bulk_download(sid, docs) | ||
|
||
|
||
@app.route('/download_all_unread') | ||
@login_required | ||
def download_all_unread(): | ||
docs = Submission.query.filter(Submission.downloaded == False).all() | ||
if docs == []: | ||
flash("No unread documents in collections!", "error") | ||
return redirect(url_for('index')) | ||
return bulk_dl('all_unread_' + g.user.username, docs) | ||
|
||
|
||
@app.route('/bulk', methods=('POST',)) | ||
@login_required | ||
def bulk(): | ||
action = request.form['action'] | ||
|
||
doc_names_selected = request.form.getlist('doc_names_selected') | ||
selected_docs = [doc for doc in g.source.collection | ||
if doc.filename in doc_names_selected] | ||
|
||
if action == 'download_all': | ||
selected_docs = g.source.collection | ||
else: | ||
selected_docs = [doc for doc in g.source.collection | ||
if doc.filename in doc_names_selected] | ||
if selected_docs == []: | ||
if action == 'download': | ||
flash("No collections selected to download!", "error") | ||
elif action == 'download_all': | ||
flash("No collections available to download!", "error") | ||
elif action == 'delete' or action == 'confirm_delete': | ||
flash("No collections selected to delete!", "error") | ||
return redirect(url_for('col', sid=g.sid)) | ||
|
||
if action == 'download': | ||
if action in ('download', 'download_all'): | ||
return bulk_download(g.sid, selected_docs) | ||
elif action == 'delete': | ||
return bulk_delete(g.sid, selected_docs) | ||
|
@@ -627,20 +641,22 @@ def bulk_delete(sid, items_selected): | |
|
||
def bulk_download(sid, items_selected): | ||
source = get_source(sid) | ||
filenames = [store.path(sid, item.filename) for item in items_selected] | ||
return bulk_dl(source.journalist_filename, items_selected) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: can you add another newline here, just to keep the double-newline between functions style consistent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
def bulk_dl(zip_directory, items_selected): | ||
filenames = [store.path(item.source.filesystem_id, item.filename) | ||
for item in items_selected] | ||
|
||
# Mark the submissions that are about to be downloaded as such | ||
for item in items_selected: | ||
if isinstance(item, Submission): | ||
item.downloaded = True | ||
db_session.commit() | ||
|
||
zf = store.get_bulk_archive( | ||
filenames, | ||
zip_directory=source.journalist_filename) | ||
zf = store.get_bulk_archive(filenames, | ||
zip_directory=zip_directory) | ||
attachment_filename = "{}--{}.zip".format( | ||
source.journalist_filename, | ||
datetime.utcnow().strftime("%Y-%m-%d--%H-%M-%S")) | ||
zip_directory, datetime.utcnow().strftime("%Y-%m-%d--%H-%M-%S")) | ||
return send_file(zf.name, mimetype="application/zip", | ||
attachment_filename=attachment_filename, | ||
as_attachment=True) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,12 @@ | |
{% if source.collection %} | ||
<p>The documents are stored encrypted for security. To read them, you will need to decrypt them using GPG.</p> | ||
<form action="/bulk" method="post"> | ||
<div class="document-actions"> | ||
<div id='select-container'></div> | ||
<button type="submit" name="action" value="download"><i class="fa fa-download"></i> Download selected</button> | ||
<button type="submit" name="action" value="confirm_delete" class="danger" id="delete_selected"><i class="fa fa-times"></i> Delete selected</button> | ||
</div> | ||
<div class="document-actions"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you redo the indent for this block? |
||
<div id='select-container'></div> | ||
<button type="submit" name="action" value="download_all"><i class="fa fa-download"></i> Download all</button> | ||
<button type="submit" name="action" value="download"><i class="fa fa-download"></i> Download selected</button> | ||
<button type="submit" name="action" value="confirm_delete" class="danger" id="delete_selected"><i class="fa fa-times"></i> Delete selected</button> | ||
</div> | ||
<ul id="submissions" class="plain submissions"> | ||
{% for doc in source.collection %} | ||
<li class="submission"><input type="checkbox" name="doc_names_selected" value="{{ doc.filename }}" class="doc-check"/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one thing about this naming scheme is that for multi-journalist user SD instances, if one journalist downloads a message, it's marked read for all journalists. So I'd just leave the first positional argument as
all_unread
.