annotate src/pages/files/page_meta.py @ 1091:092e910292c9

pages (chat): don't change session.jid anymore, as it is now set on log-in
author Goffi <goffi@goffi.org>
date Fri, 01 Jun 2018 12:56:13 +0200
parents 5d179a3dac50
children cdd389ef97bc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
1 #!/usr/bin/env python2.7
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
2 # -*- coding: utf-8 -*-
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
3
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
4 from libervia.server.constants import Const as C
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
5 from twisted.internet import defer
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
6 from twisted.words.protocols.jabber import jid
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
7 from sat.core.log import getLogger
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
8 log = getLogger('pages/files')
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
9 """files handling pages"""
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
10
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
11 name = u'files'
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
12 access = C.PAGES_ACCESS_PROFILE
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
13 template = u"file/discover.html"
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
14
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
15
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
16 @defer.inlineCallbacks
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
17 def prepare_render(self, request):
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
18 profile = self.getProfile(request)
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
19 template_data = request.template_data
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
20 namespace = self.host.ns_map['fis']
1087
5d179a3dac50 pages (blog, files): use new local_device argument of discoFindByFeatures
Goffi <goffi@goffi.org>
parents: 1076
diff changeset
21 entities_services, entities_own, entities_roster = yield self.host.bridgeCall('discoFindByFeatures', [namespace], [], False, True, True, True, False, profile)
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
22 tpl_service_entities = template_data['disco_service_entities'] = {}
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
23 tpl_own_entities = template_data['disco_own_entities'] = {}
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
24 tpl_roster_entities = template_data['disco_roster_entities'] = {}
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
25 entities_url = template_data['entities_url'] = {}
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
26
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
27 # we store identities in dict of dict using category and type as keys
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
28 # this way it's easier to test category in the template
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
29 for tpl_entities, entities_map in ((tpl_service_entities, entities_services),
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
30 (tpl_own_entities, entities_own),
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
31 (tpl_roster_entities, entities_roster)):
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
32 for entity_str, entity_ids in entities_map.iteritems():
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
33 entity_jid = jid.JID(entity_str)
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
34 tpl_entities[entity_jid] = identities = {}
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
35 for cat, type_, name in entity_ids:
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
36 identities.setdefault(cat, {}).setdefault(type_, []).append(name)
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
37 entities_url[entity_jid] = self.getPageByName('files_list').getURL(entity_jid.full())
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
38
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
39 def on_data_post(self, request):
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
40 jid_str = self.getPostedData(request, u'jid')
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
41 try:
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
42 jid_ = jid.JID(jid_str)
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
43 except RuntimeError:
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
44 self.pageError(request, C.HTTP_BAD_REQUEST)
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
45 url = self.getPageByName(u'files_list').getURL(jid_.full())
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
46 self.HTTPRedirect(request, url)