def test_file_rename_file_by_key_success(self): key = ps.add_file( FileInfo("testFilernfks",ndb.Key("someKey","rnfks") ) ) self.assertTrue(ps.rename_file_by_key(key,"testFilernfks2")) fileobj = ps.get_file_by_key(key) self.assertEqual(fileobj.file_name,"testFilernfks2")
def file_list_json(request): app_access = __check_app_access() if app_access is not None: return app_access authed_user = auth.get_current_user() user_key = ps.get_user_key_by_id(authed_user.user_id()) #TODO: This shouldn't be here - a generic method in APIPermissions would be nice. # 'your files' file_list = [] lst = ps.get_user_permissions_list(user_key) temp_group = [] if lst is not None: for perm in lst: list_entry = {} file_entry = ps.get_file_by_key(perm.file_key) if file_entry is not None: temp_file = ds.get_file_info(file_entry.file_name) if temp_file is None: continue list_entry.update({ 'permissions' : 'yes', 'friendlyName' : file_entry.friendly_name, 'colour' : perm.colour, 'starred' : perm.starred } ) temp_file.filename = temp_file.filename.rpartition('/')[2] list_entry.update( { 'filename' : temp_file.filename, 'size' : temp_file.st_size, 'hash' : temp_file.etag, 'timestamp' : temp_file.st_ctime }) temp_group.append(list_entry) if len(temp_group) > 0: file_list.append({ 'catagory' : 'owned', 'heading' : 'Your Files', 'type' : 'files', 'data' : temp_group }) if len(file_list) == 0: file_list.append({ 'catagory' : 'notice', 'type' : 'html', # TODO: move this line out 'data' : '<a data-toggle="modal" data-target="#uploadModal" class="list-group-item">No files - Click here to upload one</a>' }) return HttpResponse(json.dumps(file_list), content_type="application/json")
def test_file_get_file_by_key_success(self): key = ps.add_file( FileInfo( "testFilegfks",ndb.Key("someKey","gfks") ) ) fileobj = ps.get_file_by_key(key) self.assertEqual(fileobj.file_name,"testFilegfks")
def file_preview(request, file = None): app_access = __check_app_access() if app_access is not None: return app_access ## Authentication. authed_user = auth.get_current_user() if authed_user is None: authed_user_nick = 'Guest' else: authed_user_nick = authed_user.nickname() ## Graph visualisation. # Replaced by a spinning canvas on the clientside # if not ds.check_exists(GRAPH_BUCKET + '/' + file_name_without_extension + '.png', None): # file_name_without_extension = None #TODO: Might need to be simplified or moved to a function in fileinfo # TODO the folowing should be replaced by a method in the APIDatastore file_info = ps.get_file_by_name(DATA_BUCKET + '/' + file) undo_uri = None if file_info is not None: prev_file = ps.get_file_by_key(file_info.prev_file_key) if prev_file is not None: undo_uri = prev_file.file_name.rpartition(DATA_BUCKET + '/')[2] lst = ds.list(DATA_BUCKET) current_file = None for temp_file in lst: temp_file.filename = temp_file.filename.rpartition('/')[2] if temp_file.filename == file: current_file = temp_file; # Check whether graph exists yet. graph_exists = ds.check_exists(GRAPH_BUCKET + '/' + file.partition('.')[0] + '.png', None) # Get permissions for file. permissions = None if file_info is not None: user_key = ps.get_user_key_by_id(authed_user.user_id()) permissions = ps.get_user_file_permissions(file_info.key, user_key) template_dict = {'current_file' : current_file, 'name' : file, 'authed_user_nick': authed_user_nick, 'file_info' : file_info, 'graph_ready' : graph_exists, 'undo_link' : undo_uri, 'permissions' : permissions } ## Get gating information. info_path = INFO_BUCKET + '/' + file.partition('.')[0] + '.txt' if ds.check_exists(info_path, None): buffer = ds.open(info_path) if buffer: file_text = buffer.read() stats = file_text.split(' ') if len(stats)>=3: template_dict.update( { 'gating_stats' : { 'selection' : stats[0], 'total' : stats[1], 'percent' : float(stats[2])*100 } } ) ## Get different axis axis_path = INFO_BUCKET + '/' + file.partition('.')[0] + 'info.txt' if ds.check_exists(axis_path, None): buffer = ds.open(axis_path) if buffer: file_text = buffer.read() axis = file_text.split('\n') if len(axis)>0: while '' in axis: axis.remove('') template_dict.update( { 'available_axes' : axis } ) return render(request, 'file_preview.html', template_dict)