diff options
Diffstat (limited to 'mediagoblin/user_pages')
-rw-r--r-- | mediagoblin/user_pages/forms.py | 2 | ||||
-rw-r--r-- | mediagoblin/user_pages/routing.py | 4 | ||||
-rw-r--r-- | mediagoblin/user_pages/views.py | 48 |
3 files changed, 46 insertions, 8 deletions
diff --git a/mediagoblin/user_pages/forms.py b/mediagoblin/user_pages/forms.py index 1a09864b..77e280e1 100644 --- a/mediagoblin/user_pages/forms.py +++ b/mediagoblin/user_pages/forms.py @@ -41,7 +41,7 @@ class MediaCollectForm(wtforms.Form): note = wtforms.TextAreaField( _('Include a note'), [wtforms.validators.Optional()],) - collection_title = wtforms.TextField( + collection_title = wtforms.StringField( _('Title'), [wtforms.validators.Length(min=0, max=500)]) collection_description = wtforms.TextAreaField( diff --git a/mediagoblin/user_pages/routing.py b/mediagoblin/user_pages/routing.py index 8eb51c8d..1a1d4139 100644 --- a/mediagoblin/user_pages/routing.py +++ b/mediagoblin/user_pages/routing.py @@ -31,6 +31,10 @@ add_route('mediagoblin.user_pages.media_confirm_delete', '/u/<string:user>/m/<int:media_id>/confirm-delete/', 'mediagoblin.user_pages.views:media_confirm_delete') +add_route('mediagoblin.user_pages.activity_view', + '/<string:username>/activity/<string:id>/', + 'mediagoblin.user_pages.views:activity_view') + # Submission handling of new comments. TODO: only allow for POST methods add_route('mediagoblin.user_pages.media_post_comment', '/u/<string:user>/m/<int:media_id>/comment/add/', diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 78751a28..cc7f3684 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -18,14 +18,17 @@ import logging import datetime import json +import six + from mediagoblin import messages, mg_globals from mediagoblin.db.models import (MediaEntry, MediaTag, Collection, - CollectionItem, User) + CollectionItem, User, Activity) from mediagoblin.tools.response import render_to_response, render_404, \ redirect, redirect_obj from mediagoblin.tools.text import cleaned_markdown_conversion from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.pagination import Pagination +from mediagoblin.tools.federation import create_activity from mediagoblin.user_pages import forms as user_forms from mediagoblin.user_pages.lib import (send_comment_email, add_media_to_collection, build_report_object) @@ -178,7 +181,7 @@ def media_post_comment(request, media): comment = request.db.MediaComment() comment.media_entry = media.id comment.author = request.user.id - comment.content = unicode(request.form['comment_content']) + comment.content = six.text_type(request.form['comment_content']) # Show error message if commenting is disabled. if not mg_globals.app_config['allow_comments']: @@ -192,16 +195,15 @@ def media_post_comment(request, media): messages.ERROR, _("Oops, your comment was empty.")) else: + create_activity("post", comment, comment.author, target=media) + add_comment_subscription(request.user, media) comment.save() messages.add_message( request, messages.SUCCESS, _('Your comment has been posted!')) - trigger_notification(comment, media, request) - add_comment_subscription(request.user, media) - return redirect_obj(request, media) @@ -212,7 +214,7 @@ def media_preview_comment(request): if not request.is_xhr: return render_404(request) - comment = unicode(request.form['comment_content']) + comment = six.text_type(request.form['comment_content']) cleancomment = { "content":cleaned_markdown_conversion(comment)} return Response(json.dumps(cleancomment)) @@ -260,6 +262,7 @@ def media_collect(request, media): collection.description = form.collection_description.data collection.creator = request.user.id collection.generate_slug() + create_activity("create", collection, collection.creator) collection.save() # Otherwise, use the collection selected from the drop-down @@ -287,7 +290,7 @@ def media_collect(request, media): % (media.title, collection.title)) else: # Add item to collection add_media_to_collection(collection, media, form.note.data) - + create_activity("add", media, request.user, target=collection) messages.add_message(request, messages.SUCCESS, _('"%s" added to collection "%s"') % (media.title, collection.title)) @@ -692,3 +695,34 @@ def file_a_report(request, media, comment): request, 'mediagoblin/user_pages/report.html', context) + +@require_active_login +def activity_view(request): + """ /<username>/activity/<id> - Display activity + + This should display a HTML presentation of the activity + this is NOT an API endpoint. + """ + # Get the user object. + username = request.matchdict["username"] + user = User.query.filter_by(username=username).first() + + activity_id = request.matchdict["id"] + + if request.user is None: + return render_404(request) + + activity = Activity.query.filter_by( + id=activity_id, + author=user.id + ).first() + + if activity is None: + return render_404(request) + + return render_to_response( + request, + "mediagoblin/api/activity.html", + {"activity": activity} + ) + |