From f435aedf2b2454a33be72ea4ebe1b9dd88397821 Mon Sep 17 00:00:00 2001 From: Tanishq Dubey Date: Sun, 20 Oct 2024 16:22:45 -0400 Subject: [PATCH] More admin change --- app.py | 71 ++++++++++++++++++++++++- config.py | 6 ++- templates/admin.html | 121 ++++++++++++++++++++++++++++++++++++++++--- templates/index.html | 23 ++++---- 4 files changed, 203 insertions(+), 18 deletions(-) diff --git a/app.py b/app.py index 50b7279..5bf10f0 100644 --- a/app.py +++ b/app.py @@ -205,5 +205,74 @@ def admin_logout(): def serve_thumbnail(filename): return send_from_directory(THUMBNAIL_FOLDER, filename) +@app.route('/admin/update_photo/', methods=['POST']) +def update_photo(photo_id): + if 'logged_in' not in session: + return jsonify({'success': False, 'error': 'Not logged in'}), 401 + + data = request.json + db_session = DBSession() + photo = db_session.query(Photo).get(photo_id) + + if not photo: + db_session.close() + return jsonify({'success': False, 'error': 'Photo not found'}), 404 + + try: + for field, value in data.items(): + if field == 'date_taken': + value = datetime.strptime(value, '%Y-%m-%d %H:%M:%S') + elif field == 'iso': + value = int(value) + setattr(photo, field, value) + + db_session.commit() + db_session.close() + return jsonify({'success': True}) + except Exception as e: + db_session.rollback() + db_session.close() + return jsonify({'success': False, 'error': str(e)}), 500 + +@app.route('/admin/delete_photo/', methods=['POST']) +def delete_photo(photo_id): + if 'logged_in' not in session: + return jsonify({'success': False, 'error': 'Not logged in'}), 401 + + db_session = DBSession() + photo = db_session.query(Photo).get(photo_id) + + if not photo: + db_session.close() + return jsonify({'success': False, 'error': 'Photo not found'}), 404 + + try: + # Delete the original file + original_path = os.path.join(UPLOAD_FOLDER, photo.input_filename) + if os.path.exists(original_path): + os.remove(original_path) + + # Delete the thumbnail directory + thumb_dir = os.path.join(THUMBNAIL_FOLDER, os.path.splitext(photo.input_filename)[0]) + if os.path.exists(thumb_dir): + for thumb_file in os.listdir(thumb_dir): + os.remove(os.path.join(thumb_dir, thumb_file)) + os.rmdir(thumb_dir) + + # Delete the database entry + db_session.delete(photo) + db_session.commit() + db_session.close() + + return jsonify({'success': True}) + except Exception as e: + db_session.rollback() + db_session.close() + return jsonify({'success': False, 'error': str(e)}), 500 + if __name__ == '__main__': - app.run(debug=True, port=5002, host='0.0.0.0') + app.run( + debug=True, + port=config['server']['port'], + host=config['server']['host'] + ) diff --git a/config.py b/config.py index 0c5b9a7..e31241b 100644 --- a/config.py +++ b/config.py @@ -16,7 +16,11 @@ def load_or_create_config(): 'thumbnail': 'thumbnails' }, 'appearance': { - 'accent_color': '{{ accent_color }}' + 'accent_color': '#ff6600' + }, + 'server': { + 'host': '0.0.0.0', + 'port': 5002 } } with open(CONFIG_FILE, 'w') as f: diff --git a/templates/admin.html b/templates/admin.html index f54bde2..3136451 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -90,6 +90,31 @@ .logout a:hover { text-decoration: underline; } + .editable { + cursor: pointer; + } + .editable:hover { + background-color: #f0f0f0; + } + .editing { + background-color: #fff; + border: 1px solid #ccc; + padding: 2px; + } + .delete-btn { + background-color: #ff4136; + color: white; + border: none; + padding: 0.25rem 0.5rem; + border-radius: 4px; + cursor: pointer; + font-family: inherit; + font-weight: bold; + margin-left: 0.5rem; + } + .delete-btn:hover { + background-color: #ff1a1a; + } @@ -126,23 +151,105 @@ Shutter Speed ISO Dimensions + Actions {% for photo in photos %} - + Thumbnail - {{ photo.input_filename }} - {{ photo.date_taken.strftime('%Y-%m-%d %H:%M:%S') }} - {{ photo.focal_length }} - {{ photo.aperture }} - {{ photo.shutter_speed }} - {{ photo.iso }} + {{ photo.input_filename }} + {{ photo.date_taken.strftime('%Y-%m-%d %H:%M:%S') }} + {{ photo.focal_length }} + {{ photo.aperture }} + {{ photo.shutter_speed }} + {{ photo.iso }} {{ photo.width }}x{{ photo.height }} + + + + {% endfor %} + diff --git a/templates/index.html b/templates/index.html index fda2ef6..f73b7a4 100644 --- a/templates/index.html +++ b/templates/index.html @@ -126,15 +126,8 @@ @media (max-width: 768px) { - body { - flex-direction: column; - } - .sidebar { - width: 100%; - height: auto; - position: static; - padding: 10px; - } + + .main-content { padding: 10px; } @@ -149,6 +142,18 @@ height: auto; } } + + @media (max-width: 1024px) { + body { + flex-direction: column; + } + .sidebar { + width: 100%; + height: auto; + position: static; + padding: 10px; + } + }