home · contact · privacy
Collect GET /calendar range from "?start=" and "?end=".
authorChristian Heller <c.heller@plomlompom.de>
Wed, 20 Mar 2024 02:33:17 +0000 (03:33 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 20 Mar 2024 02:33:17 +0000 (03:33 +0100)
plomtask/http.py
tests/test_days.py

index 0af96e7538c2cefd9febd1ac55dedc6fd95f4f90..b698fcbef94b73d790c6346e9bc8db7b5f4e7e33 100644 (file)
@@ -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."""
index e25eafdbf00856a85738d00a49907ebac2a7c642..2adf7657a46f2f7d49102c7aa3db06bbcc117302 100644 (file)
@@ -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()