Coverage for an_website / quotes / share.py: 92.308%
13 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 19:37 +0000
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-11 19:37 +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"""Share page to share quotes on multiple services."""
16from __future__ import annotations
18from urllib.parse import quote
20from tornado.web import HTTPError
22from .utils import QuoteReadyCheckHandler, get_wrong_quote
25class ShareQuote(QuoteReadyCheckHandler):
26 """Request handler for the share page."""
28 async def get(
29 self, quote_id: str, author_id: str, *, head: bool = False
30 ) -> None:
31 """Handle GET requests to the share page."""
32 wrong_quote = await get_wrong_quote(int(quote_id), int(author_id))
33 if not wrong_quote:
34 raise HTTPError(404, reason="Falsches Zitat nicht gefunden")
35 if head:
36 return
37 text = f"»{wrong_quote.quote.quote}«\n- {wrong_quote.author.name}"
38 await self.render(
39 "pages/quotes/share.html",
40 text=quote(text, safe=""),
41 u_text=text,
42 u_url=(
43 url := self.fix_url(
44 f"/zitate/{quote_id}-{author_id}",
45 include_protocol_and_host=True,
46 )
47 ),
48 quote_url=quote(url, safe=""),
49 wrong_quote=str(wrong_quote),
50 )