<commit_before>from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext as _

from osmaxx.excerptexport.models import extraction_order, ExtractionOrderState
from osmaxx.excerptexport.services.conversion_api_client import get_authenticated_api_client
from osmaxx.utilities.shortcuts import Emissary


def tracker(request, order_id):
    order = get_object_or_404(extraction_order.ExtractionOrder, pk=order_id)
    order.progress_url = request.GET['status']
    order.save()
    client = get_authenticated_api_client()
    client.update_order_status(order)

    emissary = Emissary(recipient=order.orderer)

    if order.are_downloads_ready:
        message = _('The extraction of the order "{order_id}" has been finished.').format(order_id=order.id)

        finished_email_subject = _('Extraction Order "{order_id} finished'.format(order_id=order.id))
        finished_email_body = _(
            'The extraction order "{order_id}" has been finished and is ready for retrieval.'
        ).format(order_id=order.id)

        emissary.success(message)
        emissary.inform_mail(subject=finished_email_subject, mail_body=finished_email_body)
    elif order.state == ExtractionOrderState.FAILED:
        message = _('The extraction order "{order_id}" has failed. Please try again later.').format(
            order_id=order.id,
        )

        finished_email_subject = _('Extraction Order "{order_id} failed'.format(order_id=order.id))
        finished_email_body = _(
            'The extraction order "{order_id}" could not be completed, please try again later.'
        ).format(order_id=order.id)

        emissary.error(message)
        emissary.inform_mail(subject=finished_email_subject, mail_body=finished_email_body)
    else:
        message = _('The progress of the extraction order "{order_id}" has been updated.').format(
            order_id=order.id,
        )
        emissary.info(message)
    response = HttpResponse('')
    response.status_code = 200
    return response<commit_msg>add better user message upon progress change<commit_after>from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext as _

from osmaxx.excerptexport.models import extraction_order, ExtractionOrderState
from osmaxx.excerptexport.services.conversion_api_client import get_authenticated_api_client
from osmaxx.utilities.shortcuts import Emissary


def tracker(request, order_id):
    order = get_object_or_404(extraction_order.ExtractionOrder, pk=order_id)
    order.progress_url = request.GET['status']
    order.save()
    client = get_authenticated_api_client()
    client.update_order_status(order)

    emissary = Emissary(recipient=order.orderer)

    if order.are_downloads_ready:
        message = _('The extraction of the order "{order_id}" has been finished.').format(order_id=order.id)

        finished_email_subject = _('Extraction Order "{order_id} finished'.format(order_id=order.id))
        finished_email_body = _(
            'The extraction order "{order_id}" has been finished and is ready for retrieval.'
        ).format(order_id=order.id)

        emissary.success(message)
        emissary.inform_mail(subject=finished_email_subject, mail_body=finished_email_body)
    elif order.state == ExtractionOrderState.FAILED:
        message = _('The extraction order "{order_id}" has failed. Please try again later.').format(
            order_id=order.id,
        )

        finished_email_subject = _('Extraction Order "{order_id} failed'.format(order_id=order.id))
        finished_email_body = _(
            'The extraction order "{order_id}" could not be completed, please try again later.'
        ).format(order_id=order.id)

        emissary.error(message)
        emissary.inform_mail(subject=finished_email_subject, mail_body=finished_email_body)
    else:
        message = _("Extraction order {order} is now {order_state}.").format(
            order_id=order.id,
            order_state=str(order.state),
        )
        emissary.info(message)
    response = HttpResponse('')
    response.status_code = 200
    return response
{'fraction_non_alphanumeric': 0.09019514516896716, 'fraction_numerical': 0.004283674440742504, 'mean_word_length': 3.814432989690722, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7135187', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1204, 'n_words': 264}