Skip to content

Commit

Permalink
Merge pull request 2i2c-org#185 from 2i2c-org/submission-view
Browse files Browse the repository at this point in the history
Display metadata in the submission view page
  • Loading branch information
jnywong authored Nov 6, 2024
2 parents 75410ea + 15c2254 commit 1f7a7c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
41 changes: 24 additions & 17 deletions frx_challenges/web/templates/submission/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,29 @@
<div class="row py-2">
<div class="col py-2">
<h1>{{ submission.name }}</h1>
{% if submission.description %}<p>{{ submission.description }}</p>{% endif %}
<div class="row py-2">
{% for md in metadata_display %}
<div class="col">
<b class="d-inline">{{ md.display_name }}</b>
{% if md.value %}
<p>{{ md.value }}</p>
{% else %}
<p></p>
{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
</div>
<div class="container">
{% if versions %}
<div class="row py-2">
<div class="col">
<a href="{% url 'upload' submission.id %}"
class="btn btn-primary mt-2 float-end">Upload</a>
</div>
<div class="row py-2 border-top">
<div class="col">
<a href="{% url 'upload' submission.id %}"
class="btn btn-primary mt-2 float-end">Upload</a>
</div>
<div class="row py-2">
</div>
<div class="row py-2">
{% if versions %}
<table id="results" class="table table-striped table-sm">
<thead>
<tr>
Expand All @@ -52,14 +63,10 @@ <h1>{{ submission.name }}</h1>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="row py-2">
<div class="col">
<a href="{% url 'upload' submission.id %}" class="btn btn-primary mt-2">Upload submission</a>
</div>
</div>
{% endif %}
{% else %}
<p class="text-center">See your results here after you make an upload!</p>
{% endif %}
</div>
</div>
<script>
async function main() {
Expand Down
31 changes: 26 additions & 5 deletions frx_challenges/web/views/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.auth.decorators import login_required
from django.http import Http404, HttpRequest, HttpResponse, HttpResponseRedirect
from django.shortcuts import render
from django.urls import reverse

from ..forms import SubmissionForm
from ..md import MARKDOWN_RENDERER
Expand All @@ -27,7 +28,9 @@ def create(request: HttpRequest) -> HttpResponse:
submission.metadata = form.cleaned_data["metadata"]
submission.toc_accepted = form.cleaned_data["toc_accepted"]
submission.save()
return HttpResponseRedirect("/submissions")
return HttpResponseRedirect(
reverse("submissions-detail", args=[submission.id])
)
else:
form = SubmissionForm()

Expand All @@ -45,21 +48,39 @@ def list(request: HttpRequest) -> HttpResponse:
return render(request, "submission/list.html", {"submissions": submissions})


@login_required
def detail(request: HttpRequest, id: int) -> HttpResponse:
"""
Show details of a specific submission, such as versions and evaluations
"""
queryset = Submission.objects.filter(user=request.user)
try:
submission = queryset.get(id=id)
submission = Submission.objects.get(id=id)
except Submission.DoesNotExist:
raise Http404("Submission does not exist")
versions = submission.versions.all()

# Decide how we display metadata
metadata_display = []
if settings.SITE_SUBMISSION_FORM_SCHEMA:
for k, v in settings.SITE_SUBMISSION_FORM_SCHEMA["properties"].items():
if v["type"] == "string":
metadata_display.append(
{
"display_name": v["title"],
"help_string": v.get("helpText"),
"value": submission.metadata.get(k),
}
)
else:
raise ValueError(f"Unsupported metadata schema type {v['type']} found")

return render(
request,
"submission/detail.html",
{"submission": submission, "versions": versions},
{
"submission": submission,
"versions": versions,
"metadata_display": metadata_display,
},
)


Expand Down

0 comments on commit 1f7a7c6

Please sign in to comment.