From ad11ec7f93dca356748cb6c8bc49313a7ee7c3d7 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Mon, 30 Jan 2023 22:26:19 -0600 Subject: Add form for new form --- Dockerfile | 2 +- docker-compose.yml | 2 + index.html | 247 --------------------------------------------------- server.py | 24 ++++- static/index.html | 247 +++++++++++++++++++++++++++++++++++++++++++++++++++ static/new_form.html | 74 +++++++++++++++ 6 files changed, 344 insertions(+), 252 deletions(-) delete mode 100644 index.html create mode 100644 static/index.html create mode 100644 static/new_form.html diff --git a/Dockerfile b/Dockerfile index 412b929..2270d51 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM ubuntu RUN apt update -y && apt install -y python3-pip RUN pip install psycopg2-binary -COPY index.html /src/index.html +#COPY static /src/static COPY server.py /src/server.py WORKDIR /src diff --git a/docker-compose.yml b/docker-compose.yml index ee1518d..bad313e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,8 @@ services: - 60934:8000 environment: PYTHONUNBUFFERED: 1 + volumes: + - ./static:/src/static grafana: image: grafana/grafana restart: always diff --git a/index.html b/index.html deleted file mode 100644 index 83136dc..0000000 --- a/index.html +++ /dev/null @@ -1,247 +0,0 @@ - - - - - - - -
-
-
-
- -
- - diff --git a/server.py b/server.py index be69c04..b678cf0 100644 --- a/server.py +++ b/server.py @@ -30,14 +30,19 @@ class TrackerHTTPRequestHandler(BaseHTTPRequestHandler): cur.execute("UPDATE book SET completed = TRUE where id = %s", (book_id,)) conn.commit() + def send_static_file(self, path): + with open(f"static/{path}", "rb") as f: + self.send_response(200) + self.end_headers() + self.wfile.write(f.read()) + def do_GET(self): u = urlparse(self.path) print("GET", u.path) if u.path == "/": - with open("index.html", "rb") as f: - self.send_response(200) - self.end_headers() - self.wfile.write(f.read()) + self.send_static_file("index.html") + elif u.path == "/new_form": + self.send_static_file("new_form.html") elif date_pattern.match(u.path[1:]): with conn.cursor() as cur: cur.execute("SELECT datatype, key, value FROM datapoint where date(created) = %s", (u.path[1:],)) @@ -106,6 +111,17 @@ class TrackerHTTPRequestHandler(BaseHTTPRequestHandler): self.send_response(204) self.end_headers() self.wfile.write(b"") + elif u.path == "/submit_new_form": + prompt_type = post_data.pop("type") + prompt = post_data.pop("prompt") + prompt_id = post_data.pop("prompt_id") + extra = json.dumps(post_data) + with conn.cursor() as cur: + cur.execute("INSERT INTO form (type, prompt, prompt_id, extra) VALUES (%s, %s, %s, %s)", (prompt_type, prompt, prompt_id, extra)) + conn.commit() + self.send_response(204) + self.end_headers() + self.wfile.write(b"") else: self.send_response(404) self.end_headers() diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..83136dc --- /dev/null +++ b/static/index.html @@ -0,0 +1,247 @@ + + + + + + + +
+
+
+
+ +
+ + diff --git a/static/new_form.html b/static/new_form.html new file mode 100644 index 0000000..7022d5a --- /dev/null +++ b/static/new_form.html @@ -0,0 +1,74 @@ + + + + + + +
+ +
+ + +
+ +
+ + +
+
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+ +
+ + -- cgit v1.2.3