diff --git a/frx_challenges/frx_challenges/settings.py b/frx_challenges/frx_challenges/settings.py
index a8c56e9..b7e087c 100644
--- a/frx_challenges/frx_challenges/settings.py
+++ b/frx_challenges/frx_challenges/settings.py
@@ -260,6 +260,7 @@
"type": "string",
"title": "Repository",
"helpText": "Link to repository containing code and stuff",
+ "format": "uri",
}
},
}
diff --git a/frx_challenges/web/forms.py b/frx_challenges/web/forms.py
index 628c0b3..aaed525 100644
--- a/frx_challenges/web/forms.py
+++ b/frx_challenges/web/forms.py
@@ -5,11 +5,12 @@
from django.urls import reverse
from django.utils.safestring import mark_safe
from django_jsonform.forms.fields import JSONFormField
+from web.models import Submission
from .md import MARKDOWN_RENDERER
-class SubmissionForm(forms.Form):
+class SubmissionForm(forms.ModelForm):
"""Form to create a new submission"""
def __init__(self, *args, **kwargs):
@@ -17,12 +18,12 @@ def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_method = "post"
- self.helper.form_action = "submissions-create"
self.helper.add_input(
Submit("submit", "Submit", css_class="form-control btn btn-secondary")
)
self.fields["name"] = forms.CharField()
+ self.fields["name"].label = "Submission name"
self.fields["description"] = forms.CharField(required=False)
self.fields["metadata"] = JSONFormField(
schema=settings.SITE_SUBMISSION_FORM_SCHEMA
@@ -34,6 +35,10 @@ def __init__(self, *args, **kwargs):
required=True,
)
+ class Meta:
+ model = Submission
+ fields = ["name", "description", "metadata", "toc_accepted"]
+
class UploadForm(forms.Form):
"""Form to upload a version of a submission to be evaluated"""
diff --git a/frx_challenges/web/templates/results.html b/frx_challenges/web/templates/results.html
index e746965..e9a1a03 100644
--- a/frx_challenges/web/templates/results.html
+++ b/frx_challenges/web/templates/results.html
@@ -62,7 +62,7 @@
Explanatory Headline
const resultsTable = new DataTable("#results", {
order: [
// Apply reverse chronological ordering by default
- [3, "desc"]
+ [3, "asc"]
],
columnDefs: [
{
diff --git a/frx_challenges/web/templates/submission/create.html b/frx_challenges/web/templates/submission/create.html
index 1eacb3c..504ff63 100644
--- a/frx_challenges/web/templates/submission/create.html
+++ b/frx_challenges/web/templates/submission/create.html
@@ -6,6 +6,8 @@
Create a submission
+
+ {{ html_content|safe }}
diff --git a/frx_challenges/web/templates/submission/detail.html b/frx_challenges/web/templates/submission/detail.html
index f1bd398..4669319 100644
--- a/frx_challenges/web/templates/submission/detail.html
+++ b/frx_challenges/web/templates/submission/detail.html
@@ -13,13 +13,25 @@
-
{{ submission.name }}
- {% if submission.description %}
{{ submission.description }}
{% endif %}
+
+
+
{{ submission.name }}
+ {% if submission.description %}
{{ submission.description }}
{% endif %}
+
+
+
{% for md in metadata_display %}
{{ md.display_name }}
- {% if md.value %}
+ {% if md.value and md.format == 'uri' %}
+
+ {{ md.value }}
+
+ {% elif md.value %}
{{ md.value }}
{% else %}
–
@@ -74,7 +86,7 @@
{{ submission.name }}
const resultsTable = new DataTable("#results", {
order: [
// Apply reverse chronological ordering by default
- [2, "desc"]
+ [2, "asc"]
],
columnDefs: [
{
diff --git a/frx_challenges/web/templates/submission/edit.html b/frx_challenges/web/templates/submission/edit.html
new file mode 100644
index 0000000..6670f8f
--- /dev/null
+++ b/frx_challenges/web/templates/submission/edit.html
@@ -0,0 +1,17 @@
+{% extends "page.html" %}
+{% load static %}
+{% load crispy_forms_tags %}
+{% block body %}
+
+
+
+
Edit a submission
+
+ {{ html_content|safe }}
+
+
+
+
+{% endblock body %}
diff --git a/frx_challenges/web/templates/submission/list.html b/frx_challenges/web/templates/submission/list.html
index 011d110..42342ba 100644
--- a/frx_challenges/web/templates/submission/list.html
+++ b/frx_challenges/web/templates/submission/list.html
@@ -12,26 +12,23 @@
{% block body %}
-
-
- Create, view and edit submissions. Each submission can contain multiple entries. Click on the submission name to view details.
-
+
Create, view and edit submissions. Each submission can contain multiple entries.
+
Click on the submission name to view details.
{% if submissions %}
-
@@ -80,7 +77,7 @@ My Submissions
const resultsTable = new DataTable("#results", {
order: [
// Apply reverse chronological ordering by default
- [3, "desc"]
+ [3, "asc"]
],
columnDefs: [
{
diff --git a/frx_challenges/web/urls.py b/frx_challenges/web/urls.py
index 3c21089..4a72e4d 100644
--- a/frx_challenges/web/urls.py
+++ b/frx_challenges/web/urls.py
@@ -19,6 +19,7 @@
path("submissions/", submissions.list, name="submissions-list"),
path("submissions/create", submissions.create, name="submissions-create"),
path("submissions/", submissions.detail, name="submissions-detail"),
+ path("submissions//edit", submissions.edit, name="submissions-edit"),
path(
"evaluation/", submissions.detail_evaluation, name="evaluation-detail"
),
diff --git a/frx_challenges/web/views/submissions.py b/frx_challenges/web/views/submissions.py
index 9abfcbb..a3af67b 100644
--- a/frx_challenges/web/views/submissions.py
+++ b/frx_challenges/web/views/submissions.py
@@ -68,6 +68,7 @@ def detail(request: HttpRequest, id: int) -> HttpResponse:
"display_name": v["title"],
"help_string": v.get("helpText"),
"value": submission.metadata.get(k),
+ "format": v["format"],
}
)
else:
@@ -84,6 +85,39 @@ def detail(request: HttpRequest, id: int) -> HttpResponse:
)
+@login_required
+def edit(request: HttpRequest, id: int) -> HttpResponse:
+ """
+ Edit submission metadata
+ """
+
+ html_content = MARKDOWN_RENDERER.render(
+ settings.SITE_SUBMISSION_INSTRUCTIONS_MARKDOWN
+ )
+
+ # Get model instance to pre-populate form
+ submission = Submission.objects.get(id=id)
+
+ if request.method == "POST":
+ form = SubmissionForm(request.POST, instance=submission)
+ if form.is_valid():
+ submission.user = request.user
+ submission.name = form.cleaned_data["name"]
+ submission.description = form.cleaned_data["description"]
+ submission.metadata = form.cleaned_data["metadata"]
+ submission.toc_accepted = form.cleaned_data["toc_accepted"]
+ submission.save()
+ return HttpResponseRedirect(
+ reverse("submissions-detail", args=[submission.id])
+ )
+ else:
+ form = SubmissionForm(instance=submission)
+
+ return render(
+ request, "submission/edit.html", {"form": form, "html_content": html_content}
+ )
+
+
@login_required
def detail_evaluation(request: HttpRequest, id: int) -> HttpResponse:
"""