Add filters for space launches

This commit is contained in:
Edward Betts 2024-07-01 22:27:19 +03:00
parent c41bcc3304
commit b65d79cb63
3 changed files with 66 additions and 6 deletions

View file

@ -145,10 +145,34 @@ def launch_list() -> str:
now = datetime.now()
data_dir = app.config["DATA_DIR"]
rocket_dir = os.path.join(data_dir, "thespacedevs")
rockets = agenda.thespacedevs.get_launches(rocket_dir, limit=100)
launches = agenda.thespacedevs.get_launches(rocket_dir, limit=100)
mission_type_filter = flask.request.args.get("type")
rocket_filter = flask.request.args.get("rocket")
mission_types = {
launch["mission"]["type"] for launch in launches if launch["mission"]
}
rockets = {launch["rocket"]["full_name"] for launch in launches}
launches = [
launch
for launch in launches
if (
not mission_type_filter
or (launch["mission"] and launch["mission"]["type"] == mission_type_filter)
)
and (not rocket_filter or launch["rocket"]["full_name"] == rocket_filter)
]
return flask.render_template(
"launches.html", rockets=rockets, now=now, get_country=agenda.get_country
"launches.html",
launches=launches,
rockets=rockets,
now=now,
get_country=agenda.get_country,
mission_types=mission_types,
)