import later, add missing bit of signal, change model reference in signal connection

This commit is contained in:
Thomas Steen Rasmussen 2018-03-04 13:19:42 +01:00
parent fe4e47edb0
commit 07b3387831
3 changed files with 11 additions and 3 deletions

View file

@ -0,0 +1,2 @@
default_app_config = 'tickets.apps.TicketsConfig'

View file

@ -10,5 +10,5 @@ class TicketsConfig(AppConfig):
def ready(self):
# connect the post_save signal, including a dispatch_uid to prevent it being called multiple times in corner cases
post_save.connect(ticket_changed, sender='models.ShopTicket', dispatch_uid='shopticket_save_signal')
post_save.connect(ticket_changed, sender='tickets.ShopTicket', dispatch_uid='shopticket_save_signal')

View file

@ -1,6 +1,4 @@
from django.conf import settings
from .models import ShopTicket
from ircbot.models import OutgoingIrcMessage
def ticket_changed(sender, instance, created, **kwargs):
"""
@ -15,6 +13,7 @@ def ticket_changed(sender, instance, created, **kwargs):
target = settings.IRCBOT_CHANNELS['orga'] if 'orga' in settings.IRCBOT_CHANNELS else settings.IRCBOT_CHANNELS['default']
# get ticket stats
from .models import ShopTicket
ticket_prefix = "BornHack {}".format(datetime.now().year)
stats = ", ".join(
@ -45,6 +44,7 @@ def ticket_changed(sender, instance, created, **kwargs):
).count()
# queue the messages
from ircbot.models import OutgoingIrcMessage
OutgoingIrcMessage.objects.create(
target=target,
message="%s sold!" % instance.product.name,
@ -54,3 +54,9 @@ def ticket_changed(sender, instance, created, **kwargs):
target=target,
message="Totals: {}, 1day: {}, 1day child: {}".format(
stats,
onedaystats,
onedaychildstats
)[:200],
timeout=timezone.now()+timedelta(minutes=10)
)