<commit_before>"""
byceps.services.shop.order.export.service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2017 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from datetime import datetime
from typing import Any, Dict

from flask import current_app

from .....util.money import to_two_places
from .....util.templating import load_template

from .. import service as order_service
from ..models.order import Order


def export_order_as_xml(order_id):
    """Export the order as an XML document."""
    order = order_service.find_order_with_details(order_id)

    if order is None:
        return None

    context = _assemble_context(order)
    xml = _render_template(context)

    return {
        'content': xml,
        'content_type': 'application/xml; charset=iso-8859-1',
    }


def _assemble_context(order: Order) -> Dict[str, Any]:
    """Assemble template context."""
    order_tuple = order.to_tuple()

    order_items = [item.to_tuple() for item in order.items]

    now = datetime.now()

    return {
        'order': order_tuple,
        'email_address': order.placed_by.email_address,
        'order_items': order_items,
        'now': now,
        'format_export_amount': _format_export_amount,
        'format_export_datetime': _format_export_datetime,
    }<commit_msg>Take order item tuples directly from order tuple as they have already been created<commit_after>"""
byceps.services.shop.order.export.service
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2017 <NAME>
:License: Modified BSD, see LICENSE for details.
"""

from datetime import datetime
from typing import Any, Dict

from flask import current_app

from .....util.money import to_two_places
from .....util.templating import load_template

from .. import service as order_service
from ..models.order import Order


def export_order_as_xml(order_id):
    """Export the order as an XML document."""
    order = order_service.find_order_with_details(order_id)

    if order is None:
        return None

    context = _assemble_context(order)
    xml = _render_template(context)

    return {
        'content': xml,
        'content_type': 'application/xml; charset=iso-8859-1',
    }


def _assemble_context(order: Order) -> Dict[str, Any]:
    """Assemble template context."""
    order_tuple = order.to_tuple()

    now = datetime.now()

    return {
        'order': order_tuple,
        'email_address': order.placed_by.email_address,
        'order_items': order_tuple.items,
        'now': now,
        'format_export_amount': _format_export_amount,
        'format_export_datetime': _format_export_datetime,
    }
{'fraction_non_alphanumeric': 0.1332323996971991, 'fraction_numerical': 0.00984102952308857, 'mean_word_length': 3.564766839378238, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '5001948', 'n_tokens_mistral': 820, 'n_tokens_neox': 769, 'n_words': 207}