home · contact · privacy
Overhaul caching.
[plomtask] / plomtask / http.py
index 230ed3f26c5d53398a27d87558a28abeb28ceff5..fc0059c530e20c5e347a264703905b3fcadcb3df 100644 (file)
@@ -139,8 +139,11 @@ class TaskHandler(BaseHTTPRequestHandler):
                         msg = f'{not_found_msg}: {self._site}'
                         raise NotFoundException(msg)
                 except HandledException as error:
-                    html = self.server.jinja.\
-                            get_template('msg.html').render(msg=error)
+                    for cls in (Day, Todo, Condition, Process, ProcessStep):
+                        assert hasattr(cls, 'empty_cache')
+                        cls.empty_cache()
+                    tmpl = self.server.jinja.get_template('msg.html')
+                    html = tmpl.render(msg=error)
                     self._send_html(html, error.http_code)
                 finally:
                     self.conn.close()
@@ -205,8 +208,7 @@ class TaskHandler(BaseHTTPRequestHandler):
     def do_GET_day(self) -> dict[str, object]:
         """Show single Day of ?date=."""
         date = self._params.get_str('date', date_in_n_days(0))
-        day = Day.by_id(self.conn, date, create=True,
-                        init_empty_todo_list=True)
+        day = Day.by_id(self.conn, date, create=True)
         make_type = self._params.get_str('make_type')
         conditions_present = []
         enablers_for = {}
@@ -482,10 +484,6 @@ class TaskHandler(BaseHTTPRequestHandler):
             if len(efforts) > 0:
                 todo.effort = float(efforts[i]) if efforts[i] else None
             todo.save(self.conn)
-            for condition in todo.enables:
-                condition.save(self.conn)
-            for condition in todo.disables:
-                condition.save(self.conn)
         return f'/day?date={date}&make_type={make_type}'
 
     def do_POST_todo(self) -> str:
@@ -541,10 +539,6 @@ class TaskHandler(BaseHTTPRequestHandler):
         todo.calendarize = len(self._form_data.get_all_str('calendarize')) > 0
         todo.comment = self._form_data.get_str('comment', ignore_strict=True)
         todo.save(self.conn)
-        for condition in todo.enables:
-            condition.save(self.conn)
-        for condition in todo.disables:
-            condition.save(self.conn)
         return f'/todo?id={todo.id_}'
 
     def do_POST_process_descriptions(self) -> str:
@@ -606,12 +600,10 @@ class TaskHandler(BaseHTTPRequestHandler):
                                       None)]
             except ValueError:
                 new_step_title = step_identifier
-        process.uncache()
         process.set_steps(self.conn, steps)
         process.set_step_suppressions(self.conn,
                                       self._form_data.
                                       get_all_int('suppresses'))
-        process.save(self.conn)
         owners_to_set = []
         new_owner_title = None
         for owner_identifier in self._form_data.get_all_str('step_of'):
@@ -627,6 +619,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         elif new_owner_title:
             title_b64_encoded = b64encode(new_owner_title.encode()).decode()
             params = f'has_step={process.id_}&title_b64={title_b64_encoded}'
+        process.save(self.conn)
         return f'/process?{params}'
 
     def do_POST_condition_descriptions(self) -> str: