<commit_before>from decimal import Decimal
from importlib import import_module

from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db.models import Sum
from django.dispatch import receiver
from django.shortcuts import render
from django.template.loader import get_template
from django.utils import formats
from django.utils.formats import date_format
from django.utils.translation import ugettext_lazy as _

from pretix.base.models import (
    Event, Item, Order, OrderPosition, Voucher, WaitingListEntry,
)
from pretix.control.signals import (
    event_dashboard_widgets, user_dashboard_widgets,
)

from ..logdisplay import OVERVIEW_BLACKLIST

SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
NUM_WIDGET = '<div class="numwidget"><span class="num">{num}</span><span class="text">{text}</span></div>'


@receiver(signal=event_dashboard_widgets)
def base_widgets(sender, **kwargs):
    prodc = Item.objects.filter(
        event=sender, active=True,
    ).count()

    tickc = OrderPosition.objects.filter(
        order__event=sender, item__admission=True,
        order__status__in=(Order.STATUS_PAID, Order.STATUS_PENDING)
    ).count()

    paidc = OrderPosition.objects.filter(
        order__event=sender, item__admission=True,
        order__status=Order.STATUS_PAID,
    ).count()

    rev = Order.objects.filter(
        event=sender,
        status=Order.STATUS_PAID
    ).aggregate(sum=Sum('total'))['sum'] or Decimal('0.00')

    return [
        {
            'content': NUM_WIDGET.format(num=tickc, text=_('Attendees (ordered)')),
            'display_size': 'small',
            'priority': 100,
            'url': reverse('control:event.orders', kwargs={
                'event': sender.slug,
                'organizer': sender.organizer.slug
            })
        },
        {
            'content': NUM_WIDGET.format(num=paidc, text=_('Attendees (paid)')),
            'display_size': 'small',
            'priority': 100,
            'url': reverse('control:event.orders.overview', kwargs={
                'event': sender.slug,
                'organizer': sender.organizer.slug
            })
        },
        {
            'content': NUM_WIDGET.format(
                num=formats.localize(rev), text=_('Total revenue ({currency})').format(currency=sender.currency)),
            'display_size': 'small',
            'priority': 100,
            'url': reverse('control:event.orders.overview', kwargs={
                'event': sender.slug,
                'organizer': sender.organizer.slug
            })
        },
        {
            'content': NUM_WIDGET.format(num=prodc, text=_('Active products')),
            'display_size': 'small',
            'priority': 100,
            'url': reverse('control:event.items', kwargs={
                'event': sender.slug,
                'organizer': sender.organizer.slug
            })
        },
    ]


@receiver(signal=event_dashboard_widgets)
def waitinglist_widgets(sender, **kwargs):
    widgets = []

    wles = WaitingListEntry.objects.filter(event=sender)
    if wles.count():
        quota_cache = {}
        itemvar_cache = {}
        happy = 0

        for wle in wles:
            if (wle.item, wle.variation) not in itemvar_cache:
                itemvar_cache[(wle.item, wle.variation)] = (
                    wle.variation.check_quotas(count_waitinglist=False, _cache=quota_cache)
                    if wle.variation
                    else wle.item.check_quotas(count_waitinglist=False, _cache=quota_cache)
                )
            row = itemvar_cache.get((wle.item, wle.variation))
            if row[1] > 0:
                itemvar_cache[(wle.item, wle.variation)] = (row[0], row[1] - 1)
                happy += 1

        widgets.append({
            'content': NUM_WIDGET.format(num=str(happy), text=_('available to give to people on waiting list')),
            'priority': 50,<commit_msg>Fix dashboard widgets to show correct waiting list numbers<commit_after>from decimal import Decimal
from importlib import import_module

from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.core.urlresolvers import reverse
from django.db.models import Sum
from django.dispatch import receiver
from django.shortcuts import render
from django.template.loader import get_template
from django.utils import formats
from django.utils.formats import date_format
from django.utils.translation import ugettext_lazy as _

from pretix.base.models import (
    Event, Item, Order, OrderPosition, Voucher, WaitingListEntry,
)
from pretix.control.signals import (
    event_dashboard_widgets, user_dashboard_widgets,
)

from ..logdisplay import OVERVIEW_BLACKLIST

SessionStore = import_module(settings.SESSION_ENGINE).SessionStore
NUM_WIDGET = '<div class="numwidget"><span class="num">{num}</span><span class="text">{text}</span></div>'


@receiver(signal=event_dashboard_widgets)
def base_widgets(sender, **kwargs):
    prodc = Item.objects.filter(
        event=sender, active=True,
    ).count()

    tickc = OrderPosition.objects.filter(
        order__event=sender, item__admission=True,
        order__status__in=(Order.STATUS_PAID, Order.STATUS_PENDING)
    ).count()

    paidc = OrderPosition.objects.filter(
        order__event=sender, item__admission=True,
        order__status=Order.STATUS_PAID,
    ).count()

    rev = Order.objects.filter(
        event=sender,
        status=Order.STATUS_PAID
    ).aggregate(sum=Sum('total'))['sum'] or Decimal('0.00')

    return [
        {
            'content': NUM_WIDGET.format(num=tickc, text=_('Attendees (ordered)')),
            'display_size': 'small',
            'priority': 100,
            'url': reverse('control:event.orders', kwargs={
                'event': sender.slug,
                'organizer': sender.organizer.slug
            })
        },
        {
            'content': NUM_WIDGET.format(num=paidc, text=_('Attendees (paid)')),
            'display_size': 'small',
            'priority': 100,
            'url': reverse('control:event.orders.overview', kwargs={
                'event': sender.slug,
                'organizer': sender.organizer.slug
            })
        },
        {
            'content': NUM_WIDGET.format(
                num=formats.localize(rev), text=_('Total revenue ({currency})').format(currency=sender.currency)),
            'display_size': 'small',
            'priority': 100,
            'url': reverse('control:event.orders.overview', kwargs={
                'event': sender.slug,
                'organizer': sender.organizer.slug
            })
        },
        {
            'content': NUM_WIDGET.format(num=prodc, text=_('Active products')),
            'display_size': 'small',
            'priority': 100,
            'url': reverse('control:event.items', kwargs={
                'event': sender.slug,
                'organizer': sender.organizer.slug
            })
        },
    ]


@receiver(signal=event_dashboard_widgets)
def waitinglist_widgets(sender, **kwargs):
    widgets = []

    wles = WaitingListEntry.objects.filter(event=sender, voucher__isnull=True)
    if wles.count():
        quota_cache = {}
        itemvar_cache = {}
        happy = 0

        for wle in wles:
            if (wle.item, wle.variation) not in itemvar_cache:
                itemvar_cache[(wle.item, wle.variation)] = (
                    wle.variation.check_quotas(count_waitinglist=False, _cache=quota_cache)
                    if wle.variation
                    else wle.item.check_quotas(count_waitinglist=False, _cache=quota_cache)
                )
            row = itemvar_cache.get((wle.item, wle.variation))
            if row[1] > 0:
                itemvar_cache[(wle.item, wle.variation)] = (row[0], row[1] - 1)
                happy += 1

        widgets.append({
            'content': NUM_WIDGET.format(num=str(happy), text=_('available to give to people on waiting list')),
            'priority': 50,
{'fraction_non_alphanumeric': 0.12155651636812848, 'fraction_numerical': 0.00592958616429895, 'mean_word_length': 2.4836488812392425, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5310388', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2361, 'n_words': 456}