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
|
|
| 42 | 42 | |
| 43 | 43 | <br /> |
| 44 | 44 | |
| 45 | | <p class="delete_checkbox_box"> |
| 46 | | {{ form.confirm }} |
| 47 | | {{ wtforms_util.render_label(form.confirm) }} |
| 48 | | </p> |
| 49 | | |
| 50 | 45 | <div class="form_submit_buttons"> |
| 51 | 46 | {# TODO: This isn't a button really... might do unexpected things :) #} |
| 52 | 47 | <a class="button_action" href=" |
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
|
|
| 48 | 48 | |
| 49 | 49 | <br /> |
| 50 | 50 | |
| 51 | | <p class="delete_checkbox_box"> |
| 52 | | {{ form.confirm }} |
| 53 | | {{ wtforms_util.render_label(form.confirm) }} |
| 54 | | </p> |
| 55 | | |
| 56 | 51 | <div class="form_submit_buttons"> |
| 57 | 52 | {# TODO: This isn't a button really... might do unexpected things :) #} |
| 58 | 53 | <a class="button_action" href=" |
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
|
|
| 38 | 38 | |
| 39 | 39 | <br /> |
| 40 | 40 | |
| 41 | | <p class="delete_checkbox_box"> |
| 42 | | {{ form.confirm }} |
| 43 | | {{ wtforms_util.render_label(form.confirm) }} |
| 44 | | </p> |
| 45 | | |
| 46 | 41 | <div class="form_submit_buttons"> |
| 47 | 42 | {# TODO: This isn't a button really... might do unexpected things :) #} |
| 48 | 43 | <a class="button_action" href="{{ media.url_for_self(request.urlgen) }}">{% trans %}Cancel{% endtrans %}</a> |
diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
index f51b132..ae5c9d5 100644
|
a
|
b
|
class TestSubmissionBasics(BaseTestSubmission):
|
| 341 | 341 | url=comment_url, do_follow=True)[0] |
| 342 | 342 | self.check_comments(request, media_id, 1) |
| 343 | 343 | |
| 344 | | # Do not confirm deletion |
| | 344 | # Check Deletion |
| 345 | 345 | # --------------------------------------------------- |
| 346 | 346 | delete_url = request.urlgen( |
| 347 | 347 | 'mediagoblin.user_pages.media_confirm_delete', |
| 348 | 348 | 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, |
| 357 | 350 | do_follow=True, url=delete_url) |
| 358 | 351 | self.check_media(request, {'id': media_id}, 0) |
| 359 | 352 | self.check_comments(request, media_id, 0) |
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):
|
| 332 | 332 | form = user_forms.ConfirmDeleteForm(request.form) |
| 333 | 333 | |
| 334 | 334 | 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 |
| 337 | 336 | |
| 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) |
| 342 | 341 | |
| 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() |
| 347 | 346 | |
| 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) |
| 369 | 361 | |
| 370 | 362 | if ((request.user.has_privilege(u'admin') and |
| 371 | 363 | request.user.id != media.actor)): |
| … |
… |
def collection_item_confirm_remove(request, collection_item):
|
| 436 | 428 | username = collection_item.in_collection.get_actor.username |
| 437 | 429 | collection = collection_item.in_collection |
| 438 | 430 | |
| 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() |
| 442 | 433 | |
| 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() |
| 446 | 437 | |
| 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.')) |
| 457 | 442 | |
| 458 | 443 | return redirect_obj(request, collection) |
| 459 | 444 | |
| … |
… |
def collection_confirm_delete(request, collection):
|
| 482 | 467 | if request.method == 'POST' and form.validate(): |
| 483 | 468 | |
| 484 | 469 | username = collection.get_actor.username |
| | 470 | |
| | 471 | collection_title = collection.title |
| 485 | 472 | |
| 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) |
| 498 | 476 | |
| 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() |
| 505 | 482 | |
| 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) |
| 514 | 489 | |
| 515 | | return redirect_obj(request, collection) |
| | 490 | return redirect(request, "mediagoblin.user_pages.user_home", |
| | 491 | user=username) |
| 516 | 492 | |
| 517 | 493 | if ((request.user.has_privilege(u'admin') and |
| 518 | 494 | request.user.id != collection.actor)): |