annotate libervia/pages/chat/select/page_meta.py @ 1157:64952ba7affe

pages: fixed children retrieval in onFileChange
author Goffi <goffi@goffi.org>
date Sat, 23 Feb 2019 21:04:31 +0100
parents 29eb15062416
children b2d067339de3
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
1145
29eb15062416 pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents: 1124
diff changeset
11 log = getLogger(__name__)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
12
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
13 name = u"chat_select"
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
14 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
15 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
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
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 @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
19 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
20 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
21 template_data = request.template_data
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
22 rooms = template_data["rooms"] = []
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
23 bookmarks = yield self.host.bridgeCall("bookmarksList", "muc", "all", profile)
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
24 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
25 for room_jid, room_data in bm_values.iteritems():
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
26 url = self.getPageByName(u"chat").getURL(room_jid)
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
27 rooms.append(data_objects.Room(room_jid, name=room_data.get("name"), url=url))
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
28 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
29
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 @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
32 def on_data_post(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
33 jid_ = self.getPostedData(request, u"jid")
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
34 if u"@" not in jid_:
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
35 profile = self.getProfile(request)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
36 service = yield self.host.bridgeCall("mucGetService", "", profile)
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
37 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
38 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
39 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
40 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
41 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
42 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
43 defer.returnValue(C.POST_NO_CONFIRM)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 999
diff changeset
44 url = self.getPageByName(u"chat").getURL(jid_)
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
45 self.HTTPRedirect(request, url)