Mercurial > libervia-web
annotate libervia/pages/forums/list/page_meta.py @ 1346:cda5537c71d6
browser (photos/album): videos integrations:
videos can now be added to an album, the alternative media player is then used to display
them. Slides options are used to remove pagination and slidebar from slideshow (they don't
play well with media player), and video are reset when its slide is exited.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 25 Aug 2020 08:31:56 +0200 |
parents | f511f8fbbf8a |
children | eaf36fffcbdb |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1058 | 3 |
4 from libervia.server.constants import Const as C | |
5 from twisted.internet import defer | |
6 from sat.core.log import getLogger | |
1080
2c2b8c08e6c9
pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
7 from sat.core.i18n import _ |
1058 | 8 from sat.tools.common import uri as xmpp_uri |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
9 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
10 log = getLogger(__name__) |
1058 | 11 import json |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
12 |
1058 | 13 """forum handling pages""" |
14 | |
1216 | 15 name = "forums" |
1058 | 16 access = C.PAGES_ACCESS_PUBLIC |
1216 | 17 template = "forum/overview.html" |
1058 | 18 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
19 |
1058 | 20 def parse_url(self, request): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
21 self.getPathArgs( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
22 request, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
23 ["service", "node", "forum_key"], |
1216 | 24 service="@jid", |
25 node="@", | |
26 forum_key="", | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
27 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
28 |
1058 | 29 |
30 def getLinks(self, forums): | |
31 for forum in forums: | |
32 try: | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
33 uri = forum["uri"] |
1058 | 34 except KeyError: |
35 pass | |
36 else: | |
37 uri = xmpp_uri.parseXMPPUri(uri) | |
1216 | 38 service = uri["path"] |
39 node = uri["node"] | |
40 forum["http_url"] = self.getPageByName("forum_topics").getURL(service, node) | |
41 if "sub-forums" in forum: | |
42 getLinks(self, forum["sub-forums"]) | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
43 |
1058 | 44 |
45 @defer.inlineCallbacks | |
46 def prepare_render(self, request): | |
47 data = self.getRData(request) | |
48 template_data = request.template_data | |
1216 | 49 service, node, key = data["service"], data["node"], data["forum_key"] |
1058 | 50 profile = self.getProfile(request) or C.SERVICE_PROFILE |
51 | |
1080
2c2b8c08e6c9
pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
52 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
53 forums_raw = yield self.host.bridgeCall( |
1216 | 54 "forumsGet", service.full() if service else "", node, key, profile |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1080
diff
changeset
|
55 ) |
1080
2c2b8c08e6c9
pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
56 except Exception as e: |
1216 | 57 log.warning(_("Can't retrieve forums: {msg}").format(msg=e)) |
1080
2c2b8c08e6c9
pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
58 forums = [] |
2c2b8c08e6c9
pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
59 else: |
2c2b8c08e6c9
pages (forums): log a warning and use an empty list when forums are not available
Goffi <goffi@goffi.org>
parents:
1058
diff
changeset
|
60 forums = json.loads(forums_raw) |
1058 | 61 getLinks(self, forums) |
62 | |
1216 | 63 template_data["forums"] = forums |