comparison libervia/web/pages/photos/new/page_meta.py @ 1518:eb00d593801d

refactoring: rename `libervia` to `libervia.web` + update imports following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 16:49:28 +0200
parents libervia/pages/photos/new/page_meta.py@106bae41f5c8
children
comparison
equal deleted inserted replaced
1517:b8ed9726525b 1518:eb00d593801d
1 #!/usr/bin/env python3
2
3 from libervia.web.server.constants import Const as C
4 from twisted.internet import defer
5 from libervia.backend.core.log import getLogger
6 from libervia.backend.core.i18n import D_
7 from libervia.backend.core import exceptions
8 from libervia.frontends.bridge.bridge_frontend import BridgeException
9
10 """creation of new events"""
11
12 name = "photos_new"
13 access = C.PAGES_ACCESS_PROFILE
14 template = "photo/create.html"
15 log = getLogger(__name__)
16
17
18 async def on_data_post(self, request):
19 request_data = self.get_r_data(request)
20 profile = self.get_profile(request)
21 name = self.get_posted_data(request, "name").replace('/', '_')
22 albums_path = "/albums"
23 album_path = f"{albums_path}/{name}"
24 if profile is None:
25 self.page_error(request, C.HTTP_BAD_REQUEST)
26 fis_ns = self.host.ns_map["fis"]
27 http_upload_ns = self.host.ns_map["http_upload"]
28 entities_services, __, __ = await self.host.bridge_call(
29 "disco_find_by_features",
30 [fis_ns, http_upload_ns],
31 [],
32 False,
33 True,
34 False,
35 False,
36 False,
37 profile
38 )
39 try:
40 fis_service = next(iter(entities_services))
41 except StopIteration:
42 raise exceptions.DataError(D_(
43 "You server has no service to create a photo album, please ask your server "
44 "administrator to add one"))
45
46 try:
47 await self.host.bridge_call(
48 "fis_create_dir",
49 fis_service,
50 "",
51 albums_path,
52 {"access_model": "open"},
53 profile
54 )
55 except BridgeException as e:
56 if e.condition == 'conflict':
57 pass
58 else:
59 log.error(f"Can't create {albums_path} path: {e}")
60 raise e
61
62 try:
63 await self.host.bridge_call(
64 "fis_create_dir",
65 fis_service,
66 "",
67 album_path,
68 {"access_model": "whitelist"},
69 profile
70 )
71 except BridgeException as e:
72 if e.condition == 'conflict':
73 pass
74 else:
75 log.error(f"Can't create {album_path} path: {e}")
76 raise e
77
78 await self.host.bridge_call(
79 "interests_file_sharing_register",
80 fis_service,
81 "photos",
82 "",
83 album_path,
84 name,
85 "",
86 profile
87 )
88 log.info(f"album {name} created")
89 request_data["post_redirect_page"] = self.get_page_by_name("photos")
90 defer.returnValue(C.POST_NO_CONFIRM)