Changeset - 970ec9184c57
[Not reviewed]
0 4 0
Tobias - 5 years ago 2019-01-21 02:39:35
tobiasschulmann@catalyst.net.nz
Raffle draw changes
4 files changed with 13 insertions and 8 deletions:
0 comments (0 inline, 0 general)
pinaxcon/raffle/mixins.py
Show inline comments
...
 
@@ -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)
pinaxcon/raffle/models.py
Show inline comments
 
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
pinaxcon/raffle/signals.py
Show inline comments
...
 
@@ -69,8 +69,9 @@ 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."""
 
    raise IntegrityError("Deleting a drawn ticket is not allowed.")
 
    """Protects :model:`pinaxcon_raffle.DrawnTicket` from deletion if lock is in place."""
 
    if instance.locked:
 
        raise IntegrityError("Deleting a drawn ticket is not allowed.")
 

	
 

	
 
@receiver(pre_save, sender=DrawnTicket)
pinaxcon/templates/raffle_draw.html
Show inline comments
...
 
@@ -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 %}
0 comments (0 inline, 0 general)