def new_event():
    form = EventForm()
    if form.validate_on_submit():
        event = Event(start=form.start.data,
                      end=form.end.data,
                      subject=form.subject.data,
                      description=form.description.data,
                      author=current_user)
        db.session.add(event)
        db.session.commit()
        flash('Your event has been created!', 'success')
        return redirect(url_for('home'))
    return render_template('create_event.html',
                           title='New Event',
                           form=form,
                           legend='New Event')
def update_event(event_id):
    event = Event.query.get_or_404(event_id)
    if event.author != current_user:
        abort(403)
    form = EventForm()
    if form.validate_on_submit():
        event.start = form.start.data
        event.end = form.end.data
        event.subject = form.subject.data
        event.description = form.description.data
        db.session.commit()
        flash('Your event has been updated!', 'success')
        return redirect(url_for('event', event_id=event.id))
    elif request.method == 'GET':
        form.start.data = event.start
        form.end.data = event.end
        form.subject.data = event.subject
        form.description.data = event.description
    return render_template('create_event.html',
                           title='Update Event',
                           form=form,
                           legend='Update Event')