annotate src/pages/chat/select/page_meta.py @ 1067:808ec98de8b3

pages (files/list): retrieve thumbnail: when thumbnail url is not available (only id is available), thumbnail are retrieved using BoB. The thumbnail closest to 300px witdh is used.
author Goffi <goffi@goffi.org>
date Wed, 14 Mar 2018 09:23:23 +0100
parents ded41172dcb5
children cdd389ef97bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
999
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2.7
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
3
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from sat.core.i18n import _
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from libervia.server.constants import Const as C
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from twisted.internet import defer
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from twisted.words.protocols.jabber import jid
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat.tools.common import data_objects
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
9 from sat.core.log import getLogger
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
10 log = getLogger('pages/chat_select')
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
11
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
12 name = u'chat_select'
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
13 access = C.PAGES_ACCESS_PROFILE
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
14 template = u"chat/select.html"
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
15
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
16
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
17 @defer.inlineCallbacks
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
18 def prepare_render(self, request):
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
19 profile = self.getProfile(request)
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
20 template_data = request.template_data
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
21 rooms = template_data['rooms'] = []
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
22 bookmarks = yield self.host.bridgeCall('bookmarksList', 'muc', 'all', profile)
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
23 for bm_values in bookmarks.values():
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
24 for room_jid, room_data in bm_values.iteritems():
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
25 url = self.getPageByName(u'chat').getURL(room_jid)
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
26 rooms.append(data_objects.Room(room_jid,
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
27 name=room_data.get('name'),
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
28 url=url))
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
29 rooms.sort(key=lambda r: r.name)
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
30
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
31
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
32 @defer.inlineCallbacks
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
33 def on_data_post(self, request):
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
34 jid_ = self.getPostedData(request, u'jid')
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
35 if u'@' not in jid_:
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
36 profile = self.getProfile(request)
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
37 service = yield self.host.bridgeCall('mucGetService', '', profile)
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
38 if service:
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
39 muc_jid = jid.JID(service)
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
40 muc_jid.user = jid_
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
41 jid_ = muc_jid.full()
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
42 else:
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
43 log.warning(_(u"Invalid jid received: {jid}".format(jid=jid_)))
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
44 defer.returnValue(C.POST_NO_CONFIRM)
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
45 url = self.getPageByName(u'chat').getURL(jid_)
ded41172dcb5 pages (chat): new chat_select page which display rooms from bookmarks and allows to specify a jid to talk to.
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.HTTPRedirect(request, url)