home · contact · privacy
Minor template fixes.
[plomtask] / plomtask / http.py
index a2e8fa69fd05d4423751a4fa3ad3623ed4dffe8c..944f79a274f32d2dbb616a5f26eb91e5f6a2efd1 100644 (file)
@@ -5,7 +5,7 @@ from http.server import HTTPServer
 from urllib.parse import urlparse, parse_qs
 from os.path import split as path_split
 from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader
-from plomtask.dating import todays_date
+from plomtask.dating import date_in_n_days
 from plomtask.days import Day
 from plomtask.exceptions import HandledException, BadFormatException, \
         NotFoundException
@@ -113,14 +113,19 @@ class TaskHandler(BaseHTTPRequestHandler):
         """Show Days from ?start= to ?end=."""
         start = self.params.get_str('start')
         end = self.params.get_str('end')
-        days = Day.all(self.conn, date_range=(start, end), fill_gaps=True)
+        if not end:
+            end = date_in_n_days(60)
+        ret = Day.by_date_range_with_limits(self.conn, (start, end), 'id')
+        days, start, end = ret
+        days = Day.with_filled_gaps(days, start, end)
         for day in days:
             day.collect_calendarized_todos(self.conn)
-        return {'start': start, 'end': end, 'days': days}
+        today = date_in_n_days(0)
+        return {'start': start, 'end': end, 'days': days, 'today': today}
 
     def do_GET_day(self) -> dict[str, object]:
         """Show single Day of ?date=."""
-        date = self.params.get_str('date', todays_date())
+        date = self.params.get_str('date', date_in_n_days(0))
         todays_todos = Todo.by_date(self.conn, date)
         conditions_present = []
         enablers_for = {}
@@ -161,18 +166,18 @@ class TaskHandler(BaseHTTPRequestHandler):
         process_id = self.params.get_int_or_none('process_id')
         comment_pattern = self.params.get_str('comment_pattern')
         todos = []
-        for t in Todo.by_date_range(self.conn, (start, end)):
-            if (process_id and t.process.id_ != process_id)\
-                    or (comment_pattern not in t.comment):
-                continue
-            todos += [t]
+        ret = Todo.by_date_range_with_limits(self.conn, (start, end))
+        todos_by_date_range, start, end = ret
+        todos = [t for t in todos_by_date_range
+                 if comment_pattern in t.comment
+                 and ((not process_id) or t.process.id_ == process_id)]
         if sort_by == 'doneness':
             todos.sort(key=lambda t: t.is_done)
         elif sort_by == '-doneness':
             todos.sort(key=lambda t: t.is_done, reverse=True)
-        elif sort_by == 'process':
+        elif sort_by == 'title':
             todos.sort(key=lambda t: t.title_then)
-        elif sort_by == '-process':
+        elif sort_by == '-title':
             todos.sort(key=lambda t: t.title_then, reverse=True)
         elif sort_by == 'comment':
             todos.sort(key=lambda t: t.comment)