diff --git a/bda/admin.py b/bda/admin.py index 8f5915d5..eb8d3106 100644 --- a/bda/admin.py +++ b/bda/admin.py @@ -193,8 +193,9 @@ class SpectacleAdmin(admin.ModelAdmin): class TirageAdmin(admin.ModelAdmin): model = Tirage - list_display = ("title", "ouverture", "fermeture", "active") - readonly_fields = ("token", ) + list_display = ("title", "ouverture", "fermeture", "active", + "enable_do_tirage") + readonly_fields = ("tokens", ) list_filter = ("active", ) search_fields = ("title", ) diff --git a/bda/migrations/0006_add_tirage_switch.py b/bda/migrations/0006_add_tirage_switch.py new file mode 100644 index 00000000..fc923c9a --- /dev/null +++ b/bda/migrations/0006_add_tirage_switch.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +from django.utils import timezone + + +def forwards_func(apps, schema_editor): + Tirage = apps.get_model("bda", "Tirage") + db_alias = schema_editor.connection.alias + for tirage in Tirage.objects.using(db_alias).all(): + if tirage.tokens: + tirage.tokens = "Before %s\n\"\"\"%s\"\"\"\n" % ( + timezone.now().strftime("%y-%m-%d %H:%M:%S"), + tirage.tokens) + tirage.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('bda', '0005_encoding'), + ] + + operations = [ + migrations.RenameField('tirage', 'token', 'tokens'), + migrations.AddField( + model_name='tirage', + name='enable_do_tirage', + field=models.BooleanField( + default=False, + verbose_name=b'Le tirage peut \xc3\xaatre lanc\xc3\xa9'), + ), + migrations.RunPython(forwards_func, migrations.RunPython.noop), + ] diff --git a/bda/models.py b/bda/models.py index 41037643..ba72416a 100644 --- a/bda/models.py +++ b/bda/models.py @@ -26,8 +26,10 @@ class Tirage(models.Model): title = models.CharField("Titre", max_length=300) ouverture = models.DateTimeField("Date et heure d'ouverture du tirage") fermeture = models.DateTimeField("Date et heure de fermerture du tirage") - token = models.TextField("Graine du tirage", blank=True) + tokens = models.TextField("Graine(s) du tirage", blank=True) active = models.BooleanField("Tirage actif", default=False) + enable_do_tirage = models.BooleanField("Le tirage peut être lancé", + default=False) def date_no_seconds(self): return self.fermeture.strftime('%d %b %Y %H:%M') diff --git a/bda/templates/bda-attrib-extra.html b/bda/templates/bda-attrib-extra.html index 1fdb29a5..b2e05132 100644 --- a/bda/templates/bda-attrib-extra.html +++ b/bda/templates/bda-attrib-extra.html @@ -2,7 +2,7 @@ {% block extracontent %} -
{{ token }}
Pour raison de sécurité, le lancement du tirage + a été désactivé. Vous pouvez le réactiver dans + l'interface admin
+{{ token }}
Soit les inscriptions ne sont en pas encore fermées, soit le lancement du +tirage est désactivé. Si vous savez ce que vous faites, vous pouvez autoriser +le lancement du tirage dans +l'interface admin.
+{% endblock %} diff --git a/bda/views.py b/bda/views.py index fbf75359..bf666f08 100644 --- a/bda/views.py +++ b/bda/views.py @@ -197,8 +197,6 @@ def do_tirage(request, tirage_id): form = TokenForm(request.POST) if not form.is_valid(): return tirage(request, tirage_id) - tirage_elt.token = form.cleaned_data['token'] - tirage_elt.save() start = time.time() data = {} shows = tirage_elt.spectacle_set.select_related().all() @@ -249,16 +247,16 @@ def do_tirage(request, tirage_id): members2 = members2.items() data["members2"] = sorted(members2, key=lambda m: m[0].user.last_name) # À partir d'ici, le tirage devient effectif - # FIXME: Établir les conditions de validations (formulaire ?) - # cf. issue #32 - if True: - Attribution.objects.filter( - spectacle__tirage=tirage_elt - ).delete() - for (show, members, _) in results: - for (member, _, _, _) in members: - attrib = Attribution(spectacle=show, participant=member) - attrib.save() + Attribution.objects.filter(spectacle__tirage=tirage_elt).delete() + tirage_elt.tokens += "%s\n\"\"\"%s\"\"\"\n" % ( + timezone.now().strftime("%y-%m-%d %H:%M:%S"), + form.cleaned_data['token']) + tirage_elt.enable_do_tirage = False + tirage_elt.save() + Attribution.objects.bulk_create([ + Attribution(spectacle=show, participant=member) + for show, members, _ in results + for member, _, _, _ in members]) return render(request, "bda-attrib-extra.html", data) else: return render(request, "bda-attrib.html", data) @@ -266,6 +264,10 @@ def do_tirage(request, tirage_id): @buro_required def tirage(request, tirage_id): + tirage_elt = get_object_or_404(Tirage, id=tirage_id) + if not (tirage_elt.enable_do_tirage + and tirage_elt.fermeture < timezone.now()): + return render(request, "tirage-failed.html", {'tirage': tirage_elt}) if request.POST: form = TokenForm(request.POST) if form.is_valid(): diff --git a/gestioncof/static/css/cof.css b/gestioncof/static/css/cof.css index 21b38d97..5db3c9bb 100644 --- a/gestioncof/static/css/cof.css +++ b/gestioncof/static/css/cof.css @@ -526,6 +526,10 @@ h4.block-title { background-color: transparent; } +.success a { + color: inherit; +} + .error { font-weight: bold; color: #F6BEBE;