annotate libervia/pages/files/page_meta.py @ 1128:6414fd795df4

server, pages: multi-sites refactoring: Libervia is now handling external sites (i.e. other sites than Libervia official site). The external site are declared in sites_path_public_dict (in [DEFAULT] section) which is read by template engine, then they are linked to virtual host with vhosts_dict (linking host name to site name) in [libervia] section. Sites are only instanced once, so adding an alias is just a matter of mapping the alias host name in vhosts_dict with the same site name. menu_json and url_redirections_dict can now accept keys named after site name, which will be linked to the data for the site. Data for default site can still be keyed at first level. Libervia official pages are added to external site (if pages are not overriden), allowing to call pages of the framework and to have facilities like login handling. Deprecated url_redirections_profile option has been removed.
author Goffi <goffi@goffi.org>
date Fri, 14 Sep 2018 21:41:28 +0200
parents 28e3eb3bb217
children 29eb15062416
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
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
8
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
9 log = getLogger("pages/files")
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
10 """files handling pages"""
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
11
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
12 name = u"files"
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
13 access = C.PAGES_ACCESS_PROFILE
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
14 template = u"file/discover.html"
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
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
17 @defer.inlineCallbacks
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
18 def prepare_render(self, request):
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
19 profile = self.getProfile(request)
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
20 template_data = request.template_data
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
21 namespace = self.host.ns_map["fis"]
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
22 entities_services, 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", [namespace], [], False, True, True, True, False, profile
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 tpl_service_entities = template_data["disco_service_entities"] = {}
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
26 tpl_own_entities = template_data["disco_own_entities"] = {}
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
27 tpl_roster_entities = template_data["disco_roster_entities"] = {}
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
28 entities_url = template_data["entities_url"] = {}
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
29
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
30 # 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
31 # this way it's easier to test category in the template
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
32 for tpl_entities, entities_map in (
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
33 (tpl_service_entities, entities_services),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
34 (tpl_own_entities, entities_own),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
35 (tpl_roster_entities, entities_roster),
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
36 ):
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
37 for entity_str, entity_ids in entities_map.iteritems():
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
38 entity_jid = jid.JID(entity_str)
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
39 tpl_entities[entity_jid] = identities = {}
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
40 for cat, type_, name in entity_ids:
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
41 identities.setdefault(cat, {}).setdefault(type_, []).append(name)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
42 entities_url[entity_jid] = self.getPageByName("files_list").getURL(
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
43 entity_jid.full()
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
44 )
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
45
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
46
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
47 def on_data_post(self, request):
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
48 jid_str = self.getPostedData(request, u"jid")
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
49 try:
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
50 jid_ = jid.JID(jid_str)
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
51 except RuntimeError:
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
52 self.pageError(request, C.HTTP_BAD_REQUEST)
1113
cdd389ef97bc server: code style reformatting using black
Goffi <goffi@goffi.org>
parents: 1087
diff changeset
53 url = self.getPageByName(u"files_list").getURL(jid_.full())
1073
09a5e824dd42 imported patch discover
Goffi <goffi@goffi.org>
parents: 1064
diff changeset
54 self.HTTPRedirect(request, url)