annotate libervia/pages/blog/page_meta.py @ 1245:079e8eb6e327

server (tasks): refactoring: - moved `TasksManager` to `server.tasks.manager` - tasks modules now must have a `Task` class which will be instanciated by TasksManager - `server.tasks.task` has a basis for `Task` class - `Task.prepare` can now be asynchronous - `importlib` is now used to import tasks, instead of exec - tasks are now parsed/run after pages are imported - `server.BackendReady` is now a coroutine - type hinting for Task attributes
author Goffi <goffi@goffi.org>
date Sat, 25 Apr 2020 16:08:55 +0200
parents 8aff742d0dd0
children 6b7f9c3558cc
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
1139
e45480b6ba24 pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
3 from sat.core.i18n import _
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from libervia.server.constants import Const as C
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from twisted.words.protocols.jabber import jid
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from twisted.internet import defer
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from libervia.server import session_iface
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
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 from sat.core.log import getLogger
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1139
diff changeset
11 log = getLogger(__name__)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
12
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
13 name = "blog"
1079
3af28f84ce91 pages (blog): blog page is now public (only free jid is available when not connected)
Goffi <goffi@goffi.org>
parents: 1077
diff changeset
14 access = C.PAGES_ACCESS_PUBLIC
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
15 template = "blog/discover.html"
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
17
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 @defer.inlineCallbacks
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 def prepare_render(self, request):
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 profile = self.getProfile(request)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 template_data = request.template_data
1079
3af28f84ce91 pages (blog): blog page is now public (only free jid is available when not connected)
Goffi <goffi@goffi.org>
parents: 1077
diff changeset
22 if profile is not None:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
23 __, entities_own, entities_roster = yield self.host.bridgeCall(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
24 "discoFindByFeatures",
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
25 [],
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
26 [("pubsub", "pep")],
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
27 True,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
28 False,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
29 True,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
30 True,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
31 True,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
32 profile,
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
33 )
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
34 entities = template_data["disco_entities"] = (
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
35 list(entities_own.keys()) + list(entities_roster.keys())
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
36 )
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
37 entities_url = template_data["entities_url"] = {}
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
38 identities = template_data["identities"] = self.host.getSessionData(
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
39 request, session_iface.ISATSession
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
40 ).identities
1139
e45480b6ba24 pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
41 d_list = []
1079
3af28f84ce91 pages (blog): blog page is now public (only free jid is available when not connected)
Goffi <goffi@goffi.org>
parents: 1077
diff changeset
42 for entity_jid_s in entities:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
43 entities_url[entity_jid_s] = self.getPageByName("blog_view").getURL(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
44 entity_jid_s
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
45 )
1079
3af28f84ce91 pages (blog): blog page is now public (only free jid is available when not connected)
Goffi <goffi@goffi.org>
parents: 1077
diff changeset
46 if entity_jid_s not in identities:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
47 d_list.append(self.host.bridgeCall("identityGet",
1139
e45480b6ba24 pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
48 entity_jid_s,
1243
8aff742d0dd0 pages: updated `identityGet` call, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
49 [],
8aff742d0dd0 pages: updated `identityGet` call, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
50 True,
1139
e45480b6ba24 pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
51 profile))
e45480b6ba24 pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
52 identities_data = yield defer.DeferredList(d_list)
1243
8aff742d0dd0 pages: updated `identityGet` call, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
53 for idx, (success, identity_raw) in enumerate(identities_data):
1139
e45480b6ba24 pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
54 entity_jid_s = entities[idx]
e45480b6ba24 pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
55 if not success:
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
56 log.warning(_("Can't retrieve identity of {entity}")
1139
e45480b6ba24 pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
57 .format(entity=entity_jid_s))
e45480b6ba24 pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
58 else:
1243
8aff742d0dd0 pages: updated `identityGet` call, following backend changes
Goffi <goffi@goffi.org>
parents: 1239
diff changeset
59 identities[entity_jid_s] = data_format.deserialise(identity_raw)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
60
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 def on_data_post(self, request):
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
63 jid_str = self.getPostedData(request, "jid")
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
65 jid_ = jid.JID(jid_str)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 except RuntimeError:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 self.pageError(request, C.HTTP_BAD_REQUEST)
1216
b2d067339de3 python 3 port:
Goffi <goffi@goffi.org>
parents: 1145
diff changeset
68 url = self.getPageByName("blog_view").getURL(jid_.full())
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.HTTPRedirect(request, url)