コード例 #1
0
    def handle(self, *args, **options):
        start_dt = datetime.strptime(options['start_dt'], '%Y%m%d%H%M%S')
        end_dt = datetime.strptime(options['end_dt'], '%Y%m%d%H%M%S')
        contacts = Contact.objects.filter(
            creation_datetime__gte=start_dt,
            creation_datetime__lte=end_dt,
        ).select_related('mrsrequest', 'mrsrequest__insured')

        if not options.get('confirm'):
            setattr(settings, 'EMAIL_BACKEND',
                    'django.core.mail.backends.console.EmailBackend')

        for contact in contacts:
            mrsrequest = getattr(
                contact,
                'mrsrequest',
                None,
            )

            form = ContactForm(
                dict(
                    motif=contact.subject,
                    nom=contact.name,
                    email=contact.email,
                    message=contact.message,
                    caisse=getattr(contact.caisse, 'id', None),
                    mrsrequest_display_id=getattr(mrsrequest, 'display_id',
                                                  None),
                ))
            form.full_clean()
            email = EmailMessage(**form.get_email_kwargs())
            email.send()
コード例 #2
0
def test_contactform_email_kwargs_request_other(p, srf, caisse, data):
    # fixes regression #851
    data['caisse'] = 'other'
    form = ContactForm(data)
    assert form.is_valid()
    kwargs = form.get_email_kwargs()
    assert settings.TEAM_EMAIL in kwargs['to']
    obj = form.save()
    assert obj.caisse is None
コード例 #3
0
ファイル: test_contactviews.py プロジェクト: sanbox98/mrs
def test_contactform_email_kwargs_request(p, srf, caisse, data):
    form = ContactForm(data)
    assert form.is_valid()
    kwargs = form.get_email_kwargs()
    assert kwargs['subject'] == 'RÉCLAMATION MRS'
    # do not enable before product team is ready
    assert caisse.liquidation_email in kwargs['to']
    assert 'Motif: J\'ai fait une erreur' in kwargs['body']

    # test the form save method
    obj = form.save()
    assert obj.caisse == caisse
    assert obj.email == data['email']
    assert obj.name == data['nom']
    assert obj.message == data['message']
    assert obj.mrsrequest is None

    # check that it attaches the request if it exists
    mrs = MRSRequest.objects.create(display_id=data['mrsrequest_display_id'])
    assert form.save().mrsrequest == mrs
コード例 #4
0
ファイル: test_contactviews.py プロジェクト: sanbox98/mrs
def test_contactform_email_kwargs_suggestion(caisse, data, motif):
    data['motif'] = motif
    form = ContactForm(data)
    assert form.is_valid()
    kwargs = form.get_email_kwargs()
    assert caisse.liquidation_email in kwargs['to']
コード例 #5
0
def test_contactform_email_kwargs_suggestion(p, srf, caisse, data, motif):
    data['motif'] = motif
    form = ContactForm(data)
    assert form.is_valid()
    kwargs = form.get_email_kwargs()
    assert settings.TEAM_EMAIL in kwargs['to']