예제 #1
0
파일: email.py 프로젝트: isaleem/cumin
def send_comment_notification(media_obj, comment):
    """
    Helper method to send a email notification that a comment has been posted.

    Sends to the address configured in the 'email_comment_posted' setting,
    if it is configured.

    :param media_obj: The media object to send a notification about.
    :type media_obj: :class:`~mediacore.model.media.Media` instance

    :param comment: The newly posted comment.
    :type comment: :class:`~mediacore.model.comments.Comment` instance
    """
    send_to = request.settings['email_comment_posted']
    if not send_to:
        # Comment notification emails are disabled!
        return

    author_name = media_obj.author.name
    comment_subject = comment.subject
    post_url = url_for_media(media_obj, qualified=True)
    comment_body = strip_xhtml(line_break_xhtml(line_break_xhtml(comment.body)))
    subject = _('New Comment: %(comment_subject)s') % locals()
    body = _("""A new comment has been posted!

Author: %(author_name)s
Post: %(post_url)s

Body: %(comment_body)s
""") % locals()

    send(send_to, request.settings['email_send_from'], subject, body)
예제 #2
0
def send_media_notification(media_obj):
    send_to = fetch_setting("email_media_uploaded")
    if not send_to:
        # media notification emails are disabled!
        return

    edit_url = (url_for(controller="mediaadmin", action="edit", id=media_obj.id, qualified=True),)

    clean_description = strip_xhtml(line_break_xhtml(line_break_xhtml(media_obj.description)))

    subject = "New %s: %s" % (media_obj.type, media_obj.title)
    body = """A new %s file has been uploaded!

Title: %s

Author: %s (%s)

Admin URL: %s

Description: %s
""" % (
        media_obj.type,
        media_obj.title,
        media_obj.author.name,
        media_obj.author.email,
        edit_url,
        clean_description,
    )

    send(send_to, fetch_setting("email_send_from"), subject, body)
예제 #3
0
def send_media_notification(media_obj):
    send_to = app_globals.settings['email_media_uploaded']
    if not send_to:
        # media notification emails are disabled!
        return

    edit_url = url_for(controller='/admin/media', action='edit',
                       id=media_obj.id, qualified=True),

    clean_description = strip_xhtml(line_break_xhtml(line_break_xhtml(media_obj.description)))

    type = media_obj.type
    title = media_obj.title
    author_name = media_obj.author.name
    author_email = media_obj.author.email
    subject = _('New %(type)s: %(title)s') % locals()
    body = _("""A new %(type)s file has been uploaded!

Title: %(title)s

Author: %(author_name)s (%(author_email)s)

Admin URL: %(edit_url)s

Description: %(clean_description)s
""") % locals()

    send(send_to, app_globals.settings['email_send_from'], subject, body)
예제 #4
0
def send_media_notification(media_obj):
    send_to = app_globals.settings['email_media_uploaded']
    if not send_to:
        # media notification emails are disabled!
        return

    edit_url = url_for(controller='/admin/media', action='edit',
                       id=media_obj.id, qualified=True),

    clean_description = strip_xhtml(
            line_break_xhtml(line_break_xhtml(media_obj.description)))

    subject = 'New %s: %s' % (media_obj.type, media_obj.title)
    body = """A new %s file has been uploaded!

Title: %s

Author: %s (%s)

Admin URL: %s

Description: %s
""" % (media_obj.type, media_obj.title, media_obj.author.name,
       media_obj.author.email, edit_url, clean_description)

    send(send_to, app_globals.settings['email_send_from'], subject, body)
def generate_plain_descriptions(conn):
    values = []
    query = select([media.c.id, media.c.description, media.c.publish_on, media.c.likes])
    for media_id, desc, publish_on, likes in conn.execute(query):
        plain_desc = line_break_xhtml(desc)
        plain_desc = line_break_xhtml(plain_desc)
        plain_desc = strip_xhtml(plain_desc, True)
        popularity = calculate_popularity(publish_on, likes)
        values.append({
            'media_id': media_id,
            'desc': plain_desc,
            'popularity': popularity,
        })
    if values:
        query = media.update().where(media.c.id==bindparam('media_id'))\
                              .values(description_plain=bindparam('desc'),
                                      popularity_points=bindparam('popularity'))
        conn.execute(query, *values)
예제 #6
0
def send_comment_notification(media, comment):
    send_to = app_globals.settings['email_comment_posted']
    if not send_to:
        # Comment notification emails are disabled!
        return

    subject = 'New Comment: %s' % comment.subject
    body = """A new comment has been posted!

Author: %s
Post: %s

Body: %s
""" % (comment.author.name,
    url_for(controller='/media', action='view', slug=media.slug, qualified=True),
    strip_xhtml(line_break_xhtml(line_break_xhtml(comment.body))))

    send(send_to, app_globals.settings['email_send_from'], subject, body)
def generate_plain_descriptions(conn):
    values = []
    query = select([media.c.id, media.c.description, media.c.publish_on, media.c.likes])
    for media_id, desc, publish_on, likes in conn.execute(query):
        plain_desc = line_break_xhtml(desc)
        plain_desc = line_break_xhtml(plain_desc)
        plain_desc = strip_xhtml(plain_desc, True)
        popularity = calculate_popularity(publish_on, likes)
        values.append({
            'media_id': media_id,
            'desc': plain_desc,
            'popularity': popularity,
        })
    if values:
        query = media.update().where(media.c.id==bindparam('media_id'))\
                              .values(description_plain=bindparam('desc'),
                                      popularity_points=bindparam('popularity'))
        conn.execute(query, *values)
예제 #8
0
def send_comment_notification(media, comment):
    send_to = fetch_setting("email_comment_posted")
    if not send_to:
        # Comment notification emails are disabled!
        return

    subject = "New Comment: %s" % comment.subject
    body = """A new comment has been posted!

Author: %s
Post: %s

Body: %s
""" % (
        comment.author.name,
        url_for(controller="media", action="view", slug=media.slug, qualified=True),
        strip_xhtml(line_break_xhtml(line_break_xhtml(comment.body))),
    )

    send(send_to, fetch_setting("email_send_from"), subject, body)
예제 #9
0
def send_comment_notification(media_obj, comment):
    send_to = app_globals.settings['email_comment_posted']
    if not send_to:
        # Comment notification emails are disabled!
        return

    author_name = media_obj.author.name
    comment_subject = comment.subject
    post_url = url_for(controller='/media', action='view', slug=media_obj.slug, qualified=True),
    comment_body = strip_xhtml(line_break_xhtml(line_break_xhtml(comment.body)))
    subject = _('New Comment: %(comment_subject)s') % locals()
    body = _("""A new comment has been posted!

Author: %(author_name)s
Post: %(post_url)s

Body: %(comment_body)s
""") % locals()

    send(send_to, app_globals.settings['email_send_from'], subject, body)
예제 #10
0
def send_media_notification(media_obj):
    """
    Send a creation notification email that a new Media object has been
    created.

    Sends to the address configured in the 'email_media_uploaded' address,
    if one has been created.

    :param media_obj: The media object to send a notification about.
    :type media_obj: :class:`~mediacore.model.media.Media` instance
    """
    send_to = request.settings['email_media_uploaded']
    if not send_to:
        # media notification emails are disabled!
        return

    edit_url = url_for(controller='/admin/media',
                       action='edit',
                       id=media_obj.id,
                       qualified=True)

    clean_description = strip_xhtml(
        line_break_xhtml(line_break_xhtml(media_obj.description)))

    type = media_obj.type
    title = media_obj.title
    author_name = media_obj.author.name
    author_email = media_obj.author.email
    subject = _('New %(type)s: %(title)s') % locals()
    body = _("""A new %(type)s file has been uploaded!

Title: %(title)s

Author: %(author_name)s (%(author_email)s)

Admin URL: %(edit_url)s

Description: %(clean_description)s
""") % locals()

    send(send_to, request.settings['email_send_from'], subject, body)
예제 #11
0
def send_media_notification(media_obj):
    """
    Send a creation notification email that a new Media object has been
    created.

    Sends to the address configured in the 'email_media_uploaded' address,
    if one has been created.

    :param media_obj: The media object to send a notification about.
    :type media_obj: :class:`~mediacore.model.media.Media` instance
    """
    send_to = request.settings['email_media_uploaded']
    if not send_to:
        # media notification emails are disabled!
        return

    edit_url = url_for(controller='/admin/media', action='edit',
                       id=media_obj.id, qualified=True)

    clean_description = strip_xhtml(line_break_xhtml(line_break_xhtml(media_obj.description)))

    type = media_obj.type
    title = media_obj.title
    author_name = media_obj.author.name
    author_email = media_obj.author.email
    subject = _('New %(type)s: %(title)s') % locals()
    body = _("""A new %(type)s file has been uploaded!

Title: %(title)s

Author: %(author_name)s (%(author_email)s)

Admin URL: %(edit_url)s

Description: %(clean_description)s
""") % locals()

    send(send_to, request.settings['email_send_from'], subject, body)
예제 #12
0
    def _jsonify(self, media):
        im_path = '/images/media/%d%%s.jpg' % media.id

        if media.podcast_id:
            media_url = url_for(controller='/media', action='view', slug=media.slug,
                                podcast_slug=media.podcast.slug)
        else:
            media_url = url_for(controller="/media", action="view", slug=media.slug)

        return dict(
            title = media.title,
            description = media.description,
            description_plain = helpers.strip_xhtml(helpers.line_break_xhtml(\
                helpers.line_break_xhtml(media.description))),
            img_l = url_for(im_path % 'l'),
            img_m = url_for(im_path % 'm'),
            img_s = url_for(im_path % 's'),
            img_ss = url_for(im_path % 'ss'),
            id = media.id,
            slug = media.slug,
            url = media_url,
            podcast = media.podcast and media.podcast.slug or None,
        )
예제 #13
0
 def _validate_description_plain(self, key, value):
     return helpers.strip_xhtml(value, True)
import os
import urllib2
import urllib
import transaction
import time
import sys

from mediacore.model import *
from sqlalchemy import create_engine, select
from sqlalchemy.orm import eagerload, undefer
from paste.deploy import appconfig
from pylons import config
from mediacore.config.environment import load_environment

conf = appconfig('config:development.ini', relative_to='../..')
load_environment(conf.global_conf, conf.local_conf)

from mediacore.lib.helpers import strip_xhtml, line_break_xhtml

def commit_session():
    DBSession.flush()
    transaction.commit()

for m in DBSession.query(Media):
    m.description_plain = strip_xhtml(line_break_xhtml(line_break_xhtml(m.description)), True)
    DBSession.add(m)

commit_session()
예제 #15
0
conf = appconfig('config:deployment.ini', relative_to='../../..')
load_environment(conf.global_conf, conf.local_conf)

from mediacore.lib import helpers
from mediacore.model import *
from mediacore.model.meta import DBSession

def commit_session():
    DBSession.flush()
    transaction.commit()

for m in DBSession.query(Media):
    p = helpers.line_break_xhtml(m.description)
    p = helpers.line_break_xhtml(p)
    p = helpers.strip_xhtml(p, True)
    m.description_plain = p
    DBSession.add(m)

for m in DBSession.query(Media):
    m.update_popularity()
    DBSession.add(m)

type_map = {
    'mp3': 'audio',
    'm4a': 'audio',
    'flac': 'audio',
}
embeddable_types = ['youtube', 'vimeo', 'google']

for f in DBSession.query(MediaFile):