annotate src/pages/blog/page_meta.py @ 1087:5d179a3dac50

pages (blog, files): use new local_device argument of discoFindByFeatures
author Goffi <goffi@goffi.org>
date Wed, 23 May 2018 21:55:13 +0200
parents ff503f23ac37
children cdd389ef97bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 -*-
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from libervia.server.constants import Const as C
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from twisted.words.protocols.jabber import jid
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from twisted.internet import defer
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from libervia.server import session_iface
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.core.log import getLogger
1083
ff503f23ac37 pages: fixed calls to "blog" instead of "blog_view"
Goffi <goffi@goffi.org>
parents: 1079
diff changeset
8 log = getLogger('pages/blog')
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 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
11 access = C.PAGES_ACCESS_PUBLIC
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 template = u"blog/discover.html"
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
13
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
14
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 @defer.inlineCallbacks
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 def prepare_render(self, request):
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 profile = self.getProfile(request)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 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
19 if profile is not None:
1087
5d179a3dac50 pages (blog, files): use new local_device argument of discoFindByFeatures
Goffi <goffi@goffi.org>
parents: 1083
diff changeset
20 __, entities_own, entities_roster = yield self.host.bridgeCall('discoFindByFeatures', [], [(u'pubsub', u'pep')], True, False, True, True, True, profile)
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 entities = template_data[u'disco_entities'] = entities_own.keys() + entities_roster.keys()
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 entities_url = template_data[u'entities_url'] = {}
3af28f84ce91 pages (blog): blog page is now public (only free jid is available when not connected)
Goffi <goffi@goffi.org>
parents: 1077
diff changeset
23 identities = template_data[u'identities'] = self.host.getSessionData(request, session_iface.ISATSession).identities
3af28f84ce91 pages (blog): blog page is now public (only free jid is available when not connected)
Goffi <goffi@goffi.org>
parents: 1077
diff changeset
24 for entity_jid_s in entities:
3af28f84ce91 pages (blog): blog page is now public (only free jid is available when not connected)
Goffi <goffi@goffi.org>
parents: 1077
diff changeset
25 entities_url[entity_jid_s] = self.getPageByName('blog_view').getURL(entity_jid_s)
3af28f84ce91 pages (blog): blog page is now public (only free jid is available when not connected)
Goffi <goffi@goffi.org>
parents: 1077
diff changeset
26 if entity_jid_s not in identities:
3af28f84ce91 pages (blog): blog page is now public (only free jid is available when not connected)
Goffi <goffi@goffi.org>
parents: 1077
diff changeset
27 identities[entity_jid_s] = yield self.host.bridgeCall(u'identityGet', entity_jid_s, profile)
1077
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def on_data_post(self, request):
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 jid_str = self.getPostedData(request, u'jid')
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 try:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 jid_ = jid.JID(jid_str)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 except RuntimeError:
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 self.pageError(request, C.HTTP_BAD_REQUEST)
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 url = self.getPageByName(u'blog_view').getURL(jid_.full())
880ea673aaff blog: moved blog page from /common to /blog:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 self.HTTPRedirect(request, url)