mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-24 17:02:24 +00:00
Upload to the good place
This commit is contained in:
parent
2ca0444053
commit
ead59e28b8
@ -312,6 +312,15 @@ class Pool(models.Model):
|
||||
verbose_name_plural = _("pools")
|
||||
|
||||
|
||||
def get_solution_filename(instance, filename):
|
||||
return f"solutions/{instance.participation.team.trigram}_{instance.problem}" \
|
||||
+ ("final" if instance.final_solution else "")
|
||||
|
||||
|
||||
def get_random_synthesis_filename(instance, filename):
|
||||
return "syntheses/" + get_random_string(64)
|
||||
|
||||
|
||||
class Solution(models.Model):
|
||||
participation = models.ForeignKey(
|
||||
Participation,
|
||||
@ -331,14 +340,15 @@ class Solution(models.Model):
|
||||
|
||||
file = models.FileField(
|
||||
verbose_name=_("file"),
|
||||
upload_to="solutions/",
|
||||
upload_to=get_solution_filename,
|
||||
unique=True,
|
||||
blank=True,
|
||||
default="",
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return repr(self)
|
||||
return _("Solution of team {team} for problem {problem}")\
|
||||
.format(team=self.participation.team.name, problem=self.problem)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("solution")
|
||||
@ -369,7 +379,7 @@ class Synthesis(models.Model):
|
||||
|
||||
file = models.FileField(
|
||||
verbose_name=_("file"),
|
||||
upload_to="syntheses/",
|
||||
upload_to=get_random_synthesis_filename,
|
||||
unique=True,
|
||||
blank=True,
|
||||
default="",
|
||||
|
@ -19,9 +19,7 @@
|
||||
<dt class="col-sm-2">{% trans "Solutions:" %}</dt>
|
||||
<dd class="col-sm-10">
|
||||
{% for solution in participation.solutions.all %}
|
||||
<a href="{% url "solution" filename=solution.file %}">
|
||||
{% blocktrans trimmed with problem=solution.problem %}problem {{ problem }}{% endblocktrans %}{% if not forloop.last %}, {% endif %}
|
||||
</a>
|
||||
<a href="{{ solution.file.url }}">{{ solution }}{% if not forloop.last %}, {% endif %}</a>
|
||||
{% empty %}
|
||||
{% trans "No solution was uploaded yet." %}
|
||||
{% endfor %}
|
||||
@ -36,7 +34,7 @@
|
||||
{% trans "Upload solution" as modal_title %}
|
||||
{% trans "Upload" as modal_button %}
|
||||
{% url "participation:upload_solution" pk=participation.pk as modal_action %}
|
||||
{% include "base_modal.html" with modal_id="uploadSolution" %}
|
||||
{% include "base_modal.html" with modal_id="uploadSolution" modal_enctype="multipart/form-data" %}
|
||||
{% endblock %}
|
||||
|
||||
{% block extrajavascript %}
|
||||
|
@ -3,7 +3,7 @@
|
||||
{% load crispy_forms_filters i18n %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post">
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<div id="form-content">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
|
@ -456,11 +456,10 @@ class SolutionUploadView(LoginRequiredMixin, FormView):
|
||||
"""
|
||||
form_sol = form.instance
|
||||
# Drop previous solution if existing
|
||||
Solution.objects.filter(
|
||||
participation=self.participation,
|
||||
problem=form_sol.problem,
|
||||
final_solution=self.participation.final,
|
||||
).delete()
|
||||
for sol in Solution.objects.filter(participation=self.participation,
|
||||
problem=form_sol.problem,
|
||||
final_solution=self.participation.final).all():
|
||||
sol.delete()
|
||||
form_sol.participation = self.participation
|
||||
form_sol.final = self.participation.final
|
||||
form_sol.save()
|
||||
|
Loading…
Reference in New Issue
Block a user