Fix #5451 - add_message inconsistencies
authorAndrew Browning <ayleph@thisshitistemp.com>
Sat, 2 Apr 2016 01:14:40 +0000 (21:14 -0400)
committerAndrew Browning <ayleph@thisshitistemp.com>
Sat, 2 Apr 2016 23:59:01 +0000 (19:59 -0400)
Reformat add_message function calls for consistency and PEP8 line
continuations.

mediagoblin/edit/views.py
mediagoblin/media_types/blog/views.py
mediagoblin/notifications/views.py
mediagoblin/plugins/basic_auth/views.py
mediagoblin/submit/views.py
mediagoblin/tools/mail.py
mediagoblin/user_pages/views.py

index 00c611573dcf020d41b3e243961aa2385f2af822..521359f5bcce303540fda3adce4e286f47829092 100644 (file)
@@ -94,7 +94,8 @@ def edit_media(request, media):
             and media.actor != request.user.id \
             and request.method != 'POST':
         messages.add_message(
-            request, messages.WARNING,
+            request,
+            messages.WARNING,
             _("You are editing another user's media. Proceed with caution."))
 
     return render_to_response(
@@ -164,10 +165,11 @@ def edit_attachments(request, media):
             media.save()
 
             messages.add_message(
-                request, messages.SUCCESS,
-                _("You added the attachment %s!") \
-                    % (form.attachment_name.data
-                       or request.files['attachment_file'].filename))
+                request,
+                messages.SUCCESS,
+                _("You added the attachment %s!") %
+                    (form.attachment_name.data or
+                     request.files['attachment_file'].filename))
 
             return redirect(request,
                             location=media.url_for_self(request.urlgen))
@@ -197,7 +199,8 @@ def edit_profile(request, url_user=None):
         # No need to warn again if admin just submitted an edited profile
         if request.method != 'POST':
             messages.add_message(
-                request, messages.WARNING,
+                request,
+                messages.WARNING,
                 _("You are editing a user's profile. Proceed with caution."))
 
     user = url_user
@@ -227,9 +230,10 @@ def edit_profile(request, url_user=None):
 
         user.save()
 
-        messages.add_message(request,
-                             messages.SUCCESS,
-                             _("Profile changes saved"))
+        messages.add_message(
+            request,
+            messages.SUCCESS,
+            _("Profile changes saved"))
         return redirect(request,
                        'mediagoblin.user_pages.user_home',
                         user=user.username)
@@ -260,9 +264,10 @@ def edit_account(request):
         user.license_preference = form.license_preference.data
 
         user.save()
-        messages.add_message(request,
-                             messages.SUCCESS,
-                             _("Account settings saved"))
+        messages.add_message(
+            request,
+            messages.SUCCESS,
+            _("Account settings saved"))
         return redirect(request,
                         'mediagoblin.user_pages.user_home',
                         user=user.username)
@@ -324,7 +329,8 @@ def delete_account(request):
 
         else: # Did not check the confirmation box...
             messages.add_message(
-                request, messages.WARNING,
+                request,
+                messages.WARNING,
                 _('You need to confirm the deletion of your account.'))
 
     # No POST submission or not confirmed, just show page
@@ -360,8 +366,9 @@ def edit_collection(request, collection):
 
         if existing_collection and existing_collection.id != collection.id:
             messages.add_message(
-                request, messages.ERROR,
-                _('You already have a collection called "%s"!') % \
+                request,
+                messages.ERROR,
+                _('You already have a collection called "%s"!') %
                     form.title.data)
         elif slug_used:
             form.slug.errors.append(
@@ -379,8 +386,10 @@ def edit_collection(request, collection):
             and collection.actor != request.user.id \
             and request.method != 'POST':
         messages.add_message(
-            request, messages.WARNING,
-            _("You are editing another user's collection. Proceed with caution."))
+            request,
+            messages.WARNING,
+            _("You are editing another user's collection. "
+              "Proceed with caution."))
 
     return render_to_response(
         request,
index 4b6ea7b718f782df4e9d4943531a962806b7ec90..d48cf82f8a9900a7b6bb32b7e9904245f8c67459 100644 (file)
@@ -32,7 +32,6 @@ from mediagoblin.media_types.blog.lib import (
         may_edit_blogpost, set_blogpost_state, get_all_blogposts_of_blog,
         get_blog_by_slug)
 
-from mediagoblin.messages import add_message, SUCCESS, ERROR, WARNING
 from mediagoblin.decorators import (require_active_login, active_user_from_url,
                             get_media_entry_by_id, user_may_alter_collection,
                             get_user_collection, uses_pagination)
@@ -87,8 +86,10 @@ def blog_edit(request):
                         user=request.user.username
                        )
         else:
-            add_message(request, ERROR, "Welcome! You already have created \
-                                                        maximum number of blogs.")
+            messages.add_message(
+                request,
+                messages.ERROR,
+                "Welcome! You already have created maximum number of blogs.")
             return redirect(request, "mediagoblin.media_types.blog.blog_admin_dashboard",
                         user=request.user.username)
 
@@ -120,7 +121,10 @@ def blog_edit(request):
                 blog.generate_slug()
 
                 blog.save()
-                add_message(request, SUCCESS, "Your blog is updated.")
+                messages.add_message(
+                    request,
+                    messages.SUCCESS,
+                    "Your blog is updated.")
                 return redirect(request, "mediagoblin.media_types.blog.blog-dashboard",
                         user=request.user.username,
                         blog_slug=blog.slug)
@@ -155,7 +159,10 @@ def blogpost_create(request):
         blog_post_data.media_entry = blogpost.id
         blog_post_data.save()
 
-        add_message(request, SUCCESS, _('Woohoo! Submitted!'))
+        messages.add_message(
+            request,
+            messages.SUCCESS,
+            _('Woohoo! Submitted!'))
         add_comment_subscription(request.user, blogpost)
         return redirect(request, "mediagoblin.media_types.blog.blog-dashboard",
                         user=request.user.username,
@@ -197,7 +204,10 @@ def blogpost_edit(request):
         blogpost.generate_slug()
         blogpost.save()
 
-        add_message(request, SUCCESS, _('Woohoo! edited blogpost is submitted'))
+        messages.add_message(
+            request,
+            messages.SUCCESS,
+            _('Woohoo! edited blogpost is submitted'))
         return redirect(request, "mediagoblin.media_types.blog.blog-dashboard",
                         user=request.user.username,
                         blog_slug=blog.slug)
@@ -320,20 +330,25 @@ def blog_delete(request, **kwargs):
         if request.method == 'POST' and form.validate():
             if form.confirm.data is True:
                 blog.delete()
-                add_message(
-                request, SUCCESS, _('You deleted the Blog.'))
+                messages.add_message(
+                    request,
+                    messages.SUCCESS,
+                    _('You deleted the Blog.'))
                 return redirect(request, "mediagoblin.media_types.blog.blog_admin_dashboard",
                         user=request.user.username)
             else:
-                add_message(
-                request, ERROR,
-                _("The media was not deleted because you didn't check that you were sure."))
+                messages.add_message(
+                    request,
+                    messages.ERROR,
+                    _("The media was not deleted because you didn't check "
+                      "that you were sure."))
                 return redirect(request, "mediagoblin.media_types.blog.blog_admin_dashboard",
                         user=request.user.username)
         else:
             if request.user.has_privilege(u'admin'):
-                add_message(
-                    request, WARNING,
+                messages.add_message(
+                    request,
+                    messages.WARNING,
                     _("You are about to delete another user's Blog. "
                       "Proceed with caution."))
             return render_to_response(
@@ -343,9 +358,10 @@ def blog_delete(request, **kwargs):
             'form':form
             })
     else:
-        add_message(
-        request, ERROR,
-        _("The blog was not deleted because you have no rights."))
+        messages.add_message(
+            request,
+            messages.ERROR,
+            _("The blog was not deleted because you have no rights."))
         return redirect(request, "mediagoblin.media_types.blog.blog_admin_dashboard",
         user=request.user.username)
 
index 7298e964a41b82530ed2fd35e4f67b894c896e43..30ecec7776436583f1acfad9c920eebbee8ccf5f 100644 (file)
@@ -30,10 +30,10 @@ def subscribe_comments(request, media):
 
     add_comment_subscription(request.user, media)
 
-    messages.add_message(request,
-                         messages.SUCCESS,
-                         _('Subscribed to comments on %s!')
-                         % media.title)
+    messages.add_message(
+        request,
+        messages.SUCCESS,
+        _('Subscribed to comments on %s!') % media.title)
 
     return redirect(request, location=media.url_for_self(request.urlgen))
 
@@ -43,10 +43,11 @@ def subscribe_comments(request, media):
 def silence_comments(request, media):
     silence_comment_subscription(request.user, media)
 
-    messages.add_message(request,
-                         messages.SUCCESS,
-                         _('You will not receive notifications for comments on'
-                           ' %s.') % media.title)
+    messages.add_message(
+        request,
+        messages.SUCCESS,
+        _('You will not receive notifications for comments on %s.') %
+            media.title)
 
     return redirect(request, location=media.url_for_self(request.urlgen))
 
index 86d7eaef88104351ce6a01fdbd2d564dcba71254..f398f0d20ecc0ef4a8707a60e6c482eeaa6ded3f 100644 (file)
@@ -60,9 +60,10 @@ def forgot_password(request):
             username=fp_form.username.data).first()
 
         if user is None:
-            messages.add_message(request,
-                                 messages.WARNING,
-                                 _("Couldn't find someone with that username."))
+            messages.add_message(
+                request,
+                messages.WARNING,
+                _("Couldn't find someone with that username."))
             return redirect(request,
                             'mediagoblin.plugins.basic_auth.forgot_password')
 
@@ -71,10 +72,11 @@ def forgot_password(request):
 
     if user and user.has_privilege(u'active') is False:
         # Don't send reminder because user is inactive or has no verified email
-        messages.add_message(request,
+        messages.add_message(
+            request,
             messages.WARNING,
-            _("Could not send password recovery email as your username is in"
-              "active or your account's email address has not been verified."))
+            _("Could not send password recovery email as your username is "
+              "inactive or your account's email address has not been verified."))
 
         return redirect(request, 'mediagoblin.user_pages.user_home',
                         user=user.username)
@@ -154,15 +156,17 @@ def verify_forgot_password(request):
     #
     # if not user.email_verified:
     #     messages.add_message(
-    #         request, messages.ERROR,
+    #         request,
+    #         messages.ERROR,
     #         _('You need to verify your email before you can reset your'
     #           ' password.'))
 
     if not user.status == 'active':
         messages.add_message(
-            request, messages.ERROR,
-            _('You are no longer an active user. Please contact the system'
-              ' admin to reactivate your account.'))
+            request,
+            messages.ERROR,
+            _("You are no longer an active user. Please contact the system "
+              "admin to reactivate your account."))
 
     return redirect(
         request, 'index')
@@ -212,7 +216,8 @@ def change_pass(request):
         user.save()
 
         messages.add_message(
-            request, messages.SUCCESS,
+            request,
+            messages.SUCCESS,
             _('Your password was changed successfully'))
 
         return redirect(request, 'mediagoblin.edit.account')
index eb11dfe0268c50da968d89f9f436f276c6af2f97..be47361534ca123ada3777f519cf03afaee716a6 100644 (file)
@@ -29,7 +29,6 @@ from mediagoblin.tools.translate import pass_to_ugettext as _
 from mediagoblin.tools.response import render_to_response, redirect
 from mediagoblin.decorators import require_active_login, user_has_privilege
 from mediagoblin.submit import forms as submit_forms
-from mediagoblin.messages import add_message, SUCCESS
 from mediagoblin.media_types import FileTypeNotSupported
 from mediagoblin.submit.lib import \
     check_file_field, submit_media, get_upload_file_limits, \
@@ -87,7 +86,10 @@ def submit_start(request):
                         "add", media, request.user,
                         target=submit_form.collection.data)
 
-                add_message(request, SUCCESS, _('Woohoo! Submitted!'))
+                messages.add_message(
+                    request,
+                    messages.SUCCESS,
+                    _('Woohoo! Submitted!'))
 
                 return redirect(request, "mediagoblin.user_pages.user_home",
                             user=request.user.username)
@@ -143,13 +145,17 @@ def add_collection(request, media=None):
                 title=collection.title).first()
 
         if existing_collection:
-            add_message(request, messages.ERROR,
-                _('You already have a collection called "%s"!') \
-                    % collection.title)
+            messages.add_message(
+                request,
+                messages.ERROR,
+                _('You already have a collection called "%s"!') %
+                    collection.title)
         else:
             collection.save()
 
-            add_message(request, SUCCESS,
+            messages.add_message(
+                request,
+                messages.SUCCESS,
                 _('Collection "%s" added!') % collection.title)
 
         return redirect(request, "mediagoblin.user_pages.user_home",
index 74e59fb3792a21a636eeac33bc9a90bfe4f6396d..c11e392bc31ff05bfe7fe4bb3dc32969c5e174a4 100644 (file)
@@ -163,6 +163,8 @@ def email_debug_message(request):
     """
     if mg_globals.app_config['email_debug_mode']:
         # DEBUG message, no need to translate
-        messages.add_message(request, messages.DEBUG,
+        messages.add_message(
+            request,
+            messages.DEBUG,
             "This instance is running in email debug mode. "
             "The email will be on the console of the server process.")
index 6949aaf617d5680aafd4a739355f5bc467a12c60..28d3ba79bc81438c588c140f9cba54b24ce7869d 100644 (file)
@@ -205,7 +205,8 @@ def media_post_comment(request, media):
         link.save()
 
         messages.add_message(
-            request, messages.SUCCESS,
+            request,
+            messages.SUCCESS,
             _('Your comment has been posted!'))
         trigger_notification(link, media, request)
 
@@ -240,7 +241,9 @@ def media_collect(request, media):
     if request.method != 'POST' or not form.validate():
         # No POST submission, or invalid form
         if not form.validate():
-            messages.add_message(request, messages.ERROR,
+            messages.add_message(
+                request,
+                messages.ERROR,
                 _('Please check your entries and try again.'))
 
         return render_to_response(
@@ -259,9 +262,11 @@ def media_collect(request, media):
             type=Collection.USER_DEFINED_TYPE
         ).first()
         if existing_collection:
-            messages.add_message(request, messages.ERROR,
-                _('You already have a collection called "%s"!')
-                % existing_collection.title)
+            messages.add_message(
+                request,
+                messages.ERROR,
+                _('You already have a collection called "%s"!') %
+                    existing_collection.title)
             return redirect(request, "mediagoblin.user_pages.media_home",
                             user=media.get_actor.username,
                             media=media.slug_or_id)
@@ -291,7 +296,8 @@ def media_collect(request, media):
 
     if not collection:
         messages.add_message(
-            request, messages.ERROR,
+            request,
+            messages.ERROR,
             _('You have to select or add a collection'))
         return redirect(request, "mediagoblin.user_pages.media_collect",
                     user=media.get_actor.username,
@@ -299,15 +305,19 @@ def media_collect(request, media):
 
     # Check whether media already exists in collection
     elif item is not None:
-        messages.add_message(request, messages.ERROR,
-                             _('"%s" already in collection "%s"')
-                             % (media.title, collection.title))
+        messages.add_message(
+            request,
+            messages.ERROR,
+            _('"%s" already in collection "%s"') %
+                (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))
+        messages.add_message(
+            request,
+            messages.SUCCESS,
+            _('"%s" added to collection "%s"') %
+                (media.title, collection.title))
 
     return redirect_obj(request, media)
 
@@ -337,7 +347,9 @@ def media_confirm_delete(request, media):
             # Delete MediaEntry and all related files, comments etc.
             media.delete()
             messages.add_message(
-                request, messages.SUCCESS, _('You deleted the media.'))
+                request,
+                messages.SUCCESS,
+                _('You deleted the media.'))
 
             location = media.url_to_next(request.urlgen)
             if not location:
@@ -348,14 +360,17 @@ def media_confirm_delete(request, media):
             return redirect(request, location=location)
         else:
             messages.add_message(
-                request, messages.ERROR,
-                _("The media was not deleted because you didn't check that you were sure."))
+                request,
+                messages.ERROR,
+                _("The media was not deleted because you didn't check "
+                  "that you were sure."))
             return redirect_obj(request, media)
 
     if ((request.user.has_privilege(u'admin') and
          request.user.id != media.actor)):
         messages.add_message(
-            request, messages.WARNING,
+            request,
+            messages.WARNING,
             _("You are about to delete another user's media. "
               "Proceed with caution."))
 
@@ -429,18 +444,23 @@ def collection_item_confirm_remove(request, collection_item):
             collection.save()
 
             messages.add_message(
-                request, messages.SUCCESS, _('You deleted the item from the collection.'))
+                request,
+                messages.SUCCESS,
+                _('You deleted the item from the collection.'))
         else:
             messages.add_message(
-                request, messages.ERROR,
-                _("The item was not removed because you didn't check that you were sure."))
+                request,
+                messages.ERROR,
+                _("The item was not removed because you didn't check "
+                  "that you were sure."))
 
         return redirect_obj(request, collection)
 
     if ((request.user.has_privilege(u'admin') and
          request.user.id != collection_item.in_collection.actor)):
         messages.add_message(
-            request, messages.WARNING,
+            request,
+            messages.WARNING,
             _("You are about to delete an item from another user's collection. "
               "Proceed with caution."))
 
@@ -476,15 +496,20 @@ def collection_confirm_delete(request, collection):
                 item.delete()
 
             collection.delete()
-            messages.add_message(request, messages.SUCCESS,
-                _('You deleted the collection "%s"') % collection_title)
+            messages.add_message(
+                request,
+                messages.SUCCESS,
+                _('You deleted the collection "%s"') %
+                    collection_title)
 
             return redirect(request, "mediagoblin.user_pages.user_home",
                 user=username)
         else:
             messages.add_message(
-                request, messages.ERROR,
-                _("The collection was not deleted because you didn't check that you were sure."))
+                request,
+                messages.ERROR,
+                _("The collection was not deleted because you didn't "
+                  "check that you were sure."))
 
             return redirect_obj(request, collection)