mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2024-12-24 17:42:23 +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")
|
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):
|
class Solution(models.Model):
|
||||||
participation = models.ForeignKey(
|
participation = models.ForeignKey(
|
||||||
Participation,
|
Participation,
|
||||||
@ -331,14 +340,15 @@ class Solution(models.Model):
|
|||||||
|
|
||||||
file = models.FileField(
|
file = models.FileField(
|
||||||
verbose_name=_("file"),
|
verbose_name=_("file"),
|
||||||
upload_to="solutions/",
|
upload_to=get_solution_filename,
|
||||||
unique=True,
|
unique=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
default="",
|
default="",
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
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:
|
class Meta:
|
||||||
verbose_name = _("solution")
|
verbose_name = _("solution")
|
||||||
@ -369,7 +379,7 @@ class Synthesis(models.Model):
|
|||||||
|
|
||||||
file = models.FileField(
|
file = models.FileField(
|
||||||
verbose_name=_("file"),
|
verbose_name=_("file"),
|
||||||
upload_to="syntheses/",
|
upload_to=get_random_synthesis_filename,
|
||||||
unique=True,
|
unique=True,
|
||||||
blank=True,
|
blank=True,
|
||||||
default="",
|
default="",
|
||||||
|
@ -19,9 +19,7 @@
|
|||||||
<dt class="col-sm-2">{% trans "Solutions:" %}</dt>
|
<dt class="col-sm-2">{% trans "Solutions:" %}</dt>
|
||||||
<dd class="col-sm-10">
|
<dd class="col-sm-10">
|
||||||
{% for solution in participation.solutions.all %}
|
{% for solution in participation.solutions.all %}
|
||||||
<a href="{% url "solution" filename=solution.file %}">
|
<a href="{{ solution.file.url }}">{{ solution }}{% if not forloop.last %}, {% endif %}</a>
|
||||||
{% blocktrans trimmed with problem=solution.problem %}problem {{ problem }}{% endblocktrans %}{% if not forloop.last %}, {% endif %}
|
|
||||||
</a>
|
|
||||||
{% empty %}
|
{% empty %}
|
||||||
{% trans "No solution was uploaded yet." %}
|
{% trans "No solution was uploaded yet." %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@ -36,7 +34,7 @@
|
|||||||
{% trans "Upload solution" as modal_title %}
|
{% trans "Upload solution" as modal_title %}
|
||||||
{% trans "Upload" as modal_button %}
|
{% trans "Upload" as modal_button %}
|
||||||
{% url "participation:upload_solution" pk=participation.pk as modal_action %}
|
{% 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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extrajavascript %}
|
{% block extrajavascript %}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
{% load crispy_forms_filters i18n %}
|
{% load crispy_forms_filters i18n %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<form method="post">
|
<form method="post" enctype="multipart/form-data">
|
||||||
<div id="form-content">
|
<div id="form-content">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form|crispy }}
|
{{ form|crispy }}
|
||||||
|
@ -456,11 +456,10 @@ class SolutionUploadView(LoginRequiredMixin, FormView):
|
|||||||
"""
|
"""
|
||||||
form_sol = form.instance
|
form_sol = form.instance
|
||||||
# Drop previous solution if existing
|
# Drop previous solution if existing
|
||||||
Solution.objects.filter(
|
for sol in Solution.objects.filter(participation=self.participation,
|
||||||
participation=self.participation,
|
problem=form_sol.problem,
|
||||||
problem=form_sol.problem,
|
final_solution=self.participation.final).all():
|
||||||
final_solution=self.participation.final,
|
sol.delete()
|
||||||
).delete()
|
|
||||||
form_sol.participation = self.participation
|
form_sol.participation = self.participation
|
||||||
form_sol.final = self.participation.final
|
form_sol.final = self.participation.final
|
||||||
form_sol.save()
|
form_sol.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user