当前位置: 首页>>代码示例>>Python>>正文


Python APIPermissions.remove_file_by_key方法代码示例

本文整理汇总了Python中API.APIPermissions.remove_file_by_key方法的典型用法代码示例。如果您正苦于以下问题:Python APIPermissions.remove_file_by_key方法的具体用法?Python APIPermissions.remove_file_by_key怎么用?Python APIPermissions.remove_file_by_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在API.APIPermissions的用法示例。


在下文中一共展示了APIPermissions.remove_file_by_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_file_remove_file_by_key_success

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import remove_file_by_key [as 别名]
	def test_file_remove_file_by_key_success(self):
		key = ps.add_file( FileInfo("testFilerfks",ndb.Key("someKey","rfks") ) )

		self.assertTrue(ps.remove_file_by_key(key))
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:6,代码来源:TestAPIPermissions.py

示例2: file_list_edit

# 需要导入模块: from API import APIPermissions [as 别名]
# 或者: from API.APIPermissions import remove_file_by_key [as 别名]
def file_list_edit(request):
	authed_user = auth.get_current_user()
	if authed_user is None:
		return __unauthed_response()
	
	user_key = ps.get_user_key_by_id(authed_user.user_id())
	
	try:
		actions = json.loads(request.raw_post_data)
	except ValueError:
		return HttpResponse(json.dumps({'error' : 'invalid request payload'}), content_type="application/json")
	
	if not isinstance(actions, list):
		return HttpResponse(json.dumps({'error' : 'Payload is not a list'}), content_type="application/json")
	
	res = []
	for a in actions:
		
		#We can't do anything without a filename
		if 'filename' not in a:
			continue
		else:
			filename = a['filename']
		
		if 'action' not in a:
			continue
		else:
			action = a['action']
		
		res_fragment = {
			'filename' 	: a['filename'],
			'action'	: a['action']
		}
		
		if action == 'delete':
			file_entry = ps.get_file_by_name(DATA_BUCKET + '/' + filename)
			if file_entry is not None:
				ps.remove_file_by_key(file_entry.key)
			
			ds.delete(DATA_BUCKET + '/' + filename)
			ds.delete(INFO_BUCKET + '/' + filename + 'info.txt')
			ds.delete(INFO_BUCKET + '/' + filename + '.txt')
			ds.delete(GRAPH_BUCKET + '/' + filename + '.png')
			
			res_fragment.update( { 'success' : True } )
		
		#Reinstate this when CE PAL is available
		#else:
		#res_fragment.update( { 'success' : False, 'error' : 'File does not exist.' } )
		
		elif action == 'rename':
			if 'newname' not in a:
				res_fragment.update( { 'success' : False, 'error' : 'New name not specified' } )
			else:
				file_entry = ps.get_file_by_name(DATA_BUCKET + '/' + filename)
				if file_entry is None:
					res_fragment.update( { 'success' : False, 'error' : 'File does not exist.' } )
				else:
					file_entry.friendly_name = a['newname']
					if ps.update_file(file_entry):
						res_fragment.update( { 'success' : True } )
					else:
						res_fragment.update( { 'success' : False, 'error' : 'Could not rename file' } )
		
		elif action == 'star' or action == 'unstar':
			file_entry = ps.get_file_by_name(DATA_BUCKET + '/' + filename)
			if file_entry is None:
				res_fragment.update( { 'success' : False, 'error' : 'File does not exist.' } )
			else:
				fp_entry = ps.get_user_file_permissions(file_entry.key, user_key)
				if fp_entry is None:
					res_fragment.update( { 'success' : False, 'error' : 'Permissions entry not found' } )
				else:
					if ps.modify_file_permissions_by_key(fp_entry.key, new_starred = (action == 'star')):
						res_fragment.update( { 'success' : True } )
					else:
						res_fragment.update( { 'success' : False, 'error' : 'Could not update file' } )

		elif action == 'recolour':
			if 'newcolour' not in a:
				res_fragment.update( { 'success' : False, 'error' : 'New colour not specified' } )
			else:
				colour = a['newcolour']
				chk_string = re.compile("^[A-Fa-f0-9]{6}$")
				if (chk_string.match(colour)):
					file_entry = ps.get_file_by_name(DATA_BUCKET + '/' + filename)
					if file_entry is None:
						res_fragment.update( { 'success' : False, 'error' : 'File does not exist.' } )
					else:
						fp_entry = ps.get_user_file_permissions(file_entry.key, user_key)
						if fp_entry is None:
							res_fragment.update( { 'success' : False, 'error' : 'Permissions entry not found' } )
						else:
							if ps.modify_file_permissions_by_key(fp_entry.key, new_colour = colour):
								res_fragment.update( { 'success' : True } )
							else:
								res_fragment.update( { 'success' : False, 'error' : 'Could not update file' } )
				else:
					res_fragment.update( { 'success' : False, 'error' : 'New colour invalid' } )

#.........这里部分代码省略.........
开发者ID:Keesaco,项目名称:KeesaFlo,代码行数:103,代码来源:views.py


注:本文中的API.APIPermissions.remove_file_by_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。