Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion biosimdb_interface/form/webform.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ def do_submit():
# keep pending_form_data and pending_files_dir for retry
return redirect(url_for("form.webform"))

# success: now clear pending state
# success: now clear pending state etc.
session.pop("pending_files_dir", None)
session.pop("access_token", None)
session.pop("user_email", None)
session.pop("post_login_redirect", None)

BASE_URL = current_app.config["BASE_URL"]
record_url = f"{BASE_URL}/uploads/{draft_id}"
Expand Down
20 changes: 16 additions & 4 deletions biosimdb_interface/templates/form/submit_success.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,43 @@
record_url (str): URL of the newly created BioSimDB record.

Behaviour:
- Clears client-side form cache so a new submission starts clean.
- Counts down 10 seconds then redirects to record_url in the same tab.
- "View Record" button opens record_url immediately and cancels the countdown.
- "Return to Webform" button returns to an empty form.
#}
{% extends "main/base.html" %}
{% block content %}
<div class="container text-center mt-5">
<p class="text-success fw-semibold">BioSimDB record created successfully! Please complete your submission there.</p>
<p class="text-muted">Redirecting to your record in <span id="countdown">10</span> seconds...</p>
<a href="{{ record_url }}" target="_blank" class="btn btn-success me-2" onclick="clearInterval(interval); document.getElementById('countdown').closest('p').style.display='none'">View Record</a>
<!-- <a href="{{ url_for('form.webform') }}" class="btn btn-outline-secondary">Submit Another</a> -->
<div class="d-inline-flex gap-2">
<a href="{{ record_url }}" target="_blank" rel="noopener" class="btn btn-success" onclick="clearInterval(interval); document.getElementById('countdown').closest('p').style.display='none'">View Record</a>
<a href="{{ url_for('form.webform') }}" target="_blank" rel="noopener" class="btn btn-outline-secondary" onclick="clearInterval(interval); document.getElementById('countdown').closest('p').style.display='none'">Return to Webform</a>
</div>
</div>
{% endblock %}

{% block scripts %}
{{ super() }}
<script>
document.addEventListener('DOMContentLoaded', () => {
sessionStorage.removeItem('formState');
sessionStorage.removeItem('extractedMetadata');
});

let seconds = 10;
const countdown = document.getElementById('countdown');
const interval = setInterval(() => {
seconds--;
countdown.textContent = seconds;
if (seconds <= 0) {
clearInterval(interval);
window.location = '{{ record_url }}';
// window.open('{{ record_url }}', '_blank');
const win = window.open('{{ record_url }}', '_blank', 'noopener,noreferrer');
if (!win) {
// Fallback if popup was blocked
window.location = '{{ record_url }}';
}
}
}, 1000);
</script>
Expand Down
11 changes: 10 additions & 1 deletion tests/test_form/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ def test_do_submit_calls_invenio(client):
patch("biosimdb_interface.form.webform.prepare_for_invenio") as mock_prepare,
):
mock_prepare.return_value = "draft-123"
_response = client.post("/do_submit")
response = client.post("/do_submit")
assert response.status_code == 200
assert b"View Record" in response.data
assert b"Return to Webform" in response.data
assert mock_invite.called
assert mock_prepare.called

with client.session_transaction() as sess:
assert "pending_files_dir" not in sess
assert "access_token" not in sess
assert "user_email" not in sess
assert "post_login_redirect" not in sess
Loading