home · contact · privacy
Extend POST tests, and handling of missing form data.
[plomtask] / plomtask / http.py
index 1046eccbb1523c784717ca8d5f7a970d11404b85..33961255889a2e00933e6110422ccb02e5aae88d 100644 (file)
@@ -53,7 +53,6 @@ class TaskHandler(BaseHTTPRequestHandler):
                 return
             else:
                 raise NotFoundException(f'Unknown page: /{site}')
-            conn.commit()
             conn.close()
             self._send_html(html)
         except HandledException as error:
@@ -108,6 +107,8 @@ class TaskHandler(BaseHTTPRequestHandler):
                     date: str, postvars: dict[str, list[str]]) -> None:
         """Update or insert Day of date and fields defined in postvars."""
         day = Day.by_date(conn, date, create=True)
+        if 'comment' not in postvars.keys():
+            raise BadFormatException('missing Day.comment value')
         day.comment = postvars['comment'][0]
         day.save(conn)
 
@@ -115,6 +116,12 @@ class TaskHandler(BaseHTTPRequestHandler):
                         postvars: dict[str, list[str]]) -> None:
         """Update or insert Process of id_ and fields defined in postvars."""
         process = Process.by_id(conn, id_, create=True)
+        if 'title' not in postvars.keys():
+            raise BadFormatException('missing Process.title value')
+        if 'description' not in postvars.keys():
+            raise BadFormatException('missing Process.description value')
+        if 'effort' not in postvars.keys():
+            raise BadFormatException('missing Process.effort value')
         process.title.set(postvars['title'][0])
         process.description.set(postvars['description'][0])
         effort = postvars['effort'][0]