annotate libervia/pages/photos/new/page_meta.py @ 1376:1b94a5ab155f

pages (blog/view): Full-Text Search is used when `search` query argument is present the new `LiberviaPage.handleSearch` method implements FTS in PubSub based features.
author Goffi <goffi@goffi.org>
date Fri, 11 Dec 2020 17:35:06 +0100
parents 39719ff4fcad
children 106bae41f5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1278
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
2
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from libervia.server.constants import Const as C
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from twisted.internet import defer
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.log import getLogger
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core.i18n import D_
1339
3a1cb3c5702f pages (photos/new): typo
Goffi <goffi@goffi.org>
parents: 1280
diff changeset
7 from sat.core import exceptions
1356
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
8 from sat_frontends.bridge.bridge_frontend import BridgeException
1278
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
9
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
10 """creation of new events"""
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
11
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
12 name = "photos_new"
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
13 access = C.PAGES_ACCESS_PROFILE
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
14 template = "photo/create.html"
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
15 log = getLogger(__name__)
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
16
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
17
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
18 async def on_data_post(self, request):
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
19 request_data = self.getRData(request)
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
20 profile = self.getProfile(request)
1280
198605982d15 pages (photos/new): create albums in "/albums/" path in default namespace
Goffi <goffi@goffi.org>
parents: 1278
diff changeset
21 name = self.getPostedData(request, "name").replace('/', '_')
1356
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
22 albums_path = "/albums"
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
23 album_path = f"{albums_path}/{name}"
1278
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
24 if profile is None:
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
25 self.pageError(request, C.HTTP_BAD_REQUEST)
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
26 fis_ns = self.host.ns_map["fis"]
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
27 http_upload_ns = self.host.ns_map["http_upload"]
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
28 entities_services, __, __ = await self.host.bridgeCall(
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
29 "discoFindByFeatures",
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
30 [fis_ns, http_upload_ns],
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
31 [],
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
32 False,
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
33 True,
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
34 False,
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
35 False,
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
36 False,
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
37 profile
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
38 )
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
39 try:
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
40 fis_service = next(iter(entities_services))
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
41 except StopIteration:
1339
3a1cb3c5702f pages (photos/new): typo
Goffi <goffi@goffi.org>
parents: 1280
diff changeset
42 raise exceptions.DataError(D_(
3a1cb3c5702f pages (photos/new): typo
Goffi <goffi@goffi.org>
parents: 1280
diff changeset
43 "You server has no service to create a photo album, please ask your server "
1278
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
44 "administrator to add one"))
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
45
1356
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
46 try:
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
47 await self.host.bridgeCall(
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
48 "FISCreateDir",
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
49 fis_service,
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
50 "",
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
51 albums_path,
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
52 {"access_model": "open"},
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
53 profile
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
54 )
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
55 except BridgeException as e:
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
56 if e.condition == 'conflict':
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
57 pass
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
58 else:
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
59 log.error(f"Can't create {albums_path} path: {e}")
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
60 raise e
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
61
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
62 try:
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
63 await self.host.bridgeCall(
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
64 "FISCreateDir",
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
65 fis_service,
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
66 "",
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
67 album_path,
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
68 {"access_model": "whitelist"},
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
69 profile
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
70 )
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
71 except BridgeException as e:
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
72 if e.condition == 'conflict':
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
73 pass
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
74 else:
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
75 log.error(f"Can't create {album_path} path: {e}")
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
76 raise e
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
77
1278
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
78 await self.host.bridgeCall(
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
79 "interestsRegisterFileSharing",
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
80 fis_service,
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
81 "photos",
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
82 "",
1356
39719ff4fcad pages (photos/new): fix permissions:
Goffi <goffi@goffi.org>
parents: 1339
diff changeset
83 album_path,
1278
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
84 name,
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
85 "",
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
86 profile
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
87 )
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
88 log.info(f"album {name} created")
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
89 request_data["post_redirect_page"] = self.getPageByName("photos")
4385a75e3962 pages (photos/new): photo album creation
Goffi <goffi@goffi.org>
parents:
diff changeset
90 defer.returnValue(C.POST_NO_CONFIRM)