comparison libervia/pages/files/list/page_meta.py @ 1316:d0575e9abf7d

pages (files/list): use new `FISAffiliationsGet` to get `directory_affiliation`
author Goffi <goffi@goffi.org>
date Sat, 01 Aug 2020 16:47:24 +0200
parents 12aa95eeb409
children 009542289bc9
comparison
equal deleted inserted replaced
1315:991ff12241e0 1316:d0575e9abf7d
28 thumb_limit = data.get("thumb_limit", 300) 28 thumb_limit = data.get("thumb_limit", 300)
29 template_data = request.template_data 29 template_data = request.template_data
30 service, path_elts = data["service"], data["path"] 30 service, path_elts = data["service"], data["path"]
31 path = Path('/', *path_elts) 31 path = Path('/', *path_elts)
32 profile = self.getProfile(request) or C.SERVICE_PROFILE 32 profile = self.getProfile(request) or C.SERVICE_PROFILE
33 session_data = self.host.getSessionData(
34 request, session_iface.ISATSession
35 )
33 36
34 try: 37 try:
35 files_data = await self.host.bridgeCall( 38 files_data = await self.host.bridgeCall(
36 "FISList", service.full(), str(path), {}, profile) 39 "FISList", service.full(), str(path), {}, profile)
37 except BridgeException as e: 40 except BridgeException as e:
80 log.warning( 83 log.warning(
81 _("Can't retrieve thumbnail: {reason}").format(reason=e) 84 _("Can't retrieve thumbnail: {reason}").format(reason=e)
82 ) 85 )
83 else: 86 else:
84 filename = os.path.basename(thumb_path) 87 filename = os.path.basename(thumb_path)
85 session_data = self.host.getSessionData(
86 request, session_iface.ISATSession
87 )
88 file_data["thumb_url"] = os.path.join( 88 file_data["thumb_url"] = os.path.join(
89 session_data.cache_dir, filename 89 session_data.cache_dir, filename
90 ) 90 )
91 else: 91 else:
92 raise ValueError( 92 raise ValueError(
110 file_data["comments"] = await pages_tools.retrieveComments( 110 file_data["comments"] = await pages_tools.retrieveComments(
111 self, comments_service, comments_node, profile=profile 111 self, comments_service, comments_node, profile=profile
112 ) 112 )
113 113
114 # parent dir affiliation 114 # parent dir affiliation
115 # for the moment the only way to get affiliation of current directory is to check
116 # it from parent's list
117 # TODO: some caching? What if affiliation changes? 115 # TODO: some caching? What if affiliation changes?
118 if path.parent != path:
119 try:
120 parent_files_data = await self.host.bridgeCall(
121 "FISList", service.full(), str(path.parent), {}, profile)
122 except BridgeException as e:
123 if e.condition == 'item-not-found':
124 pass
125 else:
126 raise e
127 else:
128 directory_data = next(f for f in parent_files_data if f['name'] == path.name)
129 template_data['directory_affiliation'] = directory_data.get('affiliation')
130 116
117 affiliations = await self.host.bridgeCall(
118 "FISAffiliationsGet", service.full(), "", str(path), profile
119 )
120 directory_affiliation = affiliations.get(session_data.jid.userhost())
121 if directory_affiliation == "owner":
122 # we need to transtype dict items to str because with some bridges (D-Bus)
123 # we have a specific type which can't be exposed
124 self.exposeToScripts(
125 request,
126 affiliations={str(e): str(a) for e, a in affiliations.items()}
127 )
131 128
129 template_data["directory_affiliation"] = directory_affiliation
132 template_data["files_data"] = files_data 130 template_data["files_data"] = files_data
133 template_data["path"] = path 131 template_data["path"] = path
134 # we make the service and path accessible from scripts 132 self.exposeToScripts(
135 self.exposeToScripts(request, files_service=service.full(), files_path=str(path)) 133 request,
134 directory_affiliation=str(directory_affiliation),
135 files_service=service.full(),
136 files_path=str(path),
137 )
136 if path_elts: 138 if path_elts:
137 template_data["parent_url"] = self.getURL(service.full(), *path_elts[:-1]) 139 template_data["parent_url"] = self.getURL(service.full(), *path_elts[:-1])