adds upload-duplicate_strategy config in interface and backend
This commit is contained in:
parent
7dd7935fed
commit
bb2ecd842d
@ -22,6 +22,7 @@ from flask import (
|
|||||||
from ..db import db
|
from ..db import db
|
||||||
from ..models import PaperMetadata, ActivityLog
|
from ..models import PaperMetadata, ActivityLog
|
||||||
from ..celery import celery # Import the celery instance directly
|
from ..celery import celery # Import the celery instance directly
|
||||||
|
from ..defaults import DUPLICATE_STRATEGIES
|
||||||
|
|
||||||
bp = Blueprint("upload", __name__)
|
bp = Blueprint("upload", __name__)
|
||||||
|
|
||||||
@ -55,10 +56,10 @@ def upload():
|
|||||||
|
|
||||||
return jsonify({"task_id": task.id})
|
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)
|
@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."""
|
"""Process CSV file and import paper metadata."""
|
||||||
|
|
||||||
# With the ContextTask in place, we're already inside an app context
|
# With the ContextTask in place, we're already inside an app context
|
||||||
|
@ -1 +1,22 @@
|
|||||||
DEBUG = False # make sure DEBUG is off unless enabled explicitly otherwise
|
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
|
||||||
|
# }
|
||||||
|
}
|
||||||
|
@ -58,6 +58,16 @@
|
|||||||
<option value="|">Pipe (|)</option>
|
<option value="|">Pipe (|)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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>
|
<button type="submit" class="btn btn-primary mt-3">Upload</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user