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:`~mediadrop.model.media.Media` instance :param comment: The newly posted comment. :type comment: :class:`~mediadrop.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)
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:`~mediadrop.model.media.Media` instance :param comment: The newly posted comment. :type comment: :class:`~mediadrop.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)
def _file_info(self, file, media): """ Return a **file_info** dict--a JSON-ready dict for describing a media file. :rtype: JSON-ready dict :returns: The returned dict has the following fields: container (unicode) The file extension of the file's container format. type (unicode) The :attr:`file type <mediadrop.model.media.MediaFile.type>`. One of (%s) or a custom type defined in a plugin. display_name (unicode) The :attr:`display_name <mediadrop.model.media.MediaFile.display_name>` of the file. Usually the original name of the uploaded file. created (unicode) The date/time that the file was added to MediaDrop, in "YYYY-MM-DDTHH:MM:SS" (ISO 8601) format. e.g. "2011-01-04T16:23:37" url (unicode) A permalink (HTTP) to the MediaDrop view page for the media instance associated with this file. uris (list of dicts) Each dict in this list represents a URI via which the file may be accessible. These dicts have the following fields: scheme (unicode) The :attr:`scheme <mediadrop.lib.uri.StorageUri.scheme>` (e.g. 'http' in the URI 'http://mediadrop.video/docs/', 'rtmp' in the URI 'rtmp://mediadrop.video/docs/', or 'file' in the URI 'file:///some/local/file.mp4') server (unicode) The :attr:`server name <mediadrop.lib.uri.StorageUri.server_uri>` (e.g. 'mediadrop.video' in the URI 'http://mediadrop.video/docs') file (unicode) The :attr:`file path <mediadrop.lib.uri.StorageUri.file_uri>` part of the URI. (e.g. 'docs' in the URI 'http://mediadrop.video/docs') uri (unicode) The full URI string (minus scheme) built from the server_uri and file_uri. See :attr:`mediadrop.lib.uri.StorageUri.__str__`. (e.g. 'mediadrop.video/docs' in the URI 'http://mediadrop.video/docs') """ uris = [] info = dict( container = file.container, type = file.type, display_name = file.display_name, created = file.created_on.isoformat(), url = url_for_media(media, qualified=True), uris = uris, ) for uri in file.get_uris(): uris.append({ 'scheme': uri.scheme, 'uri': str(uri), 'server': uri.server_uri, 'file': uri.file_uri, }) return info
def _info(self, media, podcast_slugs=None, include_embed=False): """ Return a **media_info** dict--a JSON-ready dict for describing a media instance. :rtype: JSON-ready dict :returns: The returned dict has the following fields: author (unicode) The name of the :attr:`author <mediadrop.model.media.Media.author>` of the media instance. categories (dict of unicode) A JSON-ready dict representing the categories the media instance is in. Keys are the unique :attr:`slugs <mediadrop.model.podcasts.Podcast.slug>` for each category, values are the human-readable :attr:`title <mediadrop.model.podcasts.podcast.Title>` of that category. id (int) The numeric unique :attr:`id <mediadrop.model.media.Media.id>` of the media instance. slug (unicode) The more human readable unique identifier (:attr:`slug <mediadrop.model.media.Media.slug>`) of the media instance. url (unicode) A permalink (HTTP) to the MediaDrop view page for the media instance. embed (unicode) HTML code that can be used to embed the video in another site. title (unicode) The :attr:`title <mediadrop.model.media.Media.title>` of the media instance. type (string, one of ['%s', '%s']) The :attr:`type <mediadrop.model.media.Media.type>` of the media instance podcast (unicode or None) The :attr:`slug <mediadrop.model.podcasts.Podcast.slug>` of the :class:`podcast <mediadrop.model.podcasts.Podcast>` that the media instance has been published under, or None description (unicode) An XHTML :attr:`description <mediadrop.model.media.Media.description>` of the media instance. description_plain (unicode) A plain text :attr:`description <mediadrop.model.media.Media.description_plain>` of the media instance. comment_count (int) The number of published comments on the media instance. publish_on (unicode) The date of publishing in "YYYY-MM-DD HH:MM:SS" (ISO 8601) format. e.g. "2010-02-16 15:06:49" likes (int) The number of :attr:`like votes <mediadrop.model.media.Media.likes>` that the media instance has received. views (int) The number of :attr:`views <mediadrop.model.media.Media.views>` that the media instance has received. thumbs (dict) A dict of dicts containing URLs, width and height of different sizes of thumbnails. The default sizes are 's', 'm' and 'l'. Using medium for example:: medium_url = thumbs['m']['url'] medium_width = thumbs['m']['x'] medium_height = thumbs['m']['y'] """ if media.podcast_id: media_url = url_for(controller='/media', action='view', slug=media.slug, podcast_slug=media.podcast.slug, qualified=True) else: media_url = url_for_media(media, qualified=True) if media.podcast_id is None: podcast_slug = None elif podcast_slugs: podcast_slug = podcast_slugs[media.podcast_id] else: podcast_slug = DBSession.query(Podcast.slug)\ .filter_by(id=media.podcast_id).scalar() thumbs = {} for size in config['thumb_sizes'][media._thumb_dir].iterkeys(): thumbs[size] = thumb(media, size, qualified=True) info = dict( id = media.id, slug = media.slug, url = media_url, title = media.title, author = media.author.name, type = media.type, podcast = podcast_slug, description = media.description, description_plain = media.description_plain, comment_count = media.comment_count_published, publish_on = unicode(media.publish_on), likes = media.likes, views = media.views, thumbs = thumbs, categories = dict((c.slug, c.name) for c in list(media.categories)), ) if include_embed: info['embed'] = unicode(helpers.embed_player(media)) return info