Mercurial > libervia-web
view libervia/pages/files/view/page_meta.py @ 1417:314bba1ae433
pages: breadcrumbs handling:
a new `breadcrumbs` list of dict is created in `template_data`. By default it is
automatically filled by pages run to reach the requested URI, but a page can customize it.
A breadcrumb data dict must have a `label`, should have an `url` and may have an `icon`
(which is the name of a SàT Media well-known icon).
Pages may now have a `label` attribute, which is used to automatically fill the crumb
(otherwise page name then URI is used).
A new `add_breadcrumb` method can be used to manually breadcrumb data, in which case auto-filling is disabled.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 29 Apr 2021 20:48:35 +0200 |
parents | f511f8fbbf8a |
children | e065c8886b81 |
line wrap: on
line source
#!/usr/bin/env python3 from libervia.server.constants import Const as C from sat.core.i18n import _ from twisted.internet import defer from twisted.web import static from libervia.server.utils import ProgressHandler import tempfile import os import os.path from sat.core.log import getLogger log = getLogger(__name__) """files handling pages""" name = "files_view" access = C.PAGES_ACCESS_PROFILE def parse_url(self, request): self.getPathArgs(request, ["service", "*path"], min_args=2, service="jid", path="") def cleanup(__, tmp_dir, dest_path): try: os.unlink(dest_path) except OSError: log.warning(_("Can't remove temporary file {path}").format(path=dest_path)) try: os.rmdir(tmp_dir) except OSError: log.warning(_("Can't remove temporary directory {path}").format(path=tmp_dir)) @defer.inlineCallbacks def render(self, request): data = self.getRData(request) profile = self.getProfile(request) service, path_elts = data["service"], data["path"] basename = path_elts[-1] dir_elts = path_elts[:-1] dir_path = "/".join(dir_elts) tmp_dir = tempfile.mkdtemp() dest_path = os.path.join(tmp_dir, basename) request.notifyFinish().addCallback(cleanup, tmp_dir, dest_path) progress_id = yield self.host.bridgeCall( "fileJingleRequest", service.full(), dest_path, basename, "", "", {"path": dir_path}, profile, ) log.debug("file requested") yield ProgressHandler(self.host, progress_id, profile).register() log.debug("file downloaded") self.delegateToResource(request, static.File(dest_path))