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
|
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
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 _ |
20 | 17 | from mediagoblin import mg_globals |
21 | 18 | from mediagoblin.db.base import Session |
22 | 19 | from mediagoblin.db.models import (CollectionItem, MediaReport, CommentReport, |
23 | | MediaComment, MediaEntry) |
24 | | from mediagoblin.user_pages import forms as user_forms |
| 20 | MediaComment, MediaEntry) |
| 21 | from mediagoblin.tools.mail import send_email |
| 22 | from mediagoblin.tools.pluginapi import hook_runall |
| 23 | from mediagoblin.tools.template import render_template |
| 24 | from mediagoblin.tools.translate import pass_to_ugettext as _ |
25 | 25 | |
26 | 26 | |
27 | 27 | def send_comment_email(user, comment, media, request): |
… |
… |
def send_comment_email(user, comment, media, request):
|
54 | 54 | send_email( |
55 | 55 | mg_globals.app_config['email_sender_address'], |
56 | 56 | [user.email], |
57 | | '{instance_title} - {comment_author} '.format( |
| 57 | '{instance_title} - {comment_author} {action_text}'.format( |
58 | 58 | 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')), |
61 | 61 | rendered_email) |
62 | 62 | |
63 | 63 | |
… |
… |
def add_media_to_collection(collection, media, note=None, commit=True):
|
73 | 73 | Session.add(collection) |
74 | 74 | Session.add(media) |
75 | 75 | |
| 76 | hook_runall('add_media_to_collection', |
| 77 | collection=collection, media_entry=media, note=note) |
| 78 | |
76 | 79 | if commit: |
77 | 80 | Session.commit() |
78 | 81 | |
| 82 | |
79 | 83 | def build_report_object(report_form, media_entry=None, comment=None): |
80 | 84 | """ |
81 | 85 | 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):
|
86 | 90 | :param media_entry A MediaEntry object. The MediaEntry being repo- |
87 | 91 | -rted by a MediaReport. In a CommentReport, |
88 | 92 | this will be None. |
89 | | :param comment A MediaComment object. The MediaComment being |
| 93 | :param comment A MediaComment object. The MediaComment being |
90 | 94 | reported by a CommentReport. In a MediaReport |
91 | 95 | this will be None. |
92 | 96 | |
… |
… |
def build_report_object(report_form, media_entry=None, comment=None):
|
115 | 119 | report_object.report_content = report_form.report_reason.data |
116 | 120 | report_object.reporter_id = report_form.reporter_id.data |
117 | 121 | return report_object |
118 | | |