-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 0018_reset_button.patch: an administrator will find a button on t…
…he homepage next to the race name that allows to do a full reset
- Loading branch information
1 parent
5cb7abf
commit 1f80c91
Showing
3 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
diff --git a/engine/context_processors.py b/engine/context_processors.py | ||
index ab617b5..a9a719c 100644 | ||
--- a/engine/context_processors.py | ||
+++ b/engine/context_processors.py | ||
@@ -5,7 +5,7 @@ from engine.models import Gara | ||
|
||
|
||
def get_gare(): | ||
- gare = Gara.objects.filter(inizio__isnull=False) | ||
+ gare = Gara.objects.filter(inizio__isnull=False).order_by("-inizio", "-id") | ||
loraesatta = timezone.now() | ||
attive = [] | ||
archivio = [] | ||
@@ -14,7 +14,7 @@ def get_gare(): | ||
archivio.append(g) | ||
else: | ||
attive.append(g) | ||
- da_iniziare = Gara.objects.filter(inizio__isnull=True) | ||
+ da_iniziare = Gara.objects.filter(inizio__isnull=True).order_by("-id") | ||
return attive, archivio, da_iniziare | ||
|
||
|
||
diff --git a/engine/templates/gara/reset.html b/engine/templates/gara/reset.html | ||
new file mode 100644 | ||
index 0000000..72fc6ed | ||
--- /dev/null | ||
+++ b/engine/templates/gara/reset.html | ||
@@ -0,0 +1,16 @@ | ||
+{% extends "basegara.html" %} | ||
+{% block title %}{{object.nome}} reset{% endblock %} | ||
+ | ||
+{% block content %} | ||
+<h3>Gara: <a href="{% url 'engine:gara-detail' object.pk %}">{{ object.nome }}</a></h3> | ||
+ | ||
+ | ||
+<p> | ||
+Questa azione cancellerà tutte le consegne, tutti i jolly e tutti i bonus registrati nella gara, e ne azzererà la data ed ora di inizio. Sei sicuro di voler procedere?<br/> | ||
+<form method="post">{% csrf_token %} | ||
+ <input type="hidden" name="reset" value=1> | ||
+ <input type="submit" value="Sì, procedi al reset della gara!" id="submit"> | ||
+</form> | ||
+</p> | ||
+ | ||
+{% endblock %} | ||
diff --git a/engine/templates/index.html b/engine/templates/index.html | ||
index fa86faa..0a8c812 100644 | ||
--- a/engine/templates/index.html | ||
+++ b/engine/templates/index.html | ||
@@ -21,6 +21,10 @@ | ||
<th>Testo</th> | ||
<th>Inizio</th> | ||
<th>Fine</th> | ||
+ {% if user.is_staff %} | ||
+ <th>Download</th> | ||
+ <th>Reset</th> | ||
+ {% endif %} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@@ -31,6 +35,10 @@ | ||
<td>{% if gara.testo %}<a href="{{gara.testo}}" target=_blank><i class="fas fa-file-pdf"></i></a>{% else %}<i class="fas fa-ban"></i>{% endif %}</td> | ||
<td>{{gara.inizio}}</td> | ||
<td>{{gara.get_ora_fine}}</td> | ||
+ {% if user.is_staff %} | ||
+ <td><a href="{% url 'engine:gara-download' gara.pk%}" target=_blank><i class="fas fa-download"></i></a></td> | ||
+ <td><a href="{% url 'engine:gara-reset' gara.pk%}" target=_blank><i class="fas fa-undo"></i></a></td> | ||
+ {% endif %} | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
@@ -58,6 +66,10 @@ | ||
<tr> | ||
<th>Id</th> | ||
<th>Nome</th> | ||
+ {% if user.is_staff %} | ||
+ <th>Download</th> | ||
+ <th>Reset</th> | ||
+ {% endif %} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@@ -65,6 +77,10 @@ | ||
<tr> | ||
<td>{{gara.pk}}</td> | ||
<td><a href="{% url 'engine:gara-detail' gara.pk%}">{{gara.nome}}</a></td> | ||
+ {% if user.is_staff %} | ||
+ <td><a href="{% url 'engine:gara-download' gara.pk%}" target=_blank><i class="fas fa-download"></i></a></td> | ||
+ <td><a href="{% url 'engine:gara-reset' gara.pk%}" target=_blank><i class="fas fa-undo"></i></a></td> | ||
+ {% endif %} | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
@@ -93,7 +109,10 @@ | ||
<th>Nome</th> | ||
<th>Inizio</th> | ||
<th>Fine</th> | ||
+ {% if user.is_staff %} | ||
<th>Download</th> | ||
+ <th>Reset</th> | ||
+ {% endif %} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@@ -103,7 +122,10 @@ | ||
<td><a href="{% url 'engine:gara-detail' gara.pk%}">{{gara.nome}}</a></td> | ||
<td>{{gara.inizio}}</td> | ||
<td>{{gara.get_ora_fine}}</td> | ||
+ {% if user.is_staff %} | ||
<td><a href="{% url 'engine:gara-download' gara.pk%}" target=_blank><i class="fas fa-download"></i></a></td> | ||
+ <td><a href="{% url 'engine:gara-reset' gara.pk%}" target=_blank><i class="fas fa-undo"></i></a></td> | ||
+ {% endif %} | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
diff --git a/engine/urls.py b/engine/urls.py | ||
index 1c91adc..f49cf45 100644 | ||
--- a/engine/urls.py | ||
+++ b/engine/urls.py | ||
@@ -17,6 +17,7 @@ urlpatterns = [ | ||
path('gara/<int:pk>/risposte', GaraRisposteView.as_view(), name='gara-risposte'), | ||
path('gara/<int:pk>/squadre', GaraSquadreView.as_view(), name='gara-squadre'), | ||
path('gara/<int:pk>/download', DownloadGaraView.as_view(), name='gara-download'), | ||
+ path('gara/<int:pk>/reset', GaraResetView.as_view(), name='gara-reset'), | ||
path('query/<int:pk>', QueryView.as_view(), name='query'), | ||
path('inserisci/<int:pk>', InserimentoView.as_view(), name='inserimento'), | ||
path('evento/<int:pk>/modifica', ModificaEventoView.as_view(), name='evento-modifica'), | ||
diff --git a/engine/views.py b/engine/views.py | ||
index 1e3cf2e..39ba350 100644 | ||
--- a/engine/views.py | ||
+++ b/engine/views.py | ||
@@ -9,6 +9,7 @@ from django.http import JsonResponse, HttpResponse | ||
from django.utils import timezone | ||
from django.db import transaction | ||
from django.contrib.auth import login, authenticate | ||
+from django import forms | ||
|
||
from engine.models import User, Gara, Soluzione, Squadra, Evento, Consegna, Jolly, Bonus | ||
from engine.forms import SignUpForm, RispostaFormset, SquadraFormset, InserimentoForm,\ | ||
@@ -272,15 +273,41 @@ class DownloadGaraView(DetailView): | ||
|
||
def get(self, request, *args, **kwargs): | ||
super().get(request, *args, **kwargs) | ||
- loraesatta = timezone.now() | ||
- if self.object.get_ora_fine() >= loraesatta: | ||
- return HttpResponse('Non puoi scaricare una gara in corso', status=404) | ||
data = self.object.dump_to_json() | ||
response = HttpResponse(data, content_type="application/json") | ||
response['Content-Disposition'] = 'attachment; filename={}.json'.format(self.object.nome) | ||
return response | ||
|
||
|
||
+class GaraResetView(CheckPermissionsMixin, SuccessMessageMixin, FormView, DetailView): | ||
+ """ View per il reset di una gara """ | ||
+ model = Gara | ||
+ form_class = forms.Form | ||
+ template_name = "gara/reset.html" | ||
+ success_message = 'Reset gara avvenuto con successo!' | ||
+ | ||
+ def test_func(self): | ||
+ # Salva la gara dentro self.object, così siamo sicuri | ||
+ # che sia stata validata e non viene chiamato get_object() due volte. | ||
+ self.object = self.get_object() | ||
+ return self.request.user.can_administrate(self.object) | ||
+ | ||
+ def form_valid(self, form): | ||
+ gara = self.object | ||
+ Jolly.objects.filter(gara=gara).delete() | ||
+ Jolly.history.filter(gara=gara).delete() | ||
+ Consegna.objects.filter(gara=gara).delete() | ||
+ Consegna.history.filter(gara=gara).delete() | ||
+ Bonus.objects.filter(gara=gara).delete() | ||
+ Bonus.history.filter(gara=gara).delete() | ||
+ gara.inizio = None | ||
+ gara.save() | ||
+ return super().form_valid(form) | ||
+ | ||
+ def get_success_url(self, **kwargs): | ||
+ return reverse("engine:gara-admin", kwargs={'pk': self.object.pk}) | ||
+ | ||
+ | ||
####################################### | ||
# VIEW QUERY # | ||
####################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters