comparison 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
comparison
equal deleted inserted replaced
1063:4b69f69c6ffd 1064:abc5d545dbaa
1 #!/usr/bin/env python2.7
2 # -*- coding: utf-8 -*-
3
4 from libervia.server.constants import Const as C
5 from twisted.internet import defer
6 from sat.core.log import getLogger
7 log = getLogger('pages/file')
8 """files handling pages"""
9
10 name = u'files'
11 access = C.PAGES_ACCESS_PROFILE
12 template = u"file/overview.html"
13
14 def parse_url(self, request):
15 self.getPathArgs(request, ['service', '*path'], min_args=1, service='jid', path='')
16
17 @defer.inlineCallbacks
18 def prepare_render(self, request):
19 data = self.getRData(request)
20 template_data = request.template_data
21 service, path_elts = data[u'service'], data[u'path']
22 path = u'/'.join(path_elts)
23 profile = self.getProfile(request) or C.SERVICE_PROFILE
24
25 files_data = yield self.host.bridgeCall('FISList', service.full(), path, {}, profile)
26 for file_data in files_data:
27 dir_path = path_elts + [file_data['name']]
28 if file_data[u'type'] == C.FILE_TYPE_DIRECTORY:
29 page = self
30 elif file_data[u'type'] == C.FILE_TYPE_FILE:
31 page = self.getPageByName('files_view')
32 else:
33 raise ValueError(u'unexpected file type: {file_type}'.format(file_type=file_data[u'type']))
34 file_data[u'url'] = page.getURL(service.full(), *dir_path)
35 template_data[u'files_data'] = files_data
36 template_data[u'path'] = path
37 if path_elts:
38 template_data[u'parent_url'] = self.getURL(service.full(), *path_elts[:-1])
39