comparison libervia/pages/files/list/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 c14ac2502011
children 12aa95eeb409
comparison
equal deleted inserted replaced
1289:c14ac2502011 1290:ee984eefc787
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 2
3 3 import json
4 import os
5 from twisted.internet import defer
6 from sat.core.i18n import _
7 from sat.core.log import getLogger
8 from sat.tools.common import uri
9 from sat.tools.common import utils
10 from sat_frontends.bridge.bridge_frontend import BridgeException
4 from libervia.server.constants import Const as C 11 from libervia.server.constants import Const as C
5 from sat.core.i18n import _
6 from twisted.internet import defer
7 from libervia.server import session_iface 12 from libervia.server import session_iface
8 from libervia.server import pages_tools 13 from libervia.server import pages_tools
9 from sat.core.log import getLogger
10 from sat.tools.common import uri
11 import json
12 import os
13 14
14 log = getLogger(__name__) 15 log = getLogger(__name__)
15 """files handling pages""" 16 """files handling pages"""
16 17
17 name = "files_list" 18 name = "files_list"
21 22
22 def parse_url(self, request): 23 def parse_url(self, request):
23 self.getPathArgs(request, ["service", "*path"], min_args=1, service="jid", path="") 24 self.getPathArgs(request, ["service", "*path"], min_args=1, service="jid", path="")
24 25
25 26
26 @defer.inlineCallbacks 27 async def prepare_render(self, request):
27 def prepare_render(self, request):
28 data = self.getRData(request) 28 data = self.getRData(request)
29 thumb_limit = data.get("thumb_limit", 300) 29 thumb_limit = data.get("thumb_limit", 300)
30 template_data = request.template_data 30 template_data = request.template_data
31 service, path_elts = data["service"], data["path"] 31 service, path_elts = data["service"], data["path"]
32 path = "/".join(path_elts) 32 path = "/".join(path_elts)
33 profile = self.getProfile(request) or C.SERVICE_PROFILE 33 profile = self.getProfile(request) or C.SERVICE_PROFILE
34 34
35 files_data = yield self.host.bridgeCall("FISList", service.full(), path, {}, profile) 35 try:
36 files_data = await self.host.bridgeCall("FISList", service.full(), path, {}, profile)
37 except BridgeException as e:
38 if e.condition == 'item-not-found':
39 log.debug(
40 f'"item-not-found" received for {path} at {service}, this may indicate '
41 f'that the location is new')
42 files_data = []
43 else:
44 raise e
36 for file_data in files_data: 45 for file_data in files_data:
37 try: 46 try:
38 extra_raw = file_data["extra"] 47 extra_raw = file_data["extra"]
39 except KeyError: 48 except KeyError:
40 pass 49 pass
62 thumb = thumb_data 71 thumb = thumb_data
63 if "url" in thumb: 72 if "url" in thumb:
64 file_data["thumb_url"] = thumb["url"] 73 file_data["thumb_url"] = thumb["url"]
65 elif "id" in thumb: 74 elif "id" in thumb:
66 try: 75 try:
67 thumb_path = yield self.host.bridgeCall( 76 thumb_path = await self.host.bridgeCall(
68 "bobGetFile", service.full(), thumb["id"], profile 77 "bobGetFile", service.full(), thumb["id"], profile
69 ) 78 )
70 except Exception as e: 79 except Exception as e:
71 log.warning( 80 log.warning(
72 _("Can't retrieve thumbnail: {reason}").format(reason=e) 81 _("Can't retrieve thumbnail: {reason}").format(reason=e)
96 file_data["comments_count"] 105 file_data["comments_count"]
97 ) 106 )
98 except KeyError: 107 except KeyError:
99 comments_count = None 108 comments_count = None
100 if comments_count and data.get("retrieve_comments", False): 109 if comments_count and data.get("retrieve_comments", False):
101 file_data["comments"] = yield pages_tools.retrieveComments( 110 file_data["comments"] = await pages_tools.retrieveComments(
102 self, comments_service, comments_node, profile=profile 111 self, comments_service, comments_node, profile=profile
103 ) 112 )
104 113
105 template_data["files_data"] = files_data 114 template_data["files_data"] = files_data
106 template_data["path"] = path 115 template_data["path"] = path