Mercurial > libervia-web
annotate libervia/pages/files/page_meta.py @ 1290:ee984eefc787
pages (files/list): return empty list of files when `item-not-found` is received
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 Jun 2020 16:47:51 +0200 |
parents | f511f8fbbf8a |
children | e065c8886b81 |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1073 | 3 |
4 from libervia.server.constants import Const as C | |
5 from twisted.internet import defer | |
6 from twisted.words.protocols.jabber import jid | |
7 from sat.core.log import getLogger | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1087
diff
changeset
|
8 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
9 log = getLogger(__name__) |
1073 | 10 """files handling pages""" |
11 | |
1216 | 12 name = "files" |
1073 | 13 access = C.PAGES_ACCESS_PROFILE |
1216 | 14 template = "file/discover.html" |
1073 | 15 |
16 | |
17 @defer.inlineCallbacks | |
18 def prepare_render(self, request): | |
19 profile = self.getProfile(request) | |
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 | 29 |
30 # we store identities in dict of dict using category and type as keys | |
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 ): |
1216 | 37 for entity_str, entity_ids in entities_map.items(): |
1073 | 38 entity_jid = jid.JID(entity_str) |
39 tpl_entities[entity_jid] = identities = {} | |
40 for cat, type_, name in entity_ids: | |
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 | 46 |
47 def on_data_post(self, request): | |
1216 | 48 jid_str = self.getPostedData(request, "jid") |
1073 | 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 | 51 except RuntimeError: |
52 self.pageError(request, C.HTTP_BAD_REQUEST) | |
1216 | 53 url = self.getPageByName("files_list").getURL(jid_.full()) |
1073 | 54 self.HTTPRedirect(request, url) |