Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
0
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)
Esempio n. 4
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)
Esempio n. 5
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)
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)
 def test_xhtmltextarea_logic(self):
     """Mimics the input -> clean -> display -> input... cycle of the XHTMLTextArea widget."""
     expected_clean = "<p>First line first line cont'd</p><p>second line</p><p>third line</p><p>fourth line</p>"
     dirty = "First line\nfirst line cont'd\n\nsecond line\n\nthird line\n\n\n\nfourth line"
     # Ensure that the cleaned XHTML is what we expected
     clean = clean_xhtml(dirty)
     assert clean == expected_clean, expected_text % (expected_clean, clean)
     # Ensure that re-cleaning the XHTML provides the same result.
     displayed = line_break_xhtml(clean)
     clean = clean_xhtml(displayed)
     assert clean == expected_clean, expected_text % (expected_clean, clean)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 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)
Esempio n. 12
0
    def display(self, value=None, **kwargs):
        if value:
            value = line_break_xhtml(value)

        # Enable the rich text editor, if dictated by the settings:
        if tiny_mce_condition():
            if 'css_classes' in kwargs:
                kwargs['css_classes'].append('tinymcearea')
            else:
                kwargs['css_classes'] = ['tinymcearea']

        return TextArea.display(self, value, **kwargs)
 def test_text_do_not_change_after_a_clean_xhtml_and_line_break_xhtml_cycle(self):
     """Mimics the input -> clean -> display -> input... cycle of the 
     XHTMLTextArea widget.
     """
     expected_html = '<p>first line</p><p>second line</p>'
     htmlified_text = clean_xhtml('first\nline\n\nsecond line')
     assert_equals(expected_html, htmlified_text)
     
     # Ensure that re-cleaning the XHTML provides the same result.
     display_text = line_break_xhtml(htmlified_text)
     assert_equals('<p>first line</p>\n<p>second line</p>', display_text)
     assert_equals(expected_html, clean_xhtml(display_text))
Esempio n. 14
0
    def test_text_do_not_change_after_a_clean_xhtml_and_line_break_xhtml_cycle(
            self):
        """Mimics the input -> clean -> display -> input... cycle of the 
        XHTMLTextArea widget.
        """
        expected_html = '<p>first line</p><p>second line</p>'
        htmlified_text = clean_xhtml('first\nline\n\nsecond line')
        assert_equals(expected_html, htmlified_text)

        # Ensure that re-cleaning the XHTML provides the same result.
        display_text = line_break_xhtml(htmlified_text)
        assert_equals('<p>first line</p>\n<p>second line</p>', display_text)
        assert_equals(expected_html, clean_xhtml(display_text))
Esempio n. 15
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)
Esempio n. 16
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,
        )
Esempio n. 17
0
 def _validate_description(self, key, value):
     self.description_plain = helpers.line_break_xhtml(
         helpers.line_break_xhtml(value)
     )
     return value
Esempio n. 18
0
from pylons import config
from urlparse import urlparse

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']
Esempio n. 19
0
 def display(self, value=None, **kwargs):
     if value:
         value = line_break_xhtml(value)
     return TextArea.display(self, value, **kwargs)
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()