<commit_before>from django.core.mail import EmailMessage

from plata.shop import signals


class BaseHandler(object):
    @classmethod
    def register(cls, **kwargs):
        instance = cls(**kwargs)

        dispatch_uid = kwargs.get('dispatch_uid', cls.__name__)

        signals.contact_created.connect(instance.on_contact_created,
            dispatch_uid=dispatch_uid)
        signals.order_confirmed.connect(instance.on_order_confirmed,
            dispatch_uid=dispatch_uid)
        signals.order_completed.connect(instance.on_order_completed,
            dispatch_uid=dispatch_uid)

        return instance

    def on_contact_created(self, sender, **kwargs): pass
    def on_order_confirmed(self, sender, **kwargs): pass
    def on_order_completed(self, sender, **kwargs): pass


class ConsoleHandler(BaseHandler):
    def __init__(self, stream):
        self.stream = stream

    def on_contact_created(self, sender, **kwargs):
        print >>self.stream, 'Contact created: %s' % kwargs.get('contact')

    def on_order_confirmed(self, sender, **kwargs):
        print >>self.stream, 'Order confirmed: %s' % kwargs.get('order')

    def on_order_completed(self, sender, **kwargs):
        print >>self.stream, 'Order completed: %s, payment %s, new discount %s' % (
            kwargs.get('order'),
            kwargs.get('payment'),
            kwargs.get('remaining_discount'))


class EmailHandler(BaseHandler):
    def on_contact_created(self, sender, **kwargs):
        contact = kwargs.get('contact')
        if not contact:
            return

        message = EmailMessage(
            subject='Account created',
            body='Your account has been created.',
            to=[contact.user.email],
            )
        message.send()

    def on_order_completed(self, sender, **kwargs):
        order = kwargs.get('order')
        if not order:
            return

        message = EmailMessage(
            subject='Order completed',
            body='Your order has been successfully paid.',<commit_msg>These arguments must be provided<commit_after>from django.core.mail import EmailMessage

from plata.shop import signals


class BaseHandler(object):
    @classmethod
    def register(cls, **kwargs):
        instance = cls(**kwargs)

        dispatch_uid = kwargs.get('dispatch_uid', cls.__name__)

        signals.contact_created.connect(instance.on_contact_created,
            dispatch_uid=dispatch_uid)
        signals.order_confirmed.connect(instance.on_order_confirmed,
            dispatch_uid=dispatch_uid)
        signals.order_completed.connect(instance.on_order_completed,
            dispatch_uid=dispatch_uid)

        return instance

    def on_contact_created(self, sender, **kwargs): pass
    def on_order_confirmed(self, sender, **kwargs): pass
    def on_order_completed(self, sender, **kwargs): pass


class ConsoleHandler(BaseHandler):
    def __init__(self, stream):
        self.stream = stream

    def on_contact_created(self, sender, **kwargs):
        print >>self.stream, 'Contact created: %s' % kwargs.get('contact')

    def on_order_confirmed(self, sender, **kwargs):
        print >>self.stream, 'Order confirmed: %s' % kwargs.get('order')

    def on_order_completed(self, sender, **kwargs):
        print >>self.stream, 'Order completed: %s, payment %s, new discount %s' % (
            kwargs.get('order'),
            kwargs.get('payment'),
            kwargs.get('remaining_discount'))


class EmailHandler(BaseHandler):
    def on_contact_created(self, sender, **kwargs):
        contact = kwargs['contact']

        message = EmailMessage(
            subject='Account created',
            body='Your account has been created.',
            to=[contact.user.email],
            )
        message.send()

    def on_order_completed(self, sender, **kwargs):
        order = kwargs['order']

        message = EmailMessage(
            subject='Order completed',
            body='Your order has been successfully paid.',
{'fraction_non_alphanumeric': 0.11136192626034612, 'fraction_numerical': 0.0, 'mean_word_length': 2.890731707317073, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4130029', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1068, 'n_words': 253}