get flagging/rejecting working
- ID
462c2db- date
2023-05-13 12:09:47+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
9786983- message
get flagging/rejecting working- changed files
2 files, 26 additions, 35 deletions
Changed files
server.py (5465) → server.py (5591)
diff --git a/server.py b/server.py
index 9889919..09a2f70 100755
--- a/server.py
+++ b/server.py
@@ -156,31 +156,34 @@ def get_image_path(local_identifier):
return subprocess.check_output(['swift', 'get_asset_jpeg.swift', local_identifier, '2048']).decode('utf8')
-@app.route('/actions/flag')
-def flag():
+def _perform_action(request, callback):
local_identifier = request.args['localIdentifier']
- photos_data.flag(local_identifier)
+ position = photos_data.all_positions[local_identifier]
- return redirect(url_for('index', localIdentifier=local_identifier))
+ callback(local_identifier)
+ if request.args['direction'] == 'left':
+ redirect_to = photos_data.all_assets[position - 1]['localIdentifier']
+ else:
+ redirect_to = photos_data.all_assets[position + 1]['localIdentifier']
-@app.route('/actions/reject')
-def reject():
- local_identifier = request.args['localIdentifier']
+ return redirect(url_for('index', localIdentifier=redirect_to))
- photos_data.reject(local_identifier)
- return redirect(url_for('index', localIdentifier=local_identifier))
+@app.route('/actions/flag')
+def flag():
+ return _perform_action(request, photos_data.flag)
-@app.route('/actions/needs_action')
-def needs_action():
- local_identifier = request.args['localIdentifier']
+@app.route('/actions/reject')
+def reject():
+ return _perform_action(request, photos_data.reject)
- photos_data.needs_action(local_identifier)
- return redirect(url_for('index', localIdentifier=local_identifier))
+@app.route('/actions/needs_action')
+def needs_action():
+ return _perform_action(request, photos_data.needs_action)
templates/index.html (8334) → templates/index.html (8259)
diff --git a/templates/index.html b/templates/index.html
index 2329665..e7987d6 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -182,9 +182,8 @@
</div>
<p class="metadata">
- {{ this_asset['localIdentifier'] }} /
- {% if this_asset['albums'] %}
- <strong>albums:</strong> {{ this_asset['albums'] | join(', ') }} /
+ {% if this_asset['display_albums'] %}
+ <strong>albums:</strong> {{ this_asset['display_albums'] | join(', ') }} /
{% endif %}
<strong>creation date:</strong> {{ this_asset['creationDate'] }}
</p>
@@ -197,32 +196,21 @@
{% endfor %} -->
<script>
-function httpPOST(url)
-{
- var xmlHttp = null;
-
- xmlHttp = new XMLHttpRequest();
- xmlHttp.open("POST", url, false);
- xmlHttp.send(null);
- return xmlHttp.responseText;
-}
-
document.onkeydown = function(e) {
- console.log(e);
- console.log(e.key);
- console.log(e.key === "2");
+ const direction = new URLSearchParams(window.location.search).get('direction') || 'left';
+
if (e.key === "ArrowLeft") {
- window.location = "/?localIdentifier={{ prev_five[-1]['localIdentifier'] }}";
+ window.location = "/?localIdentifier={{ prev_five[-1]['localIdentifier'] }}&direction=left";
} else if (e.key === "ArrowRight") {
{% if next_five %}
- window.location = "/?localIdentifier={{ next_five[0]['localIdentifier'] }}";
+ window.location = "/?localIdentifier={{ next_five[0]['localIdentifier'] }}&direction=right";
{% endif %}
} else if (e.key === "1") {
- window.location = "/actions/flag?localIdentifier={{ this_asset['localIdentifier'] }}";
+ window.location = "/actions/flag?localIdentifier={{ this_asset['localIdentifier'] }}&direction=" + direction;
} else if (e.key === "2") {
- window.location = "/actions/reject?localIdentifier={{ this_asset['localIdentifier'] }}";
+ window.location = "/actions/reject?localIdentifier={{ this_asset['localIdentifier'] }}&direction=" + direction;
} else if (e.key === "3") {
- window.location = "/actions/needs_action?localIdentifier={{ this_asset['localIdentifier'] }}";
+ window.location = "/actions/needs_action?localIdentifier={{ this_asset['localIdentifier'] }}&direction=" + direction;
}
}
</script>