Ticket #950: 0001-Add-new-hook-add_media_to_collection.patch

File 0001-Add-new-hook-add_media_to_collection.patch, 3.3 KB (added by Odin Hørthe Omdal (Velmont), 10 years ago)
  • mediagoblin/user_pages/lib.py

    From d24e3bdf910af9e4a2799dcb5919e05bf46ab55e Mon Sep 17 00:00:00 2001
    From: =?UTF-8?q?Odin=20H=C3=B8rthe=20Omdal?= <odinho@opera.com>
    Date: Sun, 17 Aug 2014 22:22:00 +0200
    Subject: [PATCH 1/2] Add new hook 'add_media_to_collection'
    
    ---
     mediagoblin/user_pages/lib.py | 23 +++++++++++++----------
     1 file changed, 13 insertions(+), 10 deletions(-)
    
    diff --git a/mediagoblin/user_pages/lib.py b/mediagoblin/user_pages/lib.py
    index e5c8def..b731657 100644
    a b  
    1414# You should have received a copy of the GNU Affero General Public License
    1515# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616
    17 from mediagoblin.tools.mail import send_email
    18 from mediagoblin.tools.template import render_template
    19 from mediagoblin.tools.translate import pass_to_ugettext as _
    2017from mediagoblin import mg_globals
    2118from mediagoblin.db.base import Session
    2219from mediagoblin.db.models import (CollectionItem, MediaReport, CommentReport,
    23                                   MediaComment, MediaEntry)
    24 from mediagoblin.user_pages import forms as user_forms
     20                                   MediaComment, MediaEntry)
     21from mediagoblin.tools.mail import send_email
     22from mediagoblin.tools.pluginapi import hook_runall
     23from mediagoblin.tools.template import render_template
     24from mediagoblin.tools.translate import pass_to_ugettext as _
    2525
    2626
    2727def send_comment_email(user, comment, media, request):
    def send_comment_email(user, comment, media, request):  
    5454    send_email(
    5555        mg_globals.app_config['email_sender_address'],
    5656        [user.email],
    57         '{instance_title} - {comment_author} '.format(
     57        '{instance_title} - {comment_author} {action_text}'.format(
    5858            comment_author=comment_author,
    59             instance_title=mg_globals.app_config['html_title']) \
    60                     + _('commented on your post'),
     59            instance_title=mg_globals.app_config['html_title'],
     60            action_text=_('commented on your post')),
    6161        rendered_email)
    6262
    6363
    def add_media_to_collection(collection, media, note=None, commit=True):  
    7373    Session.add(collection)
    7474    Session.add(media)
    7575
     76    hook_runall('add_media_to_collection',
     77                collection=collection, media_entry=media, note=note)
     78
    7679    if commit:
    7780        Session.commit()
    7881
     82
    7983def build_report_object(report_form, media_entry=None, comment=None):
    8084    """
    8185    This function is used to convert a form object (from a User filing a
    def build_report_object(report_form, media_entry=None, comment=None):  
    8690    :param media_entry          A MediaEntry object. The MediaEntry being repo-
    8791                                  -rted by a MediaReport. In a CommentReport,
    8892                                  this will be None.
    89     :param comment              A MediaComment object. The MediaComment being 
     93    :param comment              A MediaComment object. The MediaComment being
    9094                                  reported by a CommentReport. In a MediaReport
    9195                                  this will be None.
    9296
    def build_report_object(report_form, media_entry=None, comment=None):  
    115119    report_object.report_content = report_form.report_reason.data
    116120    report_object.reporter_id = report_form.reporter_id.data
    117121    return report_object
    118