forked from DGNum/gestioCOF
change shotgun en booleanfield
This commit is contained in:
parent
e267cb91ef
commit
4c6b33ccb4
3 changed files with 12 additions and 25 deletions
|
@ -218,7 +218,7 @@ class SpectacleReventeAdmin(admin.ModelAdmin):
|
||||||
|
|
||||||
list_display = ("spectacle", "seller", "date", "soldTo")
|
list_display = ("spectacle", "seller", "date", "soldTo")
|
||||||
raw_id_fields = ("attribution",)
|
raw_id_fields = ("attribution",)
|
||||||
readonly_fields = ("shotgun", "expiration_time")
|
readonly_fields = ("expiration_time",)
|
||||||
search_fields = ("spectacle__title",
|
search_fields = ("spectacle__title",
|
||||||
"seller__user__username",
|
"seller__user__username",
|
||||||
"seller__user__firstname",
|
"seller__user__firstname",
|
||||||
|
|
|
@ -228,7 +228,6 @@ class SpectacleRevente(models.Model):
|
||||||
answered_mail = models.ManyToManyField(Participant,
|
answered_mail = models.ManyToManyField(Participant,
|
||||||
related_name="wanted",
|
related_name="wanted",
|
||||||
blank=True)
|
blank=True)
|
||||||
|
|
||||||
seller = models.ForeignKey(Participant,
|
seller = models.ForeignKey(Participant,
|
||||||
related_name="original_shows",
|
related_name="original_shows",
|
||||||
verbose_name="Vendeur")
|
verbose_name="Vendeur")
|
||||||
|
@ -239,6 +238,8 @@ class SpectacleRevente(models.Model):
|
||||||
default=False)
|
default=False)
|
||||||
tirage_done = models.BooleanField("Tirage effectué",
|
tirage_done = models.BooleanField("Tirage effectué",
|
||||||
default=False)
|
default=False)
|
||||||
|
shotgun = models.BooleanField("Disponible immédiatement",
|
||||||
|
default=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def expiration_time(self):
|
def expiration_time(self):
|
||||||
|
@ -255,16 +256,6 @@ class SpectacleRevente(models.Model):
|
||||||
.astimezone(timezone.get_current_timezone()) \
|
.astimezone(timezone.get_current_timezone()) \
|
||||||
.strftime('%D à %H:%M')
|
.strftime('%D à %H:%M')
|
||||||
|
|
||||||
@property
|
|
||||||
def shotgun(self):
|
|
||||||
# Soit on a dépassé le délai du tirage, soit il reste peu de
|
|
||||||
# temps avant le spectacle
|
|
||||||
# On se laisse 5min de marge pour cron
|
|
||||||
return (timezone.now() > self.expiration_time + timedelta(minutes=5) or
|
|
||||||
(self.attribution.spectacle.date <= timezone.now() +
|
|
||||||
timedelta(days=1))) and (timezone.now() >= self.date +
|
|
||||||
timedelta(minutes=15))
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s -- %s" % (self.seller,
|
return "%s -- %s" % (self.seller,
|
||||||
self.attribution.spectacle.title)
|
self.attribution.spectacle.title)
|
||||||
|
@ -318,6 +309,7 @@ class SpectacleRevente(models.Model):
|
||||||
connection = mail.get_connection()
|
connection = mail.get_connection()
|
||||||
connection.send_messages(mails_to_send)
|
connection.send_messages(mails_to_send)
|
||||||
self.notif_sent = True
|
self.notif_sent = True
|
||||||
|
self.shotgun = True
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def tirage(self):
|
def tirage(self):
|
||||||
|
@ -350,4 +342,5 @@ Le BdA""" % (spectacle.title, winner.user.get_full_name(), winner.user.email)
|
||||||
mail_seller, "bda@ens.fr", [seller.user.email],
|
mail_seller, "bda@ens.fr", [seller.user.email],
|
||||||
fail_silently=False)
|
fail_silently=False)
|
||||||
self.tirage_done = True
|
self.tirage_done = True
|
||||||
|
self.shotgun = True
|
||||||
self.save()
|
self.save()
|
||||||
|
|
20
bda/views.py
20
bda/views.py
|
@ -367,6 +367,7 @@ def revente_interested(request, revente_id):
|
||||||
participant, created = Participant.objects.get_or_create(
|
participant, created = Participant.objects.get_or_create(
|
||||||
user=request.user, tirage=revente.attribution.spectacle.tirage)
|
user=request.user, tirage=revente.attribution.spectacle.tirage)
|
||||||
if timezone.now() < revente.date + timedelta(hours=1) or revente.shotgun:
|
if timezone.now() < revente.date + timedelta(hours=1) or revente.shotgun:
|
||||||
|
# TODO améliorer le message d'erreur
|
||||||
return render(request, "bda-wrongtime.html", {})
|
return render(request, "bda-wrongtime.html", {})
|
||||||
|
|
||||||
revente.answered_mail.add(participant)
|
revente.answered_mail.add(participant)
|
||||||
|
@ -388,13 +389,9 @@ def list_revente(request, tirage_id):
|
||||||
for spectacle in spectacles:
|
for spectacle in spectacles:
|
||||||
revente_objects = SpectacleRevente.objects.filter(
|
revente_objects = SpectacleRevente.objects.filter(
|
||||||
attribution__spectacle=spectacle,
|
attribution__spectacle=spectacle,
|
||||||
soldTo__isnull=True)
|
soldTo__isnull=True,
|
||||||
revente_count = 0
|
shotgun=True)
|
||||||
for revente in revente_objects:
|
if revente_objects.exists():
|
||||||
if revente.shotgun:
|
|
||||||
revente_count += 1
|
|
||||||
if revente_count:
|
|
||||||
spectacle.revente_count = revente_count
|
|
||||||
shotgun.append(spectacle)
|
shotgun.append(spectacle)
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
@ -440,16 +437,13 @@ def buy_revente(request, spectacle_id):
|
||||||
revente.delete()
|
revente.delete()
|
||||||
return HttpResponseRedirect(reverse("bda-liste-revente",
|
return HttpResponseRedirect(reverse("bda-liste-revente",
|
||||||
args=[tirage.id]))
|
args=[tirage.id]))
|
||||||
reventes_shotgun = []
|
reventes_shotgun = reventes.filter(shotgun=True)
|
||||||
for revente in reventes.all():
|
|
||||||
if revente.shotgun:
|
|
||||||
reventes_shotgun.append(revente)
|
|
||||||
|
|
||||||
if not reventes_shotgun:
|
if not reventes_shotgun.exists():
|
||||||
return render(request, "bda-no-revente.html", {})
|
return render(request, "bda-no-revente.html", {})
|
||||||
|
|
||||||
if request.POST:
|
if request.POST:
|
||||||
revente = random.choice(reventes_shotgun)
|
revente = random.choice(reventes_shotgun.all())
|
||||||
revente.soldTo = participant
|
revente.soldTo = participant
|
||||||
revente.save()
|
revente.save()
|
||||||
mail = """Bonjour !
|
mail = """Bonjour !
|
||||||
|
|
Loading…
Reference in a new issue