@require_http_methods(('DELETE', 'POST', 'PUT'))
@login_required
@ensure_csrf_cookie
def _update_asset(request, course_key, asset_key):
 if (request.method == 'DELETE'):
  try:
   delete_asset(course_key, asset_key)
   return JsonResponse()
  except AssetNotFoundException:
   return JsonResponse(status=404)
 elif (request.method in ('PUT', 'POST')):
  if ('file' in request.FILES):
   return _upload_asset(request, course_key)
  else:
   try:
    modified_asset = json.loads(request.body)
   except ValueError:
    return HttpResponseBadRequest()
   contentstore().set_attr(asset_key, 'locked', modified_asset['locked'])
   del_cached_content(asset_key)
   return JsonResponse(modified_asset, status=201)

@ require_http_methods ( ( 'DELETE' , 'POST' , 'PUT' ) ) @ login_required @ ensure_csrf_cookie def _update_asset ( request , course_key , asset_key ) : if ( request . method == 'DELETE' ) : try : delete_asset ( course_key , asset_key ) return JsonResponse ( ) except AssetNotFoundException : return JsonResponse ( status = 404 ) elif ( request . method in ( 'PUT' , 'POST' ) ) : if ( 'file' in request . FILES ) : return _upload_asset ( request , course_key ) else : try : modified_asset = json . loads ( request . body ) except ValueError : return HttpResponseBadRequest ( ) contentstore ( ) . set_attr ( asset_key , 'locked' , modified_asset [ 'locked' ] ) del_cached_content ( asset_key ) return JsonResponse ( modified_asset , status = 201 )
restful crud operations for a course asset .