From d216d771f662fc3e0a3417ce06e8355abce99988 Mon Sep 17 00:00:00 2001 From: Jessica Tallon Date: Wed, 7 Oct 2015 13:13:40 +0200 Subject: Add public_id fixes throughout the code This adds several things, mainly code which checks for the public id and if it doesn't exist generating it where it can. This is to because we need to keep the public_id to be able to effectively soft delete models. This also adds a public_id field to the Activity along with a migration. --- mediagoblin/user_pages/views.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'mediagoblin/user_pages/views.py') diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py index 4ee601b3..f1c8a622 100644 --- a/mediagoblin/user_pages/views.py +++ b/mediagoblin/user_pages/views.py @@ -267,6 +267,7 @@ def media_collect(request, media): collection.actor = request.user.id collection.type = Collection.USER_DEFINED_TYPE collection.generate_slug() + collection.get_public_id(request.urlgen) create_activity("create", collection, collection.actor) collection.save() @@ -318,6 +319,12 @@ def media_confirm_delete(request, media): if form.confirm.data is True: username = media.get_actor.username + # This probably is already filled but just in case it has slipped + # through the net somehow, we need to try and make sure the + # MediaEntry has a public ID so it gets properly soft-deleted. + media.get_public_id(request.urlgen) + + # Decrement the users uploaded quota. media.get_actor.uploaded = media.get_actor.uploaded - \ media.file_size media.get_actor.save() @@ -453,6 +460,10 @@ def collection_confirm_delete(request, collection): if form.confirm.data is True: collection_title = collection.title + # Firstly like with the MediaEntry delete, lets ensure the + # public_id is populated as this is really important! + collection.get_public_id(request.urlgen) + # Delete all the associated collection items for item in collection.get_collection_items(): obj = item.get_object() @@ -727,6 +738,10 @@ def activity_view(request): author=user.id ).first() + # There isn't many places to check that the public_id is filled so this + # will do, it really should be, lets try and fix that if it isn't. + activity.get_public_id(request.urlgen) + if activity is None: return render_404(request) -- cgit v1.2.3