annotate libervia/pages/lists/disco/page_meta.py @ 1378:e3e303a30a74

pages (tickets): renamed "tickets" to "lists": "lists" is more generic, and tickets is actually a specific kind of list. /!\ "tickets_trackers_json" option has been renamed to "lists_directory_json".
author Goffi <goffi@goffi.org>
date Thu, 28 Jan 2021 18:51:44 +0100
parents libervia/pages/tickets/disco/page_meta.py@f511f8fbbf8a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
1 #!/usr/bin/env python3
1239
f511f8fbbf8a fixed shebangs
Goffi <goffi@goffi.org>
parents: 1216
diff changeset
2
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from twisted.words.protocols.jabber import jid
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.log import getLogger
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
7
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
8 log = getLogger(__name__)
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
10 name = "lists_disco"
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 access = C.PAGES_ACCESS_PUBLIC
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
12 template = "list/discover.html"
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
14
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 def prepare_render(self, request):
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
16 lists_directory_config = self.host.options["lists_directory_json"]
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
17 if lists_directory_config:
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
18 trackers = request.template_data["lists_directory"] = []
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 try:
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
20 for tracker_data in lists_directory_config:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
21 service = tracker_data["service"]
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
22 node = tracker_data["node"]
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
23 name = tracker_data["name"]
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
24 url = self.getPageByName("lists").getURL(service, node)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
25 trackers.append({"name": name, "url": url})
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 except KeyError as e:
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
27 log.warning("Missing field in lists_directory_json: {msg}".format(msg=e))
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 except Exception as e:
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
29 log.warning("Can't decode lists directory: {msg}".format(msg=e))
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
31
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def on_data_post(self, request):
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
33 jid_str = self.getPostedData(request, "jid")
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
35 jid_ = jid.JID(jid_str)
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 except RuntimeError:
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 self.pageError(request, C.HTTP_BAD_REQUEST)
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 # for now we just use default node
1378
e3e303a30a74 pages (tickets): renamed "tickets" to "lists":
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
39 url = self.getPageByName("lists").getURL(jid_.full(), "@")
1078
296bda6b7ed0 pages (tickets): tickets discovery:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 self.HTTPRedirect(request, url)