<commit_before>from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string

from osmaxx.excerptexport.models import Export
from osmaxx.utilities.shortcuts import Emissary


def tracker(request, export_id):
    export = get_object_or_404(Export, pk=export_id)
    _handle_new_status(export, request.GET['status'])

    response = HttpResponse('')
    response.status_code = 200
    return response


def _handle_new_status(export, new_status):
    if export.status != new_status:
        export.status = new_status
        _handle_changed_status(export)
        export.save()


def _handle_changed_status(export):
    emissary = Emissary(recipient=export.extraction_order.orderer)
    view_context = dict(export=export)
    message = render_to_string(
        'job_progress/messages/export_status_changed.txt',
        context=view_context,
    ).strip()
    emissary.info(message)
<commit_msg>refactoring: extract function for rendering export status changed message<commit_after>from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template.loader import render_to_string

from osmaxx.excerptexport.models import Export
from osmaxx.utilities.shortcuts import Emissary


def tracker(request, export_id):
    export = get_object_or_404(Export, pk=export_id)
    _handle_new_status(export, request.GET['status'])

    response = HttpResponse('')
    response.status_code = 200
    return response


def _handle_new_status(export, new_status):
    if export.status != new_status:
        export.status = new_status
        _handle_changed_status(export)
        export.save()


def _handle_changed_status(export):
    emissary = Emissary(recipient=export.extraction_order.orderer)
    message = _get_export_status_changed_message(export)
    emissary.info(message)


def _get_export_status_changed_message(export):
    view_context = dict(export=export)
    message = render_to_string(
        'job_progress/messages/export_status_changed.txt',
        context=view_context,
    ).strip()
    return message

{'fraction_non_alphanumeric': 0.07862523540489642, 'fraction_numerical': 0.00847457627118644, 'mean_word_length': 4.621693121693122, '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': '2334187', 'n_tokens_mistral': 670, 'n_tokens_neox': 632, 'n_words': 126}