Mercurial > libervia-web
annotate libervia/pages/forums/topics/page_meta.py @ 1463:2c8449885272
pages: query parameters can now be specified using keyword arguments in `getURL:`
rel: 399
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 30 Sep 2021 16:57:54 +0200 |
parents | fa6fe9511aca |
children | ce879da7fcf7 |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1058 | 3 |
4 from libervia.server.constants import Const as C | |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
5 from sat.core.i18n import _, D_ |
1058 | 6 from sat.core.log import getLogger |
7 from sat.tools.common import uri as xmpp_uri | |
1243
8aff742d0dd0
pages: updated `identityGet` call, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
8 from sat.tools.common import data_format |
1270
6dfcdbeb0d33
pages: handle themes using `theme` request argument
Goffi <goffi@goffi.org>
parents:
1266
diff
changeset
|
9 from libervia.server import session_iface |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
10 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
11 log = getLogger(__name__) |
1058 | 12 |
1216 | 13 name = "forum_topics" |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
14 label = D_("Forum Topics") |
1058 | 15 access = C.PAGES_ACCESS_PUBLIC |
1216 | 16 template = "forum/view_topics.html" |
1058 | 17 |
18 | |
19 def parse_url(self, request): | |
1216 | 20 self.getPathArgs(request, ["service", "node"], 2, service="jid") |
1058 | 21 |
22 | |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
23 def add_breadcrumb(self, request, breadcrumbs): |
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
24 data = self.getRData(request) |
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
25 breadcrumbs.append({ |
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
26 "label": label, |
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
27 "url": self.getURL(data["service"].full(), data["node"]) |
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
28 }) |
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
29 |
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
30 |
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
31 async def prepare_render(self, request): |
1058 | 32 profile = self.getProfile(request) or C.SERVICE_PROFILE |
33 data = self.getRData(request) | |
1216 | 34 service, node = data["service"], data["node"] |
35 request.template_data.update({"service": service, "node": node}) | |
1058 | 36 template_data = request.template_data |
1432
fa6fe9511aca
pages (forums/topics): deserialise extra + use pagination
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
37 page_max = data.get("page_max", 20) |
fa6fe9511aca
pages (forums/topics): deserialise extra + use pagination
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
38 extra = self.getPubsubExtra(request, page_max=page_max) |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
39 topics, metadata = await self.host.bridgeCall( |
1432
fa6fe9511aca
pages (forums/topics): deserialise extra + use pagination
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
40 "forumTopicsGet", |
fa6fe9511aca
pages (forums/topics): deserialise extra + use pagination
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
41 service.full(), |
fa6fe9511aca
pages (forums/topics): deserialise extra + use pagination
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
42 node, |
fa6fe9511aca
pages (forums/topics): deserialise extra + use pagination
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
43 extra, |
fa6fe9511aca
pages (forums/topics): deserialise extra + use pagination
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
44 profile |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
45 ) |
1432
fa6fe9511aca
pages (forums/topics): deserialise extra + use pagination
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
46 metadata = data_format.deserialise(metadata) |
fa6fe9511aca
pages (forums/topics): deserialise extra + use pagination
Goffi <goffi@goffi.org>
parents:
1427
diff
changeset
|
47 self.setPagination(request, metadata) |
1266
6b7f9c3558cc
server, pages: better identities handling:
Goffi <goffi@goffi.org>
parents:
1243
diff
changeset
|
48 identities = self.host.getSessionData( |
6b7f9c3558cc
server, pages: better identities handling:
Goffi <goffi@goffi.org>
parents:
1243
diff
changeset
|
49 request, session_iface.ISATSession |
6b7f9c3558cc
server, pages: better identities handling:
Goffi <goffi@goffi.org>
parents:
1243
diff
changeset
|
50 ).identities |
1058 | 51 for topic in topics: |
1216 | 52 parsed_uri = xmpp_uri.parseXMPPUri(topic["uri"]) |
53 author = topic["author"] | |
54 topic["http_uri"] = self.getPageByName("forum_view").getURL( | |
55 parsed_uri["path"], parsed_uri["node"] | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
56 ) |
1058 | 57 if author not in identities: |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
58 id_raw = await self.host.bridgeCall( |
1243
8aff742d0dd0
pages: updated `identityGet` call, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
59 "identityGet", author, [], True, profile |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
60 ) |
1243
8aff742d0dd0
pages: updated `identityGet` call, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
61 identities[topic["author"]] = data_format.deserialise(id_raw) |
8aff742d0dd0
pages: updated `identityGet` call, following backend changes
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
62 |
1216 | 63 template_data["topics"] = topics |
1425
bcd6ad99b2b0
pages (forums/topics): add url to new topic creation page
Goffi <goffi@goffi.org>
parents:
1270
diff
changeset
|
64 template_data["url_topic_new"] = self.getSubPageURL(request, "forum_topic_new") |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
65 |
1058 | 66 |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
67 async def on_data_post(self, request): |
1058 | 68 profile = self.getProfile(request) |
69 if profile is None: | |
1173
0f37b65fe7c2
server: replaced wrong usage of C.HTTP_UNAUTHORIZED by C.HTTP_FORBIDDEN
Goffi <goffi@goffi.org>
parents:
1145
diff
changeset
|
70 self.pageError(request, C.HTTP_FORBIDDEN) |
1216 | 71 type_ = self.getPostedData(request, "type") |
72 if type_ == "new_topic": | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
73 service, node, title, body = self.getPostedData( |
1216 | 74 request, ("service", "node", "title", "body") |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
75 ) |
1058 | 76 |
77 if not title or not body: | |
78 self.pageError(request, C.HTTP_BAD_REQUEST) | |
1216 | 79 topic_data = {"title": title, "content": body} |
1058 | 80 try: |
1427
eaf36fffcbdb
pages (forums): better breadcrumbs
Goffi <goffi@goffi.org>
parents:
1425
diff
changeset
|
81 await self.host.bridgeCall( |
1216 | 82 "forumTopicCreate", service, node, topic_data, profile |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
83 ) |
1058 | 84 except Exception as e: |
1216 | 85 if "forbidden" in str(e): |
1058 | 86 self.pageError(request, 401) |
87 else: | |
88 raise e | |
89 else: | |
1216 | 90 log.warning(_("Unhandled data type: {}").format(type_)) |