Esempio n. 1
0
def ticket_changed(sender, instance, created, **kwargs):
    """
    This signal is called every time a ShopTicket is saved
    """
    # only trigger an event when a new ticket is created
    if not created:
        return

    # get ticket stats
    from .models import ShopTicket

    # TODO: this is nasty, get the prefix some other way
    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
    handle_team_event(
        eventtype="ticket_created", irc_message="%s sold!" % instance.product.name
    )
    # limit this one to a length of 200 because IRC is nice
    handle_team_event(
        eventtype="ticket_created",
        irc_message="Totals: {}, 1day: {}, 1day child: {}".format(
            stats, onedaystats, onedaychildstats
        )[:200],
    )
Esempio n. 2
0
def public_credit_name_changed(instance, original):
    """
    Checks if a users public_credit_name has been changed, and triggers a public_credit_name_changed event if so
    """
    if original and original.public_credit_name == instance.public_credit_name:
        # public_credit_name has not been changed
        return

    if (original and original.public_credit_name
            and not original.public_credit_name_approved):
        # the original.public_credit_name was not approved, no need to notify again
        return

    # put the message together
    message = "User {username} changed public credit name. please review and act accordingly: https://bornhack.dk/admin/profiles/profile/{uuid}/change/".format(
        username=instance.name, uuid=instance.uuid)

    # trigger the event
    handle_team_event(eventtype="public_credit_name_changed",
                      irc_message=message)
Esempio n. 3
0
 def handle(self, *args, **options):
     camp = Camp.objects.get(slug=options["campslug"])
     output = self.format_shop_ticket_stats_for_irc(camp)
     for line in output:
         handle_team_event("ticket_stats", line)