Mercurial > libervia-web
annotate libervia/pages/blog/page_meta.py @ 1139:e45480b6ba24
pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 Jan 2019 16:39:46 +0100 |
parents | 28e3eb3bb217 |
children | 29eb15062416 |
rev | line source |
---|---|
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python2.7 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
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 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 from sat.core.log import getLogger |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
10 log = getLogger("pages/blog") |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
11 |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
12 name = u"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
|
13 access = C.PAGES_ACCESS_PUBLIC |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 template = u"blog/discover.html" |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
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 @defer.inlineCallbacks |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 def prepare_render(self, request): |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 profile = self.getProfile(request) |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 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
|
21 if profile is not None: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
22 __, entities_own, entities_roster = yield self.host.bridgeCall( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
23 "discoFindByFeatures", |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
24 [], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
25 [(u"pubsub", u"pep")], |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
26 True, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
27 False, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
28 True, |
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 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
32 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
33 entities = template_data[u"disco_entities"] = ( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
34 entities_own.keys() + entities_roster.keys() |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
35 ) |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
36 entities_url = template_data[u"entities_url"] = {} |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
37 identities = template_data[u"identities"] = self.host.getSessionData( |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
38 request, session_iface.ISATSession |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
39 ).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
|
40 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
|
41 for entity_jid_s in entities: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
42 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
|
43 entity_jid_s |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
44 ) |
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
|
45 if entity_jid_s not in 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
|
46 d_list.append(self.host.bridgeCall(u"identityGet", |
e45480b6ba24
pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
47 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
|
48 profile)) |
e45480b6ba24
pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
49 identities_data = yield defer.DeferredList(d_list) |
e45480b6ba24
pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
50 for idx, (success, identity) in enumerate(identities_data): |
e45480b6ba24
pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
51 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
|
52 if not success: |
e45480b6ba24
pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
53 log.warning(_(u"Can't retrieve identity of {entity}") |
e45480b6ba24
pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
54 .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
|
55 else: |
e45480b6ba24
pages (blog): use DeferredList while discovering identities instead or waiting for each request individually.
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
56 identities[entity_jid_s] = identity |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
57 |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 def on_data_post(self, request): |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
60 jid_str = self.getPostedData(request, u"jid") |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 try: |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
62 jid_ = jid.JID(jid_str) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 except RuntimeError: |
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 self.pageError(request, C.HTTP_BAD_REQUEST) |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
65 url = self.getPageByName(u"blog_view").getURL(jid_.full()) |
1077
880ea673aaff
blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 self.HTTPRedirect(request, url) |