def add_project(project): db = connect_db(app.config.get('DB')) Project.set_db(db) # db_project = Project() db_project.author = project['author'] db_project.title = project['title'] db_project.start_date = datetime.date.today() db_project.due_date = datetime.date.today() db_project.text = project['descr'] # db.save_doc(db_project)
def add_project(project): db = connect_db(app.config.get("DB")) Project.set_db(db) # db_project = Project() db_project.author = project["author"] db_project.title = project["title"] db_project.start_date = datetime.date.today() db_project.due_date = datetime.date.today() db_project.text = project["descr"] # db.save_doc(db_project)
def edit(id): errors = [] form = EditProjectForm(request.form) project = None if id == NEW_PROJECT_ID: project = Project() else: if not g.db.doc_exist(id): abort(404) project = Project.get(id) if request.method == 'GET': form = EditProjectForm(obj=project) pass if request.method == 'POST' and form.validate(): form.populate_obj(project) project.author = session['username'] ''' if id != NEW_PROJECT_ID: for ff in request.files.keys(): f = request.files[ff] if f: fname = secure_filename(f.filename) fld = os.path.join(UPLOADED_FILES, id) if not os.path.exists(fld): os.mkdir(fld) target_path = os.path.join(fld, fname) while os.path.exists(target_path): filename, ext = os.path.splitext(target_path) r = ''.join(random.choice('0123456789abcdef') for i in range(8)) target_path = os.path.join(fld, filename + '-' + r + ext) f.save(target_path) flash('Successfully uploaded %s' % fname) ''' project.save() flash('Project was successfully %s' % ('created' if id == NEW_PROJECT_ID else 'updated')) return redirect(url_for('index.index')) errors.extend(format_form_errors(form.errors.items())) return render_template('project_edit.html', id=id, form=form, errors=errors)
def edit(id): errors = [] form = EditProjectForm(request.form) project = None if id == NEW_PROJECT_ID: project = Project() else: if not g.db.doc_exist(id): abort(404) project = Project.get(id) if request.method == 'GET': form = EditProjectForm(obj=project) pass if request.method == 'POST' and form.validate(): form.populate_obj(project) project.author = session['username'] ''' if id != NEW_PROJECT_ID: for ff in request.files.keys(): f = request.files[ff] if f: fname = secure_filename(f.filename) fld = os.path.join(UPLOADED_FILES, id) if not os.path.exists(fld): os.mkdir(fld) target_path = os.path.join(fld, fname) while os.path.exists(target_path): filename, ext = os.path.splitext(target_path) r = ''.join(random.choice('0123456789abcdef') for i in range(8)) target_path = os.path.join(fld, filename + '-' + r + ext) f.save(target_path) flash('Successfully uploaded %s' % fname) ''' project.save() flash('Project was successfully %s' % ('created' if id == NEW_PROJECT_ID else 'updated')) return redirect(url_for('index.index')) errors.extend(format_form_errors(form.errors.items())) return render_template('project_edit.html', id = id, form = form, errors = errors)