from mediagoblin.tools.template import render_template
from mediagoblin.tools.translate import pass_to_ugettext as _
from mediagoblin import mg_globals
+from mediagoblin.db.base import Session
+from mediagoblin.db.models import CollectionItem
def send_comment_email(user, comment, media, request):
instance_title=mg_globals.app_config['html_title']) \
+ _('commented on your post'),
rendered_email)
+
+
+def add_media_to_collection(collection, media, note=None, commit=True):
+ collection_item = CollectionItem()
+ collection_item.collection = collection.id
+ collection_item.media_entry = media.id
+ if note:
+ collection_item.note = note
+ Session.add(collection_item)
+
+ collection.items = collection.items + 1
+ Session.add(collection)
+
+ media.collected = media.collected + 1
+ Session.add(media)
+
+ if commit:
+ Session.commit()
from mediagoblin.tools.translate import pass_to_ugettext as _
from mediagoblin.tools.pagination import Pagination
from mediagoblin.user_pages import forms as user_forms
-from mediagoblin.user_pages.lib import send_comment_email
+from mediagoblin.user_pages.lib import (send_comment_email,
+ add_media_to_collection)
from mediagoblin.decorators import (uses_pagination, get_user_media_entry,
get_media_entry_by_id,
_('"%s" already in collection "%s"')
% (media.title, collection.title))
else: # Add item to collection
- collection_item = request.db.CollectionItem()
- collection_item.collection = collection.id
- collection_item.media_entry = media.id
- collection_item.note = form.note.data
- collection_item.save()
-
- collection.items = collection.items + 1
- collection.save()
-
- media.collected = media.collected + 1
- media.save()
+ add_media_to_collection(collection, media, form.note.data)
messages.add_message(request, messages.SUCCESS,
_('"%s" added to collection "%s"')