Changeset - 908dca311ce9
[Not reviewed]
0 2 0
Tobias - 6 years ago 2019-01-21 03:44:51
tobiasschulmann@catalyst.net.nz
Revert mixin changes
2 files changed with 5 insertions and 7 deletions:
0 comments (0 inline, 0 general)
pinaxcon/raffle/mixins.py
Show inline comments
...
 
@@ -33,23 +33,21 @@ class RaffleMixin:
 
            filters['invoice__user'] = user
 

	
 
        for item in LineItem.objects.filter(**filters).values('id', 'quantity'):
 
            yield (item['id'], list(create_ticket_numbers(item)))
 

	
 

	
 
class LockMixin():
 
class PrizeMixin:
 
    @property
 
    def locked(self):
 
        return self._locked
 

	
 
    def unlock(self, user):
 
        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)
 
        self.winning_ticket = None
 
        self.save(update_fields=('winning_ticket',))
 

	
pinaxcon/raffle/models.py
Show inline comments
 
from django.db import models
 

	
 
from pinaxcon.raffle.mixins import PrizeMixin, RaffleMixin, LockMixin
 
from pinaxcon.raffle.mixins import PrizeMixin, RaffleMixin
 

	
 

	
 
class Raffle(RaffleMixin, models.Model):
 
    """
 
    Stores a single Raffle object, related to one or many
 
    :model:`pinaxcon_registrasion.Product`, which  is usually a raffle ticket,
...
 
@@ -13,13 +13,13 @@ class Raffle(RaffleMixin, models.Model):
 
    products = models.ManyToManyField('registrasion.Product')
 

	
 
    def __str__(self):
 
        return self.description
 

	
 

	
 
class Prize(PrizeMixin, LockMixin, models.Model):
 
class Prize(PrizeMixin, models.Model):
 
    """
 
    Stores a Prize for a given :model:`pinaxcon_raffle.Raffle`.
 

	
 
    Once `winning_ticket` has been set to a :model:`pinaxcon_raffle.DrawnTicket`
 
    object, no further changes are permitted unless the object is explicitely
 
    unlocked.
...
 
@@ -53,26 +53,26 @@ class PrizeAudit(models.Model):
 
        ordering = ('-timestamp',)
 

	
 
    def __str__(self):
 
        return self.reason
 

	
 

	
 
class Draw(LockMixin, models.Model):
 
class Draw(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.
 
    """
 
    raffle = models.ForeignKey('pinaxcon_raffle.Raffle', related_name='draws')
 
    drawn_by = models.ForeignKey('auth.User')
 
    drawn_time = models.DateTimeField(auto_now_add=True)
 

	
 
    def __str__(self):
 
        return f"{self.raffle}: {self.drawn_time}"
 

	
 

	
 
class DrawnTicket(LockMixin, models.Model):
 
class DrawnTicket(models.Model):
 
    """
 
    Stores the result of a ticket draw, along with the corresponding
 
    :model:`pinaxcon_raffle.Draw`, :model:`pinaxcon_raffle.Prize` and the
 
    :model:`registrasion.commerce.LineItem` from which it was generated.
 
    """
 
    ticket = models.CharField(max_length=255)
0 comments (0 inline, 0 general)