<commit_before># -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2020, Shoop Commerce Ltd. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import unicode_literals

import logging
from html import unescape

from django import forms
from django.conf import settings
from django.core.mail.message import EmailMessage
from django.utils.translation import ugettext as _

from shuup.notify.base import Action, Binding
from shuup.notify.enums import ConstantUse, TemplateUse
from shuup.notify.models import EmailTemplate
from shuup.notify.signals import (
    notification_email_before_send, notification_email_sent
)
from shuup.notify.typology import Email, Language, Text


class SendEmail(Action):
    EMAIL_CONTENT_TYPE_CHOICES = (
        ('plain', _('Plain text')),
        ('html', _('HTML'))
    )

    identifier = "send_email"
    template_use = TemplateUse.MULTILINGUAL
    template_fields = {
        "subject": forms.CharField(required=True, label=_(u"Subject")),
        "email_template": forms.ChoiceField(
            choices=[(None, "-----")],
            label=_("Email Template"),
            required=False
        ),
        "body": forms.CharField(required=True, label=_("Email Body"), widget=forms.Textarea),
        "content_type": forms.ChoiceField(
            required=True, label=_(u"Content type"),
            choices=EMAIL_CONTENT_TYPE_CHOICES, initial=EMAIL_CONTENT_TYPE_CHOICES[1][0]
        )
    }
    recipient = Binding(_("Recipient"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT, required=True)
    reply_to_address = Binding(_("Reply-To"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT)
    cc = Binding(_("Carbon Copy (CC)"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT,)
    bcc = Binding(_("Blind Carbon Copy (BCC)"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT)
    from_email = Binding(
        _("From email"),
        type=Text,
        constant_use=ConstantUse.VARIABLE_OR_CONSTANT,
        required=False,
        help_text=_(
            'Override the default from email to be used. '
            'It can either be binded to a variable or be a constant like '
            '<EMAIL> or even "Store Support" <<EMAIL>>.'
        )
    )
    language = Binding(_("Language"), type=Language, constant_use=ConstantUse.VARIABLE_OR_CONSTANT, required=True)
    fallback_language = Binding(
        _("Fallback language"), type=Language, constant_use=ConstantUse.CONSTANT_ONLY,
        default=settings.PARLER_DEFAULT_LANGUAGE_CODE
    )
    send_identifier = Binding(
        _("Send Identifier"), type=Text, constant_use=ConstantUse.CONSTANT_ONLY, required=False,
        help_text=_(<commit_msg>Notify: make email action body use code editor with preview<commit_after># -*- coding: utf-8 -*-
# This file is part of Shuup.
#
# Copyright (c) 2012-2020, Shoop Commerce Ltd. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import unicode_literals

import logging
from html import unescape

from django import forms
from django.conf import settings
from django.core.mail.message import EmailMessage
from django.utils.translation import ugettext as _

from shuup.admin.forms.widgets import CodeEditorWithHTMLPreview
from shuup.notify.base import Action, Binding
from shuup.notify.enums import ConstantUse, TemplateUse
from shuup.notify.models import EmailTemplate
from shuup.notify.signals import (
    notification_email_before_send, notification_email_sent
)
from shuup.notify.typology import Email, Language, Text


class SendEmail(Action):
    EMAIL_CONTENT_TYPE_CHOICES = (
        ('html', _('HTML')),
        ('plain', _('Plain text'))
    )

    identifier = "send_email"
    template_use = TemplateUse.MULTILINGUAL
    template_fields = {
        "subject": forms.CharField(required=True, label=_(u"Subject")),
        "email_template": forms.ChoiceField(
            choices=[(None, "-----")],
            label=_("Email Template"),
            required=False
        ),
        "body": forms.CharField(required=True, label=_("Email Body"), widget=CodeEditorWithHTMLPreview),
        "content_type": forms.ChoiceField(
            required=True, label=_(u"Content type"),
            choices=EMAIL_CONTENT_TYPE_CHOICES, initial=EMAIL_CONTENT_TYPE_CHOICES[0][0]
        )
    }
    recipient = Binding(_("Recipient"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT, required=True)
    reply_to_address = Binding(_("Reply-To"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT)
    cc = Binding(_("Carbon Copy (CC)"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT,)
    bcc = Binding(_("Blind Carbon Copy (BCC)"), type=Email, constant_use=ConstantUse.VARIABLE_OR_CONSTANT)
    from_email = Binding(
        _("From email"),
        type=Text,
        constant_use=ConstantUse.VARIABLE_OR_CONSTANT,
        required=False,
        help_text=_(
            'Override the default from email to be used. '
            'It can either be binded to a variable or be a constant like '
            '<EMAIL> or even "Store Support" <<EMAIL>>.'
        )
    )
    language = Binding(_("Language"), type=Language, constant_use=ConstantUse.VARIABLE_OR_CONSTANT, required=True)
    fallback_language = Binding(
        _("Fallback language"), type=Language, constant_use=ConstantUse.CONSTANT_ONLY,
        default=settings.PARLER_DEFAULT_LANGUAGE_CODE
    )
    send_identifier = Binding(
        _("Send Identifier"), type=Text, constant_use=ConstantUse.CONSTANT_ONLY, required=False,
        help_text=_(
{'fraction_non_alphanumeric': 0.10396125237848124, 'fraction_numerical': 0.004497491783428472, 'mean_word_length': 3.739344262295082, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 9, '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': '335858', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1698, 'n_words': 418}