本文整理匯總了Python中API.APIPermissions.update_file方法的典型用法代碼示例。如果您正苦於以下問題:Python APIPermissions.update_file方法的具體用法?Python APIPermissions.update_file怎麽用?Python APIPermissions.update_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類API.APIPermissions
的用法示例。
在下文中一共展示了APIPermissions.update_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: file_list_edit
# 需要導入模塊: from API import APIPermissions [as 別名]
# 或者: from API.APIPermissions import update_file [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' } )
#.........這裏部分代碼省略.........