<commit_before>from decimal import Decimal

from django import template
from django.db import models
from django.template.defaultfilters import floatformat

from fundraising.models import DjangoHero

register = template.Library()


@register.filter
def as_percentage(part, total):
    if total is None or part is None:
        return "0.00"

    try:
        return floatformat((part / total) * Decimal("100.0"))
    except ZeroDivisionError:
        return "0.00"


@register.inclusion_tag('fundraising/donation_snippet.html')
def donation_snippet():
    try:
        donation = DjangoHero.objects.filter(is_visible=True).order_by('?')[:1]
        donation = donation.annotate(donated_amount=models.Sum('donation__amount')).get()
    except DjangoHero.DoesNotExist:
        donation = None

    return {'donation': donation}<commit_msg>Added "approved" filter to fundraising sidebar query.<commit_after>from decimal import Decimal

from django import template
from django.db import models
from django.template.defaultfilters import floatformat

from fundraising.models import DjangoHero

register = template.Library()


@register.filter
def as_percentage(part, total):
    if total is None or part is None:
        return "0.00"

    try:
        return floatformat((part / total) * Decimal("100.0"))
    except ZeroDivisionError:
        return "0.00"


@register.inclusion_tag('fundraising/donation_snippet.html')
def donation_snippet():
    try:
        donation = DjangoHero.objects.filter(approved=True, is_visible=True).order_by('?')[:1]
        donation = donation.annotate(donated_amount=models.Sum('donation__amount')).get()
    except DjangoHero.DoesNotExist:
        donation = None

    return {'donation': donation}
{'fraction_non_alphanumeric': 0.10121457489878542, 'fraction_numerical': 0.012724117987275883, 'mean_word_length': 4.073313782991202, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7549683', 'n_tokens_mistral': 535, 'n_tokens_neox': 501, 'n_words': 126}