Coverage for an_website/main_page/main_page.py: 100.000%
16 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-16 19:56 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-16 19:56 +0000
1# This program is free software: you can redistribute it and/or modify
2# it under the terms of the GNU Affero General Public License as
3# published by the Free Software Foundation, either version 3 of the
4# License, or (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU Affero General Public License for more details.
10#
11# You should have received a copy of the GNU Affero General Public License
12# along with this program. If not, see <https://www.gnu.org/licenses/>.
14"""The main page of the website."""
16from __future__ import annotations
18import contextlib
20from ..quotes.quote_of_the_day import QuoteOfTheDayBaseHandler
21from ..utils.utils import ModuleInfo
24def get_module_info() -> ModuleInfo:
25 """Create and return the ModuleInfo for this module."""
26 return ModuleInfo(
27 # the empty dict prevents the header from being changed
28 handlers=((r"/", MainPage, {}),),
29 name="Hauptseite",
30 description="Die Hauptseite der Webseite",
31 path="/",
32 keywords=("asozial", "Asoziales", "Netzwerk"),
33 )
36class MainPage(QuoteOfTheDayBaseHandler):
37 """The request handler of the main page."""
39 async def check_ready(self) -> None: # noqa: D102
40 pass
42 async def get(self, *, head: bool = False) -> None:
43 """Handle GET requests to the main page."""
44 if head:
45 return
46 quote_data = None
47 if self.redis: # type: ignore[truthy-bool]
48 with contextlib.suppress(Exception):
49 quote_data = await self.get_quote_of_today()
50 await self.render("pages/main_page.html", quote_data=quote_data)