Commit fe6ed085 by cahrens

Code review feedback.

parent d11c92d7
...@@ -145,7 +145,7 @@ def upload_asset(request, org, course, coursename): ...@@ -145,7 +145,7 @@ def upload_asset(request, org, course, coursename):
return JsonResponse(response_payload) return JsonResponse(response_payload)
@require_http_methods("DELETE") @require_http_methods(("DELETE",))
@login_required @login_required
@ensure_csrf_cookie @ensure_csrf_cookie
def update_asset(request, org, course, name, asset_id): def update_asset(request, org, course, name, asset_id):
...@@ -158,40 +158,39 @@ def update_asset(request, org, course, name, asset_id): ...@@ -158,40 +158,39 @@ def update_asset(request, org, course, name, asset_id):
""" """
get_location_and_verify_access(request, org, course, name) get_location_and_verify_access(request, org, course, name)
if request.method == 'DELETE': # make sure the location is valid
# make sure the location is valid try:
try: loc = StaticContent.get_location_from_path(asset_id)
loc = StaticContent.get_location_from_path(asset_id) except InvalidLocationError as err:
except InvalidLocationError as err: # return a 'Bad Request' to browser as we have a malformed Location
# return a 'Bad Request' to browser as we have a malformed Location return JsonResponse({"error": err.message}, status=400)
return JsonResponse({"error": err.message}, status=400)
# also make sure the item to delete actually exists
try:
content = contentstore().find(loc)
except NotFoundError:
return JsonResponse(status=404)
# ok, save the content into the trashcan
contentstore('trashcan').save(content)
# also make sure the item to delete actually exists # see if there is a thumbnail as well, if so move that as well
if content.thumbnail_location is not None:
try: try:
content = contentstore().find(loc) thumbnail_content = contentstore().find(content.thumbnail_location)
except NotFoundError: contentstore('trashcan').save(thumbnail_content)
return JsonResponse(status=404) # hard delete thumbnail from origin
contentstore().delete(thumbnail_content.get_id())
# ok, save the content into the trashcan # remove from any caching
contentstore('trashcan').save(content) del_cached_content(thumbnail_content.location)
except:
# see if there is a thumbnail as well, if so move that as well pass # OK if this is left dangling
if content.thumbnail_location is not None:
try: # delete the original
thumbnail_content = contentstore().find(content.thumbnail_location) contentstore().delete(content.get_id())
contentstore('trashcan').save(thumbnail_content) # remove from cache
# hard delete thumbnail from origin del_cached_content(content.location)
contentstore().delete(thumbnail_content.get_id()) return JsonResponse()
# remove from any caching
del_cached_content(thumbnail_content.location)
except:
pass # OK if this is left dangling
# delete the original
contentstore().delete(content.get_id())
# remove from cache
del_cached_content(content.location)
return JsonResponse()
def _get_asset_json(display_name, date, location, thumbnail_location): def _get_asset_json(display_name, date, location, thumbnail_location):
......
...@@ -10,7 +10,7 @@ CMS.Views.Assets = Backbone.View.extend({ ...@@ -10,7 +10,7 @@ CMS.Views.Assets = Backbone.View.extend({
this.$el.empty(); this.$el.empty();
var self = this; var self = this;
_.each(this.collection.models, this.collection.each(
function(asset) { function(asset) {
var view = new CMS.Views.Asset({model: asset}); var view = new CMS.Views.Asset({model: asset});
self.$el.append(view.render().el); self.$el.append(view.render().el);
......
...@@ -76,7 +76,7 @@ urlpatterns = ('', # nopep8 ...@@ -76,7 +76,7 @@ urlpatterns = ('', # nopep8
url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/assets/(?P<name>[^/]+)$', url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/assets/(?P<name>[^/]+)$',
'contentstore.views.asset_index', name='asset_index'), 'contentstore.views.asset_index', name='asset_index'),
url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/assets/(?P<name>[^/]+)/update/(?P<asset_id>.+)?.*$', url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/assets/(?P<name>[^/]+)/(?P<asset_id>.+)?.*$',
'contentstore.views.assets.update_asset', name='update_asset'), 'contentstore.views.assets.update_asset', name='update_asset'),
url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/textbooks/(?P<name>[^/]+)$', url(r'^(?P<org>[^/]+)/(?P<course>[^/]+)/textbooks/(?P<name>[^/]+)$',
'contentstore.views.textbook_index', name='textbook_index'), 'contentstore.views.textbook_index', name='textbook_index'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment