X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=plomtask%2Fhttp.py;h=afcaa116173145bb2ab5b2547937d5458d3e2666;hb=9e32ae00d4435932d55695be4e757ff109c76f26;hp=b6019ef0761b1dc3a86d3a12f395cd5b96f40c5c;hpb=a8ee9d57c7ec297ef93d616141ac8970869fb6ef;p=plomtask diff --git a/plomtask/http.py b/plomtask/http.py index b6019ef..afcaa11 100644 --- a/plomtask/http.py +++ b/plomtask/http.py @@ -22,17 +22,6 @@ class TaskHandler(BaseHTTPRequestHandler): """Handles single HTTP request.""" server: TaskServer - def send_html(self, html: str, code: int = 200): - """Send HTML as proper HTTP response.""" - self.send_response(code) - self.end_headers() - self.wfile.write(bytes(html, 'utf-8')) - - def send_msg(self, msg: str, code: int = 400): - """Send message in HTML formatting as HTTP response.""" - html = self.server.jinja.get_template('msg.html').render(msg=msg) - self.send_html(html, code) - def do_GET(self): """Handle any GET request.""" try: @@ -49,9 +38,9 @@ class TaskHandler(BaseHTTPRequestHandler): raise HandledException('Test!') conn.commit() conn.close() - self.send_html(html) + self._send_html(html) except HandledException as error: - self.send_msg(error) + self._send_msg(error) def do_GET_calendar(self, conn: DatabaseConnection): """Show Days.""" @@ -62,3 +51,14 @@ class TaskHandler(BaseHTTPRequestHandler): """Show single Day.""" day = Day.by_date(conn, date) return self.server.jinja.get_template('day.html').render(day=day) + + def _send_html(self, html: str, code: int = 200): + """Send HTML as proper HTTP response.""" + self.send_response(code) + self.end_headers() + self.wfile.write(bytes(html, 'utf-8')) + + def _send_msg(self, msg: str, code: int = 400): + """Send message in HTML formatting as HTTP response.""" + html = self.server.jinja.get_template('msg.html').render(msg=msg) + self._send_html(html, code)