<commit_before>import datetime

from django.shortcuts import get_object_or_404, redirect, render

from refugeedata import models

from .decorators import standard_distribution_access


def home(request):
    try:
        dist = models.Distribution.objects.get(date=datetime.date.today())
    except models.Distribution.DoesNotExist:
        return redirect("public")
    return redirect("dist:info", dist.id)


@standard_distribution_access
def info(request, distribution):
    return render(request, "distribution/info.html", {
        "distribution": distribution,
    })


# FIXME standard dist access or admin-only?
@standard_distribution_access
def templates(request, distribution):
    return render(request, "distribution/templates.html", {
        "distribution": distribution,
        "email_templates": distribution.templates.filter(type="E"),
        "sms_templates": distribution.templates.filter(type="P"),
    })


# FIXME standard dist access or admin-only?
@standard_distribution_access
def template_mock_send(request, distribution, template_id):
    template = get_object_or_404(models.Template, id=template_id)
    if "to_everyone" in request.GET:
        cards = models.RegistrationNumber.objects.filter(active=True)
    else:
        cards = distribution.invitees.all()
    person_ids = cards.exclude(person=None).values_list("person", flat=True)
    preferred_contact = "phone" if template.type == "P" else "email"
    people = models.Person.objects.filter(id__in=person_ids).exclude(
        **{preferred_contact: ""})
    recipients = people.values_list(preferred_contact, flat=True)
    return render(request, "distribution/template_mock_send.html", {
        "distribution": distribution,
        "template": template,
        "recipients": recipients
    })<commit_msg>Templates are only sent to people of the correct language.<commit_after>import datetime

from django.shortcuts import get_object_or_404, redirect, render

from refugeedata import models

from .decorators import standard_distribution_access


def home(request):
    try:
        dist = models.Distribution.objects.get(date=datetime.date.today())
    except models.Distribution.DoesNotExist:
        return redirect("public")
    return redirect("dist:info", dist.id)


@standard_distribution_access
def info(request, distribution):
    return render(request, "distribution/info.html", {
        "distribution": distribution,
    })


# FIXME standard dist access or admin-only?
@standard_distribution_access
def templates(request, distribution):
    return render(request, "distribution/templates.html", {
        "distribution": distribution,
        "email_templates": distribution.templates.filter(type="E"),
        "sms_templates": distribution.templates.filter(type="P"),
    })


# FIXME standard dist access or admin-only?
@standard_distribution_access
def template_mock_send(request, distribution, template_id):
    template = get_object_or_404(models.Template, id=template_id)
    if "to_everyone" in request.GET:
        cards = models.RegistrationNumber.objects.filter(active=True)
    else:
        cards = distribution.invitees.all()
    person_ids = cards.exclude(person=None).values_list("person", flat=True)
    preferred_contact = "phone" if template.type == "P" else "email"
    people = models.Person.objects.filter(
        id__in=person_ids, preferred_lang=template.language).exclude(**{
            preferred_contact: "",
        })
    recipients = people.values_list(preferred_contact, flat=True)
    return render(request, "distribution/template_mock_send.html", {
        "distribution": distribution,
        "template": template,
        "recipients": recipients
    })
{'fraction_non_alphanumeric': 0.1080715059588299, 'fraction_numerical': 0.0032502708559046588, 'mean_word_length': 4.329004329004329, 'pattern_counts': {'":': 14, '<': 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': '6418052', 'n_tokens_mistral': 1044, 'n_tokens_neox': 997, 'n_words': 219}