Ajoute un switch sur les tirages

Le switch permet d'autoriser/interdire le lancement d'un tirage. Il
s'agit d'une sécurité face aux erreurs d'inattention.

Le champ `token` du modèle `Tirage` devient `tokens` et stocke les
graines des tirages déjà lancés si le tirage est lancé plusieurs fois.
This commit is contained in:
Martin Pépin 2016-07-08 00:18:58 +02:00
parent 7de11f2285
commit 9e50a825e0
3 changed files with 36 additions and 3 deletions

View file

@ -144,8 +144,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", )

View file

@ -0,0 +1,30 @@
# -*- 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.all():
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', '0003_update_tirage_and_spectacle'),
]
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),
]

View file

@ -10,8 +10,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')