Raffle draw changes
This commit is contained in:
parent
33179794ee
commit
970ec9184c
4 changed files with 13 additions and 8 deletions
|
@ -36,7 +36,7 @@ class RaffleMixin:
|
||||||
yield (item['id'], list(create_ticket_numbers(item)))
|
yield (item['id'], list(create_ticket_numbers(item)))
|
||||||
|
|
||||||
|
|
||||||
class PrizeMixin:
|
class LockMixin():
|
||||||
@property
|
@property
|
||||||
def locked(self):
|
def locked(self):
|
||||||
return self._locked
|
return self._locked
|
||||||
|
@ -45,6 +45,8 @@ class PrizeMixin:
|
||||||
self.audit_events.create(user=user, reason="Unlocked")
|
self.audit_events.create(user=user, reason="Unlocked")
|
||||||
self._locked = False
|
self._locked = False
|
||||||
|
|
||||||
|
|
||||||
|
class PrizeMixin:
|
||||||
def remove_winner(self, user):
|
def remove_winner(self, user):
|
||||||
reason = "Removed winning ticket: {}".format(self.winning_ticket.id)
|
reason = "Removed winning ticket: {}".format(self.winning_ticket.id)
|
||||||
self.audit_events.create(user=user, reason=reason)
|
self.audit_events.create(user=user, reason=reason)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from pinaxcon.raffle.mixins import PrizeMixin, RaffleMixin
|
from pinaxcon.raffle.mixins import PrizeMixin, RaffleMixin, LockMixin
|
||||||
|
|
||||||
|
|
||||||
class Raffle(RaffleMixin, models.Model):
|
class Raffle(RaffleMixin, models.Model):
|
||||||
|
@ -16,7 +16,7 @@ class Raffle(RaffleMixin, models.Model):
|
||||||
return self.description
|
return self.description
|
||||||
|
|
||||||
|
|
||||||
class Prize(PrizeMixin, models.Model):
|
class Prize(PrizeMixin, LockMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
Stores a Prize for a given :model:`pinaxcon_raffle.Raffle`.
|
Stores a Prize for a given :model:`pinaxcon_raffle.Raffle`.
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class PrizeAudit(models.Model):
|
||||||
return self.reason
|
return self.reason
|
||||||
|
|
||||||
|
|
||||||
class Draw(models.Model):
|
class Draw(LockMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
Stores a draw for a given :model:`pinaxcon_raffle.Raffle`, along with audit fields
|
Stores a draw for a given :model:`pinaxcon_raffle.Raffle`, along with audit fields
|
||||||
for the creating :model:`auth.User` and the creation timestamp.
|
for the creating :model:`auth.User` and the creation timestamp.
|
||||||
|
@ -69,7 +69,7 @@ class Draw(models.Model):
|
||||||
return f"{self.raffle}: {self.drawn_time}"
|
return f"{self.raffle}: {self.drawn_time}"
|
||||||
|
|
||||||
|
|
||||||
class DrawnTicket(models.Model):
|
class DrawnTicket(LockMixin, models.Model):
|
||||||
"""
|
"""
|
||||||
Stores the result of a ticket draw, along with the corresponding
|
Stores the result of a ticket draw, along with the corresponding
|
||||||
:model:`pinaxcon_raffle.Draw`, :model:`pinaxcon_raffle.Prize` and the
|
:model:`pinaxcon_raffle.Draw`, :model:`pinaxcon_raffle.Prize` and the
|
||||||
|
|
|
@ -69,8 +69,9 @@ def prevent_locked_prize_deletion(sender, instance, **kwargs):
|
||||||
|
|
||||||
@receiver(pre_delete, sender=DrawnTicket)
|
@receiver(pre_delete, sender=DrawnTicket)
|
||||||
def prevent_drawn_ticket_deletion(sender, instance, **kwargs):
|
def prevent_drawn_ticket_deletion(sender, instance, **kwargs):
|
||||||
"""Protects :model:`pinaxcon_raffle.DrawnTicket` from deletion."""
|
"""Protects :model:`pinaxcon_raffle.DrawnTicket` from deletion if lock is in place."""
|
||||||
raise IntegrityError("Deleting a drawn ticket is not allowed.")
|
if instance.locked:
|
||||||
|
raise IntegrityError("Deleting a drawn ticket is not allowed.")
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_save, sender=DrawnTicket)
|
@receiver(pre_save, sender=DrawnTicket)
|
||||||
|
|
|
@ -18,9 +18,11 @@
|
||||||
{% if prize.winning_ticket %}
|
{% if prize.winning_ticket %}
|
||||||
{% with prize.winning_ticket as winner %}
|
{% with prize.winning_ticket as winner %}
|
||||||
{# this should be attendee name #}
|
{# this should be attendee name #}
|
||||||
<p><strong>Winning ticket {{ winner.ticket }}, {{ winner.lineitem.invoice.user }}</strong><br />
|
{% with winner.lineitem.invoice.user.attendee.attendeeprofilebase as profile %}
|
||||||
|
<p><strong>Winning ticket {{ winner.ticket }}, {{ profile.attendee_name }}</strong><br />
|
||||||
Drawn by {{ winner.draw.drawn_by }}, {{ winner.draw.drawn_time}}
|
Drawn by {{ winner.draw.drawn_by }}, {{ winner.draw.drawn_time}}
|
||||||
</p>
|
</p>
|
||||||
|
{% endwith %}
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
<form method="POST" action="{% url 'raffle-redraw' winner.id %}">
|
<form method="POST" action="{% url 'raffle-redraw' winner.id %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
|
|
Loading…
Reference in a new issue