<commit_before>#
# This email backend sends out specially formatted XML messages
# to be picked up by a Mantis plugin that adds corresponding Mantis
# issues.
#
# The idea was to provide a very low-threshold bridge to support
# both this specific frontend for end-users and the creation of
# Mantis issues from administrative scripts (e.g. cron jobs for backups.
# build servers, etc.)
#
#
# TODO: Add DTD
# TODO: Validate XML
#

#!/usr/bin/python
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.mail import send_mail

from tratten.categories.models import Category
from tratten.issues.models import Issue

def on_new_issue_send_mail(issue_id):
    # TODO mark as sent in issues model
    i = Issue.objects.get(id=issue_id)

    xml = """\
<tratten>
    <reporter_name><![CDATA[%(name)s]]></reporter_name>
    <reporter_email><![CDATA[%(email)s]]></reporter_email>
    <reporter_phone><![CDATA[%(phone)s]]></reporter_phone>
    <entity><![CDATA[%(entity)s]]></entity>
    <issue_type>Incident</issue_type>
    <urgent>%(urgent)s</urgent>
    <summary><![CDATA[%(summary)s]]></summary>
    <description><![CDATA[%(description)s]]></description>
    <reporter_due_date>%(due_date)s</reporter_due_date>
</tratten>""" % {'name': i.reporter_name,
           'email': i.reporter_email,
           'phone': i.reporter_phone,
           'entity': i.category.name,
           'urgent': "Ja" if i.urgent else "Nej",
           'summary': i.summary,
           'description': i.description,
           'due_date': i.due_date}

    send_mail(
        '[Tratten]',
        xml,
        settings.DEFAULT_FROM_EMAIL,
        [settings.EMAIL_BACKEND_SEND_NEW_ISSUES_TO],
        fail_silently=False)
<commit_msg>Optional backend email fields are removed from xml message if empty.<commit_after>#
# This email backend sends out specially formatted XML messages
# to be picked up by a Mantis plugin that adds corresponding Mantis
# issues.
#
# The idea was to provide a very low-threshold bridge to support
# both this specific frontend for end-users and the creation of
# Mantis issues from administrative scripts (e.g. cron jobs for backups.
# build servers, etc.)
#
#
# TODO: Add DTD
# TODO: Validate XML
#

#!/usr/bin/python
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.mail import send_mail
from django.template import Context, loader, Template

from tratten.categories.models import Category
from tratten.issues.models import Issue

def on_new_issue_send_mail(issue_id):
    # TODO mark as sent in issues model
    i = Issue.objects.get(id=issue_id)

    t = Template("""<tratten>
    <reporter_name><![CDATA[{{ name }}]]></reporter_name>
    <reporter_email><![CDATA[{{ email }}]]></reporter_email>{% if phone %}
    <reporter_phone><![CDATA[{{ phone }}]]></reporter_phone>{% endif %}
    <entity><![CDATA[{{ entity }}]]></entity>
    <issue_type>Incident</issue_type>
    <urgent>{{ urgent }}</urgent>
    <summary><![CDATA[{{ summary }}]]></summary>
    <description><![CDATA[{{ description }}]]></description>{% if due_date %}
    <reporter_due_date>{{ due_date }}</reporter_due_date>{% endif %}
</tratten>""")
    c = Context({'name': i.reporter_name,
                 'email': i.reporter_email,
                 'phone': i.reporter_phone,
                 'entity': i.category.name,
                 'urgent': "Ja" if i.urgent else "Nej",
                 'summary': i.summary,
                 'description': i.description,
                 'due_date': i.due_date})
    xml = t.render(c)

    send_mail(
        '[Tratten]',
        xml,
        settings.DEFAULT_FROM_EMAIL,
        [settings.EMAIL_BACKEND_SEND_NEW_ISSUES_TO],
        fail_silently=False)

{'fraction_non_alphanumeric': 0.14216347450768815, 'fraction_numerical': 0.0005395198273536552, 'mean_word_length': 3.4038004750593824, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, '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': '904989', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1164, 'n_words': 303}