From: Christian Heller Date: Wed, 20 Mar 2024 02:33:17 +0000 (+0100) Subject: Collect GET /calendar range from "?start=" and "?end=". X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%7B%7Bdb.prefix%7D%7D/do_todos?a=commitdiff_plain;h=836c33fc94dbb75d241717b7db6a3718edcc0464;p=plomtask Collect GET /calendar range from "?start=" and "?end=". --- diff --git a/plomtask/http.py b/plomtask/http.py index 0af96e7..b698fcb 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -29,7 +29,9 @@ class TaskHandler(BaseHTTPRequestHandler): try: conn, site, params = self._init_handling() if 'calendar' == site: - html = self.do_GET_calendar(conn) + start = params.get('start', [''])[0] + end = params.get('end', [''])[0] + html = self.do_GET_calendar(conn, start, end) elif 'day' == site: date = params.get('date', [todays_date()])[0] html = self.do_GET_day(conn, date) @@ -41,10 +43,10 @@ class TaskHandler(BaseHTTPRequestHandler): except HandledException as error: self._send_msg(error) - def do_GET_calendar(self, conn: DatabaseConnection): + def do_GET_calendar(self, conn: DatabaseConnection, start: str, end: str): """Show Days.""" return self.server.jinja.get_template('calendar.html').render( - days=Day.all(conn)) + days=Day.all(conn, date_range=(start, end))) def do_GET_day(self, conn: DatabaseConnection, date: str): """Show single Day.""" diff --git a/tests/test_days.py b/tests/test_days.py index e25eafd..2adf765 100644 --- a/tests/test_days.py +++ b/tests/test_days.py @@ -145,6 +145,14 @@ class TestsWithServer(TestsWithDB): self.assertEqual(http_conn.getresponse().status, 400) http_conn.request('GET', '/calendar') self.assertEqual(http_conn.getresponse().status, 200) + http_conn.request('GET', '/calendar?start=&end=') + self.assertEqual(http_conn.getresponse().status, 200) + http_conn.request('GET', '/calendar?start=today&end=today') + self.assertEqual(http_conn.getresponse().status, 200) + http_conn.request('GET', '/calendar?start=2024-01-01&end=2025-01-01') + self.assertEqual(http_conn.getresponse().status, 200) + http_conn.request('GET', '/calendar?start=foo') + self.assertEqual(http_conn.getresponse().status, 400) def tearDown(self): self.httpd.shutdown()