Mercurial > libervia-web
diff src/pages/files/list/page_meta.py @ 1064:abc5d545dbaa
pages (files): files sharing first draft:
2 subpages are available at the moment:
- "list" to list shared files from an entity
- "view" to request the file and send it via HTTP
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 11 Mar 2018 19:33:38 +0100 |
parents | |
children | 808ec98de8b3 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pages/files/list/page_meta.py Sun Mar 11 19:33:38 2018 +0100 @@ -0,0 +1,39 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- + +from libervia.server.constants import Const as C +from twisted.internet import defer +from sat.core.log import getLogger +log = getLogger('pages/file') +"""files handling pages""" + +name = u'files' +access = C.PAGES_ACCESS_PROFILE +template = u"file/overview.html" + +def parse_url(self, request): + self.getPathArgs(request, ['service', '*path'], min_args=1, service='jid', path='') + +@defer.inlineCallbacks +def prepare_render(self, request): + data = self.getRData(request) + template_data = request.template_data + service, path_elts = data[u'service'], data[u'path'] + path = u'/'.join(path_elts) + profile = self.getProfile(request) or C.SERVICE_PROFILE + + files_data = yield self.host.bridgeCall('FISList', service.full(), path, {}, profile) + for file_data in files_data: + dir_path = path_elts + [file_data['name']] + if file_data[u'type'] == C.FILE_TYPE_DIRECTORY: + page = self + elif file_data[u'type'] == C.FILE_TYPE_FILE: + page = self.getPageByName('files_view') + else: + raise ValueError(u'unexpected file type: {file_type}'.format(file_type=file_data[u'type'])) + file_data[u'url'] = page.getURL(service.full(), *dir_path) + template_data[u'files_data'] = files_data + template_data[u'path'] = path + if path_elts: + template_data[u'parent_url'] = self.getURL(service.full(), *path_elts[:-1]) +