2018-03-04 11:04:07 +00:00
|
|
|
from django.conf import settings
|
2018-03-04 12:29:43 +00:00
|
|
|
from datetime import (
|
|
|
|
timedelta,
|
|
|
|
datetime
|
|
|
|
)
|
2018-03-04 11:04:07 +00:00
|
|
|
|
|
|
|
def ticket_changed(sender, instance, created, **kwargs):
|
|
|
|
"""
|
|
|
|
This signal is called every time a ShopTicket is saved
|
|
|
|
"""
|
|
|
|
# only queue an IRC message when a new ticket is created
|
|
|
|
if not created:
|
|
|
|
return
|
|
|
|
|
|
|
|
# queue an IRC message to the orga channel if defined,
|
|
|
|
# otherwise for the default channel
|
|
|
|
target = settings.IRCBOT_CHANNELS['orga'] if 'orga' in settings.IRCBOT_CHANNELS else settings.IRCBOT_CHANNELS['default']
|
|
|
|
|
|
|
|
# get ticket stats
|
2018-03-04 12:19:42 +00:00
|
|
|
from .models import ShopTicket
|
2018-03-04 11:04:07 +00:00
|
|
|
ticket_prefix = "BornHack {}".format(datetime.now().year)
|
|
|
|
|
|
|
|
stats = ", ".join(
|
|
|
|
[
|
|
|
|
"{}: {}".format(
|
|
|
|
tickettype['product__name'].replace(
|
|
|
|
"{} ".format(ticket_prefix),
|
|
|
|
""
|
|
|
|
),
|
|
|
|
tickettype['total']
|
|
|
|
) for tickettype in ShopTicket.objects.filter(
|
|
|
|
product__name__startswith=ticket_prefix
|
|
|
|
).exclude(
|
|
|
|
product__name__startswith="{} One Day".format(ticket_prefix)
|
|
|
|
).values(
|
|
|
|
'product__name'
|
|
|
|
).annotate(
|
|
|
|
total=Count('product__name')
|
|
|
|
).order_by('-total')
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
onedaystats = ShopTicket.objects.filter(
|
|
|
|
product__name__startswith="{} One Day Ticket".format(ticket_prefix)
|
|
|
|
).count()
|
|
|
|
onedaychildstats = ShopTicket.objects.filter(
|
|
|
|
product__name__startswith="{} One Day Children".format(ticket_prefix)
|
|
|
|
).count()
|
|
|
|
|
|
|
|
# queue the messages
|
2018-03-04 12:19:42 +00:00
|
|
|
from ircbot.models import OutgoingIrcMessage
|
2018-03-04 11:04:07 +00:00
|
|
|
OutgoingIrcMessage.objects.create(
|
|
|
|
target=target,
|
|
|
|
message="%s sold!" % instance.product.name,
|
|
|
|
timeout=timezone.now()+timedelta(minutes=10)
|
|
|
|
)
|
|
|
|
OutgoingIrcMessage.objects.create(
|
|
|
|
target=target,
|
|
|
|
message="Totals: {}, 1day: {}, 1day child: {}".format(
|
|
|
|
stats,
|
2018-03-04 12:19:42 +00:00
|
|
|
onedaystats,
|
|
|
|
onedaychildstats
|
|
|
|
)[:200],
|
|
|
|
timeout=timezone.now()+timedelta(minutes=10)
|
|
|
|
)
|
|
|
|
|