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