from datetime import datetime, timedelta

from flask import Blueprint, render_template
from sqlalchemy import and_

from models import Event

blueprint = Blueprint("base", __name__)


@blueprint.route("/")
def index():
    upcoming = Event.query.filter_by(published=True).order_by(Event.start_time).first()
    return render_template("base/index.j2", upcoming=upcoming)


@blueprint.route("/about")
def about():
    return render_template("base/about.j2")


@blueprint.route("/events")
def events():
    eventlist = Event.query.filter(and_(Event.published is True, Event.start_time < (datetime.now() + timedelta(seconds=1)))).order_by(Event.start_time.desc()).all()
    return render_template("base/events.j2", events=eventlist)

@@ -497,24 +497,25 @@
 ():%0A    
+next_
 even
-tlis
 t = Even
@@ -550,18 +550,18 @@
 blished 
-is
+==
  True, E
@@ -580,11 +580,10 @@
 ime 
-%3C (
+%3E 
 date
@@ -596,73 +596,244 @@
 ow()
- + timedelta(seconds=1)))).order_by(Event.start_time.desc()).all(
+)).order_by(Event.start_time).first()%0A    eventlist = Event.query.filter(and_(Event.published == True, Event.start_time %3C datetime.now())).order_by(Event.start_time.desc()).all()%0A    if next_event:%0A        eventlist.insert(0, next_event
 )%0A  

Fix the events page, so that upcoming event shows up.