Mercurial > libervia-web
annotate libervia/web/pages/files/view/page_meta.py @ 1618:5d9889f14012 default tip @
server: start major redesign
- Add icons to menu items
- Switch menu items representation from tuple to dictionary for future extensibility:
- Include icon information
- Prepare for additional data
- Remove "login" from main menu, add login page URL to template data, as it is now a separate right-aligned item
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 26 Oct 2024 23:07:01 +0200 |
parents | ebd538cb26cb |
children |
rev | line source |
---|---|
1216 | 1 #!/usr/bin/env python3 |
1239 | 2 |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
1612
ebd538cb26cb
server, pages (files/view): use new `use_local_shared_tmp` option.
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
4 from pathlib import Path |
1518
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
5 from libervia.web.server.constants import Const as C |
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
6 from libervia.backend.core.i18n import _ |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 from twisted.web import static |
1518
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
8 from libervia.web.server.utils import ProgressHandler |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 import tempfile |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 import os |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 import os.path |
1518
eb00d593801d
refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
Goffi <goffi@goffi.org>
parents:
1509
diff
changeset
|
12 from libervia.backend.core.log import getLogger |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
13 |
1145
29eb15062416
pages: set __name__ for imported pages
Goffi <goffi@goffi.org>
parents:
1124
diff
changeset
|
14 log = getLogger(__name__) |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 """files handling pages""" |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
1216 | 17 name = "files_view" |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 access = C.PAGES_ACCESS_PROFILE |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
20 |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 def parse_url(self, request): |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
22 self.get_path_args(request, ["service", "*path"], min_args=2, service="jid", path="") |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
23 |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 |
1238
f55056bb67d4
replaced former use of "dummy" by "__"
Goffi <goffi@goffi.org>
parents:
1216
diff
changeset
|
25 def cleanup(__, tmp_dir, dest_path): |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 try: |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 os.unlink(dest_path) |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 except OSError: |
1216 | 29 log.warning(_("Can't remove temporary file {path}").format(path=dest_path)) |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 try: |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 os.rmdir(tmp_dir) |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 except OSError: |
1216 | 33 log.warning(_("Can't remove temporary directory {path}").format(path=tmp_dir)) |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
1421
e065c8886b81
pages (files/list): set empty affiliations when they can't be retrieved
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
36 async def render(self, request): |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
37 data = self.get_r_data(request) |
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
38 profile = self.get_profile(request) |
1216 | 39 service, path_elts = data["service"], data["path"] |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 basename = path_elts[-1] |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 dir_elts = path_elts[:-1] |
1216 | 42 dir_path = "/".join(dir_elts) |
1612
ebd538cb26cb
server, pages (files/view): use new `use_local_shared_tmp` option.
Goffi <goffi@goffi.org>
parents:
1518
diff
changeset
|
43 tmp_dir = tempfile.mkdtemp(dir=self.host.local_shared_path) |
1064
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 dest_path = os.path.join(tmp_dir, basename) |
abc5d545dbaa
pages (files): files sharing first draft:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 request.notifyFinish().addCallback(cleanup, tmp_dir, dest_path) |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
46 progress_id = await self.host.bridge_call( |
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
47 "file_jingle_request", |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
48 service.full(), |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
49 dest_path, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
50 basename, |
1216 | 51 "", |
52 "", | |
53 {"path": dir_path}, | |
1113
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
54 profile, |
cdd389ef97bc
server: code style reformatting using black
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
55 ) |
1216 | 56 log.debug("file requested") |
1421
e065c8886b81
pages (files/list): set empty affiliations when they can't be retrieved
Goffi <goffi@goffi.org>
parents:
1239
diff
changeset
|
57 await ProgressHandler(self.host, progress_id, profile).register() |
1216 | 58 log.debug("file downloaded") |
1509
106bae41f5c8
massive refactoring from camelCase -> snake_case. See backend commit log for more details
Goffi <goffi@goffi.org>
parents:
1421
diff
changeset
|
59 self.delegate_to_resource(request, static.File(dest_path)) |