def post(self): self.response.headers['Content-Type'] = 'text/html' button_value = self.request.get('button') if button_value == 'Add': absolute_name = re.sub(r"[/;]", '', self.request.get('value')).lstrip() if not (absolute_name is None or absolute_name == ''): dir_operations.add_dir(absolute_name, dir_operations.get_key_of_current_dir()) self.redirect('/') elif button_value == 'Delete': name, kind = self.request.get('name'), self.request.get('kind') if kind == 'file': file_operations.delete(name) elif kind == 'directory': dir_operations.deleting_directory(name) self.redirect('/') elif button_value == 'Up': user = user_operations.get_user_for_model() if not dir_operations.is_in_root_directory(): user.c_dir = dir_operations.get_the_key_of_parent_directory() user.put() self.redirect('/') elif button_value == 'Home': user = user_operations.get_user_for_model() user.c_dir = ndb.Key(Folder, user.key.id() + dir_operations.slash) user.put() self.redirect('/')
def delete(name): user = user_operations.get_user_for_model() object = obj_of_current_dir() p = getting_path(name, object) id = user.key.id() + p key = ndb.Key("File", id) blobobj = key.get().blob object.files.remove(key) blobstore.delete(blobobj) key.delete() object.put()
def deleting_directory(name): my_user = user_operations.get_user_for_model() parent_directory_object = obj_of_current_dir() directory_id = my_user.key.id() + getting_path(name, parent_directory_object) directory_key = ndb.Key("Folder", directory_id) directory_object = directory_key.get() if check_if_directory_is_empty(directory_object): parent_directory_object.directs.remove(directory_key) parent_directory_object.put() directory_key.delete()
def add_dir(name, parent): user = user_operations.get_user_for_model() parent_object = parent.get() p = getting_path(name, parent_object) id = user.key.id() + p dir = modelfolder(id=id) dir_key = dir.key if nocontain(dir_key, parent_object.directs): parent_object.directs.append(dir_key) parent_object.put() dir.root_dir = parent dir.name = name dir.path = p dir.put() else: print "Directory Exists"
def adding(upload, filename, datetime): user = user_operations.get_user_for_model() current_dir = obj_of_current_dir() id = user.key.id() + getting_path(filename, current_dir) key = ndb.Key("File", id) if nocontain(key, current_dir.files): object = File(id=id) object.name = filename object.date = datetime object.blob = upload.key() object.put() current_dir.files.append(key) current_dir.put() return "file added!" else: blobstore.delete(upload.key()) return "A file with this name already exists in this directory!"
def home(): user = user_operations.get_user_for_model() user.c_dir = ndb.Key("Folder", user.key.id() + slash) user.put()
def nav_dir(name): user = user_operations.get_user_for_model() path = user.key.id() + getting_path(name, obj_of_current_dir()) key = ndb.Key("Folder", path) user.c_dir = key user.put()
def get_key_of_current_dir(): user = user_operations.get_user_for_model() return user.c_dir
def obj_of_file(file_name): user = user_operations.get_user_for_model() root_dir_object = obj_of_current_dir() path = getting_path(file_name, root_dir_object) id = user.key.id() + path return ndb.Key("File", id).get()