Ticket #986: issue_986_rev.patch

File issue_986_rev.patch, 10.2 KB (added by Vijeth, 7 years ago)

Revised patch including the backend part

  • mediagoblin/templates/mediagoblin/user_pages/collection_confirm_delete.html

    From 04b90633371d14867aa0a3106266300cd5bfa34b Mon Sep 17 00:00:00 2001
    From: vijeth-aradhya <vijthaaa@gmail.com>
    Date: Fri, 20 Jan 2017 12:31:12 +0530
    Subject: [PATCH] user_pages: Remove checkbox prompt while deletion
    
    The usage of a checkbox prompt while deleting media
    or collection with the dialogue is not necessary.
    
    Fixes #986
    ---
     .../user_pages/collection_confirm_delete.html      |   5 -
     .../user_pages/collection_item_confirm_remove.html |   5 -
     .../user_pages/media_confirm_delete.html           |   5 -
     mediagoblin/tests/test_submission.py               |  11 +-
     mediagoblin/user_pages/views.py                    | 124 +++++++++------------
     5 files changed, 52 insertions(+), 98 deletions(-)
    
    diff --git a/mediagoblin/templates/mediagoblin/user_pages/collection_confirm_delete.html b/mediagoblin/templates/mediagoblin/user_pages/collection_confirm_delete.html
    index 0827834..5ded731 100644
    a b  
    4242
    4343      <br />
    4444
    45       <p class="delete_checkbox_box">
    46         {{ form.confirm }}
    47         {{ wtforms_util.render_label(form.confirm) }}
    48       </p>
    49 
    5045      <div class="form_submit_buttons">
    5146        {# TODO: This isn't a button really... might do unexpected things :) #}
    5247        <a class="button_action" href="
  • mediagoblin/templates/mediagoblin/user_pages/collection_item_confirm_remove.html

    diff --git a/mediagoblin/templates/mediagoblin/user_pages/collection_item_confirm_remove.html b/mediagoblin/templates/mediagoblin/user_pages/collection_item_confirm_remove.html
    index d7ff495..fc6345f 100644
    a b  
    4848
    4949      <br />
    5050
    51       <p class="delete_checkbox_box">
    52         {{ form.confirm }}
    53         {{ wtforms_util.render_label(form.confirm) }}
    54       </p>
    55 
    5651      <div class="form_submit_buttons">
    5752        {# TODO: This isn't a button really... might do unexpected things :) #}
    5853        <a class="button_action" href="
  • mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html

    diff --git a/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html b/mediagoblin/templates/mediagoblin/user_pages/media_confirm_delete.html
    index 243edff..1361011 100644
    a b  
    3838
    3939      <br />
    4040
    41       <p class="delete_checkbox_box">
    42         {{ form.confirm }}
    43         {{ wtforms_util.render_label(form.confirm) }}
    44       </p>
    45 
    4641      <div class="form_submit_buttons">
    4742        {# TODO: This isn't a button really... might do unexpected things :) #}
    4843        <a class="button_action" href="{{ media.url_for_self(request.urlgen) }}">{% trans %}Cancel{% endtrans %}</a>
  • mediagoblin/tests/test_submission.py

    diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
    index f51b132..ae5c9d5 100644
    a b class TestSubmissionBasics(BaseTestSubmission):  
    341341                                url=comment_url, do_follow=True)[0]
    342342        self.check_comments(request, media_id, 1)
    343343
    344         # Do not confirm deletion
     344        # Check Deletion
    345345        # ---------------------------------------------------
    346346        delete_url = request.urlgen(
    347347            'mediagoblin.user_pages.media_confirm_delete',
    348348            user=self.our_user().username, media_id=media_id)
    349         # Empty data means don't confirm
    350         response = self.do_post({}, do_follow=True, url=delete_url)[0]
    351         media = self.check_media(request, {'title': u'Balanced Goblin'}, 1)
    352         media_id = media.id
    353 
    354         # Confirm deletion
    355         # ---------------------------------------------------
    356         response, request = self.do_post({'confirm': 'y'}, *REQUEST_CONTEXT,
     349        response, request = self.do_post({}, *REQUEST_CONTEXT,
    357350                                         do_follow=True, url=delete_url)
    358351        self.check_media(request, {'id': media_id}, 0)
    359352        self.check_comments(request, media_id, 0)
  • mediagoblin/user_pages/views.py

    diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
    index eaae1bd..4cd284b 100644
    a b def media_confirm_delete(request, media):  
    332332    form = user_forms.ConfirmDeleteForm(request.form)
    333333
    334334    if request.method == 'POST' and form.validate():
    335         if form.confirm.data is True:
    336             username = media.get_actor.username
     335        username = media.get_actor.username
    337336
    338             # This probably is already filled but just in case it has slipped
    339             # through the net somehow, we need to try and make sure the
    340             # MediaEntry has a public ID so it gets properly soft-deleted.
    341             media.get_public_id(request.urlgen)
     337        # This probably is already filled but just in case it has slipped
     338        # through the net somehow, we need to try and make sure the
     339        # MediaEntry has a public ID so it gets properly soft-deleted.
     340        media.get_public_id(request.urlgen)
    342341
    343             # Decrement the users uploaded quota.
    344             media.get_actor.uploaded = media.get_actor.uploaded - \
    345                 media.file_size
    346             media.get_actor.save()
     342        # Decrement the users uploaded quota.
     343        media.get_actor.uploaded = media.get_actor.uploaded - \
     344            media.file_size
     345        media.get_actor.save()
    347346
    348             # Delete MediaEntry and all related files, comments etc.
    349             media.delete()
    350             messages.add_message(
    351                 request,
    352                 messages.SUCCESS,
    353                 _('You deleted the media.'))
    354 
    355             location = media.url_to_next(request.urlgen)
    356             if not location:
    357                 location=media.url_to_prev(request.urlgen)
    358             if not location:
    359                 location=request.urlgen("mediagoblin.user_pages.user_home",
    360                                         user=username)
    361             return redirect(request, location=location)
    362         else:
    363             messages.add_message(
    364                 request,
    365                 messages.ERROR,
    366                 _("The media was not deleted because you didn't check "
    367                   "that you were sure."))
    368             return redirect_obj(request, media)
     347        # Delete MediaEntry and all related files, comments etc.
     348        media.delete()
     349        messages.add_message(
     350            request,
     351            messages.SUCCESS,
     352            _('You deleted the media.'))
     353
     354        location = media.url_to_next(request.urlgen)
     355        if not location:
     356            location=media.url_to_prev(request.urlgen)
     357        if not location:
     358            location=request.urlgen("mediagoblin.user_pages.user_home",
     359                                    user=username)
     360        return redirect(request, location=location)
    369361
    370362    if ((request.user.has_privilege(u'admin') and
    371363         request.user.id != media.actor)):
    def collection_item_confirm_remove(request, collection_item):  
    436428        username = collection_item.in_collection.get_actor.username
    437429        collection = collection_item.in_collection
    438430
    439         if form.confirm.data is True:
    440             obj = collection_item.get_object()
    441             obj.save()
     431        obj = collection_item.get_object()
     432        obj.save()
    442433
    443             collection_item.delete()
    444             collection.num_items = collection.num_items - 1
    445             collection.save()
     434        collection_item.delete()
     435        collection.num_items = collection.num_items - 1
     436        collection.save()
    446437
    447             messages.add_message(
    448                 request,
    449                 messages.SUCCESS,
    450                 _('You deleted the item from the collection.'))
    451         else:
    452             messages.add_message(
    453                 request,
    454                 messages.ERROR,
    455                 _("The item was not removed because you didn't check "
    456                   "that you were sure."))
     438        messages.add_message(
     439            request,
     440            messages.SUCCESS,
     441            _('You deleted the item from the collection.'))
    457442
    458443        return redirect_obj(request, collection)
    459444
    def collection_confirm_delete(request, collection):  
    482467    if request.method == 'POST' and form.validate():
    483468
    484469        username = collection.get_actor.username
     470       
     471        collection_title = collection.title
    485472
    486         if form.confirm.data is True:
    487             collection_title = collection.title
    488 
    489             # Firstly like with the MediaEntry delete, lets ensure the
    490             # public_id is populated as this is really important!
    491             collection.get_public_id(request.urlgen)
    492 
    493             # Delete all the associated collection items
    494             for item in collection.get_collection_items():
    495                 obj = item.get_object()
    496                 obj.save()
    497                 item.delete()
     473        # Firstly like with the MediaEntry delete, lets ensure the
     474        # public_id is populated as this is really important!
     475        collection.get_public_id(request.urlgen)
    498476
    499             collection.delete()
    500             messages.add_message(
    501                 request,
    502                 messages.SUCCESS,
    503                 _('You deleted the collection "%s"') %
    504                     collection_title)
     477        # Delete all the associated collection items
     478        for item in collection.get_collection_items():
     479            obj = item.get_object()
     480            obj.save()
     481            item.delete()
    505482
    506             return redirect(request, "mediagoblin.user_pages.user_home",
    507                 user=username)
    508         else:
    509             messages.add_message(
    510                 request,
    511                 messages.ERROR,
    512                 _("The collection was not deleted because you didn't "
    513                   "check that you were sure."))
     483        collection.delete()
     484        messages.add_message(
     485            request,
     486            messages.SUCCESS,
     487            _('You deleted the collection "%s"') %
     488                collection_title)
    514489
    515             return redirect_obj(request, collection)
     490        return redirect(request, "mediagoblin.user_pages.user_home",
     491            user=username)
    516492
    517493    if ((request.user.has_privilege(u'admin') and
    518494         request.user.id != collection.actor)):