From: Christian Heller Date: Sat, 16 Mar 2024 23:24:01 +0000 (+0100) Subject: Use different do_GET handlers for different paths. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/todos?a=commitdiff_plain;h=0b9590b2c15c246782d9a81e1df24baa73a09765;p=plomtask Use different do_GET handlers for different paths. --- diff --git a/task.py b/task.py index d6128ee..0b88254 100755 --- 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(): diff --git a/templates/base.html b/templates/base.html index 508281e..427740b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -2,6 +2,8 @@ +calendar | test +
{% block content %} {% endblock %} diff --git a/templates/msg.html b/templates/msg.html new file mode 100644 index 0000000..90cd61c --- /dev/null +++ b/templates/msg.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} + +{% block content %} +

{{msg}}

+{% endblock %} +