Raffle draw changes

This commit is contained in:
Tobias 2019-01-21 15:39:35 +13:00
parent 33179794ee
commit 970ec9184c
4 changed files with 13 additions and 8 deletions

View file

@ -36,7 +36,7 @@ class RaffleMixin:
yield (item['id'], list(create_ticket_numbers(item)))
class PrizeMixin:
class LockMixin():
@property
def locked(self):
return self._locked
@ -45,6 +45,8 @@ class PrizeMixin:
self.audit_events.create(user=user, reason="Unlocked")
self._locked = False
class PrizeMixin:
def remove_winner(self, user):
reason = "Removed winning ticket: {}".format(self.winning_ticket.id)
self.audit_events.create(user=user, reason=reason)

View file

@ -1,6 +1,6 @@
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):
@ -16,7 +16,7 @@ class Raffle(RaffleMixin, models.Model):
return self.description
class Prize(PrizeMixin, models.Model):
class Prize(PrizeMixin, LockMixin, models.Model):
"""
Stores a Prize for a given :model:`pinaxcon_raffle.Raffle`.
@ -56,7 +56,7 @@ class PrizeAudit(models.Model):
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
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}"
class DrawnTicket(models.Model):
class DrawnTicket(LockMixin, models.Model):
"""
Stores the result of a ticket draw, along with the corresponding
:model:`pinaxcon_raffle.Draw`, :model:`pinaxcon_raffle.Prize` and the

View file

@ -69,7 +69,8 @@ def prevent_locked_prize_deletion(sender, instance, **kwargs):
@receiver(pre_delete, sender=DrawnTicket)
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."""
if instance.locked:
raise IntegrityError("Deleting a drawn ticket is not allowed.")

View file

@ -18,9 +18,11 @@
{% if prize.winning_ticket %}
{% with prize.winning_ticket as winner %}
{# 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}}
</p>
{% endwith %}
<div class="alert alert-danger">
<form method="POST" action="{% url 'raffle-redraw' winner.id %}">
{% csrf_token %}