home · contact · privacy
Use different do_GET handlers for different paths.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 16 Mar 2024 23:24:01 +0000 (00:24 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 16 Mar 2024 23:24:01 +0000 (00:24 +0100)
task.py
templates/base.html
templates/msg.html [new file with mode: 0644]

diff --git a/task.py b/task.py
index d6128eeed5fc20d0d919a91dc3c00fea14ad4150..0b8825476353fff066f4b5480c7fcbf2d5ef00b5 100755 (executable)
--- a/task.py
+++ b/task.py
@@ -1,9 +1,9 @@
 #!/usr/bin/env python3
-"""
-plom's task manager
-"""
+"""plom's task manager"""
 from http.server import BaseHTTPRequestHandler
 from http.server import HTTPServer
+from urllib.parse import urlparse
+from os.path import split as path_split
 from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader
 from days import Day
 
@@ -20,13 +20,27 @@ class TaskHandler(BaseHTTPRequestHandler):
 
     def do_GET(self):
         """Handle any GET request."""
+        parsed_url = urlparse(self.path)
+        site = path_split(parsed_url.path)[1]
+        if 'calendar' == site:
+            html = self.do_GET_calendar()
+        else:
+            html = self.do_GET_msg('I have nothing to say at this point.')
         self.send_response(200)
         self.end_headers()
+        self.wfile.write(bytes(html, 'utf-8'))
+
+    def do_GET_msg(self, msg):
+        """Show message."""
+        return self.server.jinja.get_template('msg.html').render(
+                msg=msg)
+
+    def do_GET_calendar(self):
+        """Show sorted Days."""
         days = [Day('2024-01-03'), Day('2024-01-01'), Day('2024-01-02')]
         days.sort()
-        html = self.server.jinja.get_template('calendar.html').render(
+        return self.server.jinja.get_template('calendar.html').render(
                 days=days)
-        self.wfile.write(bytes(html, 'utf-8'))
 
 
 def main():
index 508281e4fa53863d8a0a8311e6189d0ccdc220bf..427740bf4318da2cdcdd7416cd0e57d9ab9b22f7 100644 (file)
@@ -2,6 +2,8 @@
 <html>
 <meta charset="UTF-8">
 <body>
+<a href="calendar">calendar</a> | <a href="test">test</a>
+<hr>
 {% block content %}
 {% endblock %}
 </body>
diff --git a/templates/msg.html b/templates/msg.html
new file mode 100644 (file)
index 0000000..90cd61c
--- /dev/null
@@ -0,0 +1,6 @@
+{% extends 'base.html' %}
+
+{% block content %}
+<p>{{msg}}</p>
+{% endblock %}
+