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")
|
||||
raw_id_fields = ("attribution",)
|
||||
readonly_fields = ("shotgun", "expiration_time")
|
||||
readonly_fields = ("expiration_time",)
|
||||
search_fields = ("spectacle__title",
|
||||
"seller__user__username",
|
||||
"seller__user__firstname",
|
||||
|
|
|
@ -228,7 +228,6 @@ class SpectacleRevente(models.Model):
|
|||
answered_mail = models.ManyToManyField(Participant,
|
||||
related_name="wanted",
|
||||
blank=True)
|
||||
|
||||
seller = models.ForeignKey(Participant,
|
||||
related_name="original_shows",
|
||||
verbose_name="Vendeur")
|
||||
|
@ -239,6 +238,8 @@ class SpectacleRevente(models.Model):
|
|||
default=False)
|
||||
tirage_done = models.BooleanField("Tirage effectué",
|
||||
default=False)
|
||||
shotgun = models.BooleanField("Disponible immédiatement",
|
||||
default=False)
|
||||
|
||||
@property
|
||||
def expiration_time(self):
|
||||
|
@ -255,16 +256,6 @@ class SpectacleRevente(models.Model):
|
|||
.astimezone(timezone.get_current_timezone()) \
|
||||
.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):
|
||||
return "%s -- %s" % (self.seller,
|
||||
self.attribution.spectacle.title)
|
||||
|
@ -318,6 +309,7 @@ class SpectacleRevente(models.Model):
|
|||
connection = mail.get_connection()
|
||||
connection.send_messages(mails_to_send)
|
||||
self.notif_sent = True
|
||||
self.shotgun = True
|
||||
self.save()
|
||||
|
||||
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],
|
||||
fail_silently=False)
|
||||
self.tirage_done = True
|
||||
self.shotgun = True
|
||||
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(
|
||||
user=request.user, tirage=revente.attribution.spectacle.tirage)
|
||||
if timezone.now() < revente.date + timedelta(hours=1) or revente.shotgun:
|
||||
# TODO améliorer le message d'erreur
|
||||
return render(request, "bda-wrongtime.html", {})
|
||||
|
||||
revente.answered_mail.add(participant)
|
||||
|
@ -388,13 +389,9 @@ def list_revente(request, tirage_id):
|
|||
for spectacle in spectacles:
|
||||
revente_objects = SpectacleRevente.objects.filter(
|
||||
attribution__spectacle=spectacle,
|
||||
soldTo__isnull=True)
|
||||
revente_count = 0
|
||||
for revente in revente_objects:
|
||||
if revente.shotgun:
|
||||
revente_count += 1
|
||||
if revente_count:
|
||||
spectacle.revente_count = revente_count
|
||||
soldTo__isnull=True,
|
||||
shotgun=True)
|
||||
if revente_objects.exists():
|
||||
shotgun.append(spectacle)
|
||||
|
||||
if request.method == 'POST':
|
||||
|
@ -440,16 +437,13 @@ def buy_revente(request, spectacle_id):
|
|||
revente.delete()
|
||||
return HttpResponseRedirect(reverse("bda-liste-revente",
|
||||
args=[tirage.id]))
|
||||
reventes_shotgun = []
|
||||
for revente in reventes.all():
|
||||
if revente.shotgun:
|
||||
reventes_shotgun.append(revente)
|
||||
reventes_shotgun = reventes.filter(shotgun=True)
|
||||
|
||||
if not reventes_shotgun:
|
||||
if not reventes_shotgun.exists():
|
||||
return render(request, "bda-no-revente.html", {})
|
||||
|
||||
if request.POST:
|
||||
revente = random.choice(reventes_shotgun)
|
||||
revente = random.choice(reventes_shotgun.all())
|
||||
revente.soldTo = participant
|
||||
revente.save()
|
||||
mail = """Bonjour !
|
||||
|
|
Loading…
Reference in a new issue