Skip to content

Commit

Permalink
Show form errors on DOI creation page
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Aug 28, 2023
1 parent af4f397 commit 3b59c7d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
49 changes: 31 additions & 18 deletions isic/core/templates/core/collection_create_doi.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,43 @@
{% block content %}
<div class="heading-1">Create a DOI for {{ collection.name }}<span class="ml-2 text-base font-semibold"><a href="{% url 'core/collection-detail' collection.pk %}">back to collection</a></span></div>

{% if warnings %}
<ul class="flex bg-yellow-100 border border-yellow-300 my-4 px-4 py-3 rounded-md text-yellow-900 text-sm">
{% for warning in warnings %}
<li>{{ warning }}</li>
{% endfor %}
</ul>
{% endif %}

{% if error %}
<div class="rounded-md bg-red-50 p-4 mb-4">
<div class="flex items-center">
<div class="flex-shrink-0">
<!-- Heroicon name: solid/information-circle -->
<svg class="h-5 w-5 text-red-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"
aria-hidden="true">
<path fill-rule="evenodd"
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z"
clip-rule="evenodd" />
</svg>
</div>
<div class="ml-3">
<div class="mt-2 text-sm text-red-700">
<p>{{ error }}</p>
</div>
</div>
</div>
</div>
{% else %}
<div class="mt-4">Below is a preview of what your DOI will look like:</div>
<div class="my-4 bg-gray-50 p-2 rounded-sm border-gray-200 border">
<div class="heading-3">{{ preview.titles.0.title }}</div>
<div>{{ preview.creators }}</div>
<div>{{ preview.creators }}</div>
<div class="font-semibold">Dataset published {{ preview.publicationYear }} via {{ preview.publisher }}</div>
<div><a href="#">https://doi.org/{{ preview.doi }}</a></div>
<div>Contributed by <span class="font-semibold">{{ preview.contributor }}</span></div>
</div>

<div class="text-center">
<form method="post">
{% csrf_token %}
{{ form }}
<button type="submit" class="btn btn-primary">
Create this DOI
</button>
</form>
</div>
<div class="text-center">
<form method="post">
{% csrf_token %}
{{ form }}
<button type="submit" class="btn btn-primary">
Create this DOI
</button>
</form>
</div>
{% endif %}
{% endblock %}
19 changes: 14 additions & 5 deletions isic/core/views/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
from isic.core.permissions import get_visible_objects, needs_object_permission
from isic.core.services import _image_metadata_csv_headers, image_metadata_csv_rows
from isic.core.services.collection import collection_create, collection_update
from isic.core.services.collection.doi import collection_build_doi_preview, collection_create_doi
from isic.core.services.collection.doi import (
collection_build_doi_preview,
collection_check_create_doi_allowed,
collection_create_doi,
)
from isic.ingest.models import Contributor
from isic.ingest.models.accession import Accession

Expand Down Expand Up @@ -126,16 +130,21 @@ def collection_download_metadata(request, pk):
@needs_object_permission("core.create_doi", (Collection, "pk", "pk"))
def collection_create_doi_(request, pk):
collection = get_object_or_404(Collection, pk=pk)
context = {"collection": collection}
context = {"collection": collection, "error": None}

if request.method == "POST":
try:
collection_create_doi(user=request.user, collection=collection)
return HttpResponseRedirect(reverse("core/collection-detail", args=[collection.pk]))
except ValidationError:
pass
except ValidationError as e:
context["error"] = e.message
else:
context["preview"] = collection_build_doi_preview(collection=collection)
try:
collection_check_create_doi_allowed(user=request.user, collection=collection)
except ValidationError as e:
context["error"] = e.message
else:
context["preview"] = collection_build_doi_preview(collection=collection)

return render(
request,
Expand Down

0 comments on commit 3b59c7d

Please sign in to comment.