Add loading existing cars on page load. First part of #2
This commit is contained in:
@@ -4,7 +4,7 @@ import json
|
||||
import dbus
|
||||
from urllib.parse import parse_qs
|
||||
from ac_tracks import change_track, get_all_tracks, get_configs, get_preview_image, get_outline_image
|
||||
from ac_cars import get_all_cars, get_car_image, update_cars
|
||||
from ac_cars import get_all_cars, get_car_image, update_cars, get_current_cars
|
||||
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
@@ -35,6 +35,8 @@ class Handler(BaseHTTPRequestHandler):
|
||||
|
||||
if self.path == "/cars":
|
||||
return self.handle_get_cars_path()
|
||||
if self.path == "/currentcars":
|
||||
return self.handle_get_current_cars_path()
|
||||
|
||||
if self.path == "/" or self.path == "/index.html":
|
||||
return self.handle_get_root_path()
|
||||
@@ -99,6 +101,18 @@ class Handler(BaseHTTPRequestHandler):
|
||||
self.wfile.write(json.dumps(data).encode())
|
||||
return True
|
||||
|
||||
def handle_get_current_cars_path(self):
|
||||
cars = get_current_cars()
|
||||
data = {
|
||||
"cars": cars
|
||||
}
|
||||
|
||||
self.send_response(200)
|
||||
self.send_header("Content-type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(json.dumps(data).encode())
|
||||
return True
|
||||
|
||||
def handle_get_root_path(self):
|
||||
with open("index.html", "r") as f:
|
||||
html = f.read()
|
||||
|
||||
Reference in New Issue
Block a user