def addDir(dir_id): name = request.form.get('name') parent_dir = Directory.query.filter_by(id=dir_id).one() path = os.path.join(parent_dir.path, parent_dir.name) newDir = Directory(dir_id, name, path) db.session.add(newDir) db.session.commit() os.mkdir(os.path.join(STORAGE, path, name), 511) return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' }
def walk(self, path, include_files=True): """ Walk 'path' and map the directories into the main vTree """ # add the last directory in the 'path' as our top level # directory in the vTree base_path = os.path.dirname(path) root_dir = os.path.basename(path) os.chdir(base_path) if os.path.isdir(root_dir): self.dirs.append(Directory(path=root_dir)) else: print "Error: Could not find %s" % path return for root, dirs, files in os.walk(root_dir): for directory in dirs: self.dirs.append(Directory(path="%s/%s" % (root, directory))) if include_files: for fl in files: self.files.append(File(path="%s/%s" % (root, fl)))
def post(self): """ Создание новой директории внутри существующей директории """ if self.dir_exists(): self.error(400, 'Directory already exists') else: if self.parent_exists(): parent, name = self.split_parent_dir() Directory(path=parent, name=name).put() else: self.error(404, 'Parent directory doesn\'t exist')
def suggest(): form = suggestForm(request.form) if form.validate(): title = form.title.data url = form.url.data desc = form.description.data email = form.email.data cat = form.category.data new_dir = Directory(url, title, desc, cat) db.session.add(new_dir) db.session.commit() return redirect(url_for('index')) else: print 'wrong input' return render_template('suggest.html', form=form)