Exemplo n.º 1
0
def send_notifications(app, item_name, **kwargs):
    """ Send mail notifications to subscribers on item change

    :param app: local proxy app
    :param item_name: name of the changed item
    :param kwargs: key/value pairs that contain extra information about the item
                   required in order to create a notification
    """
    action = kwargs.get('action')
    revs = get_item_last_revisions(app, item_name) if action not in [
        DESTROY_REV, DESTROY_ALL, ] else []
    notification = Notification(app, item_name, revs, **kwargs)
    content_diff = notification.get_content_diff()
    meta_diff = notification.get_meta_diff()

    u = flaskg.user
    meta = kwargs.get('meta') if action in [DESTROY_REV, DESTROY_ALL, ] else revs[0].meta._meta
    subscribers = {subscriber for subscriber in get_subscribers(**meta) if
                   subscriber.itemid != u.itemid}
    subscribers_locale = {subscriber.locale for subscriber in subscribers}
    for locale in subscribers_locale:
        with force_locale(locale):
            txt_msg, html_msg = notification.render_templates(content_diff, meta_diff)
            subject = L_('[%(moin_name)s] Update of "%(item_name)s" by %(user_name)s',
                         moin_name=app.cfg.interwikiname, item_name=item_name, user_name=u.name0)
            subscribers_emails = [subscriber.email for subscriber in subscribers
                                  if subscriber.locale == locale]
            sendmail(subject, txt_msg, to=subscribers_emails, html=html_msg)
Exemplo n.º 2
0
def send_notifications(app, fqname, **kwargs):
    """ Send mail notifications to subscribers on item change

    :param app: local proxy app
    :param fqname: fqname of the changed item
    :param kwargs: key/value pairs that contain extra information about the item
                   required in order to create a notification
    """
    action = kwargs.get('action')
    revs = get_item_last_revisions(app, fqname) if action not in [
        DESTROY_REV, DESTROY_ALL, ] else []
    notification = Notification(app, fqname, revs, **kwargs)
    try:
        content_diff = notification.get_content_diff()
    except Exception:
        # current user has likely corrupted an item or fixed a corrupted item
        # if current item is corrupt, another exception will occur in a downstream script
        content_diff = [u'- ' + _('An error has occurred, the current or prior revision of this item may be corrupt.')]
    meta_diff = notification.get_meta_diff()

    u = flaskg.user
    meta = kwargs.get('meta') if action in [DESTROY_REV, DESTROY_ALL, ] else revs[0].meta._meta
    subscribers = {subscriber for subscriber in get_subscribers(**meta) if
                   subscriber.itemid != u.itemid}
    subscribers_locale = {subscriber.locale for subscriber in subscribers}
    for locale in subscribers_locale:
        with force_locale(locale):
            txt_msg, html_msg = notification.render_templates(content_diff, meta_diff)
            subject = L_('[%(moin_name)s] Update of "%(fqname)s" by %(user_name)s',
                         moin_name=app.cfg.interwikiname, fqname=unicode(fqname), user_name=u.name0)
            subscribers_emails = [subscriber.email for subscriber in subscribers
                                  if subscriber.locale == locale]
            sendmail(subject, txt_msg, to=subscribers_emails, html=html_msg)
Exemplo n.º 3
0
def test_force_locale():
    pytest.skip("This test needs to be run with --assert=reinterp or --assert=plain flag")
    app = Flask(__name__)
    b = babel.Babel(app)

    @b.localeselector
    def select_locale():
        return 'de_DE'

    with app.test_request_context():
        assert str(babel.get_locale()) == 'de_DE'
        with force_locale('en_US'):
            assert str(babel.get_locale()) == 'en_US'
        assert str(babel.get_locale()) == 'de_DE'
Exemplo n.º 4
0
def test_force_locale():
    pytest.skip("This test needs to be run with --assert=reinterp or --assert=plain flag")
    app = Flask(__name__)
    b = babel.Babel(app)

    @b.localeselector
    def select_locale():
        return 'de_DE'

    with app.test_request_context():
        assert str(babel.get_locale()) == 'de_DE'
        with force_locale('en_US'):
            assert str(babel.get_locale()) == 'en_US'
        assert str(babel.get_locale()) == 'de_DE'
Exemplo n.º 5
0
def send_notifications(app, fqname, **kwargs):
    """ Send mail notifications to subscribers on item change

    :param app: local proxy app
    :param fqname: fqname of the changed item
    :param kwargs: key/value pairs that contain extra information about the item
                   required in order to create a notification
    """
    action = kwargs.get('action')
    revs = get_item_last_revisions(app, fqname) if action not in [
        DESTROY_REV,
        DESTROY_ALL,
    ] else []
    notification = Notification(app, fqname, revs, **kwargs)
    content_diff = notification.get_content_diff()
    meta_diff = notification.get_meta_diff()

    u = flaskg.user
    meta = kwargs.get('meta') if action in [
        DESTROY_REV,
        DESTROY_ALL,
    ] else revs[0].meta._meta
    subscribers = {
        subscriber
        for subscriber in get_subscribers(**meta)
        if subscriber.itemid != u.itemid
    }
    subscribers_locale = {subscriber.locale for subscriber in subscribers}
    for locale in subscribers_locale:
        with force_locale(locale):
            txt_msg, html_msg = notification.render_templates(
                content_diff, meta_diff)
            subject = L_(
                '[%(moin_name)s] Update of "%(fqname)s" by %(user_name)s',
                moin_name=app.cfg.interwikiname,
                fqname=unicode(fqname),
                user_name=u.name0)
            subscribers_emails = [
                subscriber.email for subscriber in subscribers
                if subscriber.locale == locale
            ]
            sendmail(subject, txt_msg, to=subscribers_emails, html=html_msg)