示例#1
0
文件: view.py 项目: LapwingOrg/cupola
def send_email_notifications(event_id):
    """
    Send email notifications of events.

    :param event_id: event ID
    :type event_id: int
    """
    from cupola.api.run import create_api
    from cupola.web import create_app

    with create_api().app_context() as ctx:
        if not event_id:
            ctx.app.logger.warning("No event ID")
            return

        event = Event.query.get(event_id)

        if not event:
            ctx.app.logger.warning("No event with ID {}".format(event_id))
            return

        group = EventGroup.query.filter_by(message=event.message).first()

        subject = "Event registered for project {}".format(group.project.name)

        # We use `create_app` here so the event URLs are calculated properly
        # FIXME: There has to be a nicer way to do this.
        with create_app().app_context():
            event_url = url_for("events.view_event", event_id=event.event_id,
                                _external=True)

        if group.project.email_notifications:
            with mail.connect() as conn:
                for user in group.project.email_notifications:
                    msg = Message(subject, recipients=[user.email])

                    msg.body = render_template("api/event.txt", user=user,
                                               group=group,
                                               event_url=event_url)
                    msg.html = render_template("api/event.html", user=user,
                                               group=group,
                                               event_url=event_url)

                    conn.send(msg)
示例#2
0
文件: wsgi.py 项目: LapwingOrg/cupola
# coding=utf8
#
# wsgi.py: cupola application web frontend setup for WSGI servers
# Copyright (C) 2015-2016 Sam Black <*****@*****.**>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from cupola.web import create_app

app = create_app()