Mercurial > libervia-web
changeset 1313:12aa95eeb409
pages (files/list): set `directory_affiliation` template data:
Directory affiliation is checked by listing parent directory, then added to template_data
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 Aug 2020 16:47:24 +0200 |
parents | 39a87d9099c4 |
children | 8998f01088ac |
files | libervia/pages/files/list/page_meta.py |
diffstat | 1 files changed, 23 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/pages/files/list/page_meta.py Sat Aug 01 16:47:24 2020 +0200 +++ b/libervia/pages/files/list/page_meta.py Sat Aug 01 16:47:24 2020 +0200 @@ -2,11 +2,10 @@ import json import os -from twisted.internet import defer +from pathlib import Path from sat.core.i18n import _ from sat.core.log import getLogger from sat.tools.common import uri -from sat.tools.common import utils from sat_frontends.bridge.bridge_frontend import BridgeException from libervia.server.constants import Const as C from libervia.server import session_iface @@ -29,11 +28,12 @@ thumb_limit = data.get("thumb_limit", 300) template_data = request.template_data service, path_elts = data["service"], data["path"] - path = "/".join(path_elts) + path = Path('/', *path_elts) profile = self.getProfile(request) or C.SERVICE_PROFILE try: - files_data = await self.host.bridgeCall("FISList", service.full(), path, {}, profile) + files_data = await self.host.bridgeCall( + "FISList", service.full(), str(path), {}, profile) except BridgeException as e: if e.condition == 'item-not-found': log.debug( @@ -111,9 +111,27 @@ self, comments_service, comments_node, profile=profile ) + # parent dir affiliation + # for the moment the only way to get affiliation of current directory is to check + # it from parent's list + # TODO: some caching? What if affiliation changes? + if path.parent != path: + try: + parent_files_data = await self.host.bridgeCall( + "FISList", service.full(), str(path.parent), {}, profile) + except BridgeException as e: + if e.condition == 'item-not-found': + pass + else: + raise e + else: + directory_data = next(f for f in parent_files_data if f['name'] == path.name) + template_data['directory_affiliation'] = directory_data.get('affiliation') + + template_data["files_data"] = files_data template_data["path"] = path # we make the service and path accessible from scripts - self.exposeToScripts(request, files_service=service.full(), files_path=path) + self.exposeToScripts(request, files_service=service.full(), files_path=str(path)) if path_elts: template_data["parent_url"] = self.getURL(service.full(), *path_elts[:-1])