def edit(event_id): event = Event.query.filter_by(event_id=event_id).first_or_404() user = User.query.filter_by(id=event.user_id, username=session['username']).first_or_404() # only access their own events form = SellForm(obj=event) f_name = "" extension = "" app.config['UPLOAD_FOLDER'] = os.getcwd() + '/static/images/' if form.validate_on_submit(): original_image = event.imgpath form.populate_obj(event) # Handle event image uploads if form.imgpath.has_file(): f = request.files.get('imgpath') try: extension = os.path.splitext(f.filename)[1] f_name = str(uuid.uuid4()) + extension #encoding the image name + adding extension like jpg, png etc. f_path = os.path.join(app.config['UPLOAD_FOLDER'], f_name) f.save(f_path) #saving the image to static/images event.imgpath = '/static/images/' + f_name except: flash("The image was not uploaded") event.imgpath = original_image # "static/images/"+f_name else: event.imgpath = original_image # Commit changes to event and return to homepage db.session.commit() return redirect(url_for('index')) return render_template('event/edit.html', form=form, event=event, action="edit")
def edit(event_id): event = Event.query.filter_by(event_id=event_id).first_or_404() form = SellForm(obj=event) if form.validate_on_submit(): form.populate_obj(event) #Update form information to database if request.method == 'POST': event.name = request.form['name'] event. """ def editpost(id): post = db.session.query(Post).filter(Post.id==id).first() if request.method == 'POST': title = request.form['title'] text = request.form['content'] post.title = title post.body = content db.session.commit() return redirect(url_for('post', id=id)) else: return render_template('something.html', post=post) """ db.session.commit() return redirect(url_for('index')) return render_template('event/edit.html',form=form, event=event, action='edit')