示例#1
0
    def test_send_email_to_admins(self):
        request = testing.DummyRequest()
        mailer = get_mailer(request)

        send_email_to_admins(
            request,
            'yithlibraryserver.tests:templates/email_test',
            {
                'name': 'John',
                'email': '*****@*****.**'
            },
            'Testing message',
        )

        self.assertEqual(len(mailer.outbox), 1)
        message = mailer.outbox[0]
        self.assertEqual(message.subject, 'Testing message')
        self.assertEqual(
            message.html,
            '<p>Hello John,</p>\n\n<p>this is your email address: [email protected]</p>'
        )
        self.assertEqual(
            message.body,
            'Hello John,\n\nthis is your email address: [email protected]\n')
        self.assertEqual(message.recipients, self.admin_emails)
        self.assertEqual(message.attachments, [])
        self.assertEqual(message.extra_headers, {})
    def test_send_email_to_admins(self):
        request = testing.DummyRequest()
        mailer = get_mailer(request)

        send_email_to_admins(
            request,
            'yithlibraryserver.tests:templates/email_test',
            {'name': 'John', 'email': '*****@*****.**'},
            'Testing message',
        )

        # no email is actually send since there is no admin
        # emails configured
        self.assertEqual(len(mailer.outbox), 0)
def notify_admins_of_account_removal(request, user, reason):
    context = {"reason": reason or "no reason was given", "user": user, "home_link": request.route_url("home")}
    return send_email_to_admins(
        request,
        "yithlibraryserver.user:templates/account_removal_notification",
        context,
        "A user has destroyed his Yith Library account",
    )
示例#4
0
    def test_send_email_to_admins(self):
        request = testing.DummyRequest()
        mailer = get_mailer(request)

        send_email_to_admins(
            request,
            'yithlibraryserver.tests:templates/email_test',
            {
                'name': 'John',
                'email': '*****@*****.**'
            },
            'Testing message',
        )

        # no email is actually send since there is no admin
        # emails configured
        self.assertEqual(len(mailer.outbox), 0)
    def test_send_email_to_admins(self):
        request = testing.DummyRequest()
        mailer = get_mailer(request)

        send_email_to_admins(
            request,
            'yithlibraryserver.tests:templates/email_test',
            {'name': 'John', 'email': '*****@*****.**'},
            'Testing message',
        )

        self.assertEqual(len(mailer.outbox), 1)
        message = mailer.outbox[0]
        self.assertEqual(message.subject, 'Testing message')
        self.assertEqual(message.html, '<p>Hello John,</p>\n\n<p>this is your email address: [email protected]</p>')
        self.assertEqual(message.body, 'Hello John,\n\nthis is your email address: [email protected]\n')
        self.assertEqual(message.recipients, self.admin_emails)
        self.assertEqual(message.attachments, [])
        self.assertEqual(message.extra_headers, {})
示例#6
0
def contact(request):
    button1 = Button('submit', _('Send message'))
    button1.css_class = 'btn-primary'
    button2 = Button('cancel', _('Cancel'))
    button2.css_class = 'btn-default'

    form = Form(ContactSchema(), buttons=(button1, button2))

    if 'submit' in request.POST:
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
        except ValidationFailure as e:
            return {'form': e.render()}

        context = {'link': request.route_url('contact')}
        context.update(appstruct)
        subject = ("%s sent a message from Yith's contact form"
                   % appstruct['name'])

        result = send_email_to_admins(
            request,
            'yithlibraryserver:templates/email_contact',
            context,
            subject,
            extra_headers={'Reply-To': appstruct['email']},
        )

        if result is None:
            log.error(
                '%s <%s> tried to send a message from the contact form but no '
                'admin emails were configured. Message: %s' % (
                    appstruct['name'],
                    appstruct['email'],
                    appstruct['message'],
                )
            )

        request.session.flash(
            _('Thank you very much for sharing your opinion'),
            'info',
        )

        return HTTPFound(location=request.route_path('home'))

    elif 'cancel' in request.POST:
        return HTTPFound(location=request.route_path('home'))

    initial = {}
    if request.user is not None:
        initial['name'] = request.user.get('first_name', '')
        if request.user.get('email_verified', False):
            initial['email'] = request.user.get('email', '')

    return {'form': form.render(initial)}
def send_notification_to_admins(request, donation):
    context = {
        'home_link': request.route_url('home'),
    }
    context.update(donation)
    return send_email_to_admins(
        request,
        'yithlibraryserver.contributions:templates/email_admin_notification',
        context,
        'A new donation was received!',
    )
示例#8
0
def contact(request):
    button1 = Button('submit', _('Send message'))
    button1.css_class = 'btn-primary'
    button2 = Button('cancel', _('Cancel'))
    button2.css_class = 'btn-default'

    form = Form(ContactSchema(), buttons=(button1, button2))

    if 'submit' in request.POST:
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
        except ValidationFailure as e:
            return {'form': e.render()}

        context = {'link': request.route_url('contact')}
        context.update(appstruct)
        subject = ("%s sent a message from Yith's contact form" %
                   appstruct['name'])

        result = send_email_to_admins(
            request,
            'yithlibraryserver:templates/email_contact',
            context,
            subject,
            extra_headers={'Reply-To': appstruct['email']},
        )

        if result is None:
            log.error(
                '%s <%s> tried to send a message from the contact form but no '
                'admin emails were configured. Message: %s' % (
                    appstruct['name'],
                    appstruct['email'],
                    appstruct['message'],
                ))

        request.session.flash(
            _('Thank you very much for sharing your opinion'),
            'info',
        )

        return HTTPFound(location=request.route_path('home'))

    elif 'cancel' in request.POST:
        return HTTPFound(location=request.route_path('home'))

    initial = {}
    if request.user is not None:
        initial['name'] = request.user.first_name
        if request.user.email_verified:
            initial['email'] = request.user.email

    return {'form': form.render(initial)}
示例#9
0
def notify_admins_of_account_removal(request, user, reason):
    context = {
        'reason': reason or 'no reason was given',
        'user': user,
        'home_link': request.route_url('home'),
    }
    return send_email_to_admins(
        request,
        'yithlibraryserver.user:templates/account_removal_notification',
        context,
        'A user has destroyed his Yith Library account',
    )
示例#10
0
def notify_admins_of_account_removal(request, user, reason):
    context = {
        'reason': reason or 'no reason was given',
        'user': user,
        'home_link': request.route_url('home'),
    }
    return send_email_to_admins(
        request,
        'yithlibraryserver.user:templates/account_removal_notification',
        context,
        'A user has destroyed his Yith Library account',
    )
示例#11
0
def send_notification_to_admins(request, donation):
    context = {
        'home_link': request.route_url('home'),
    }
    context.update({
        'first_name': donation.first_name,
        'last_name': donation.last_name,
        'email': donation.email,
        'amount': donation.amount,
        'street': donation.street,
        'zipcode': donation.zipcode,
        'city': donation.city,
        'state': donation.state,
        'country': donation.country,
        'send_sticker': donation.send_sticker,
        'user': donation.user_id,
    })
    return send_email_to_admins(
        request,
        'yithlibraryserver.contributions:templates/email_admin_notification',
        context,
        'A new donation was received!',
    )