adds upload-duplicate_strategy config in interface and backend

This commit is contained in:
Michael Beck 2025-04-16 14:06:25 +02:00
parent 7dd7935fed
commit bb2ecd842d
3 changed files with 34 additions and 2 deletions

View File

@ -22,6 +22,7 @@ from flask import (
from ..db import db
from ..models import PaperMetadata, ActivityLog
from ..celery import celery # Import the celery instance directly
from ..defaults import DUPLICATE_STRATEGIES
bp = Blueprint("upload", __name__)
@ -55,10 +56,10 @@ def upload():
return jsonify({"task_id": task.id})
return render_template("upload.html.jinja")
return render_template("upload.html.jinja", duplicate_strategies=DUPLICATE_STRATEGIES)
@celery.task(bind=True)
def process_csv(self, file_content, delimiter, duplicate_strategy):
def process_csv(self, file_content, delimiter, duplicate_strategy="skip"):
"""Process CSV file and import paper metadata."""
# With the ContextTask in place, we're already inside an app context

View File

@ -1 +1,22 @@
DEBUG = False # make sure DEBUG is off unless enabled explicitly otherwise
# Define duplicate handling strategies with descriptions for the UI
DUPLICATE_STRATEGIES = {
"skip": {
"name": "Skip duplicates",
"description": "Skip papers that already exist in the database",
"is_default": True
},
"update": {
"name": "Update duplicates",
"description": "Update existing papers with new metadata",
"is_default": False
},
# Add new strategies here, they will automatically appear in the UI
# Example:
# "merge": {
# "name": "Merge duplicates",
# "description": "Merge new data with existing data, keeping both values",
# "is_default": False
# }
}

View File

@ -58,6 +58,16 @@
<option value="|">Pipe (|)</option>
</select>
</div>
<div class="form-group mt-3">
<label for="duplicate_strategy">Duplicate Handling Strategy</label>
<select name="duplicate_strategy" id="duplicate_strategy" class="form-control">
{% for strategy_id, strategy in duplicate_strategies.items() %}
<option value="{{ strategy_id }}" {% if strategy.is_default %}selected{% endif %}>
{{ strategy.name }} - {{ strategy.description }}
</option>
{% endfor %}
</select>
</div>
<button type="submit" class="btn btn-primary mt-3">Upload</button>
</form>