annotate libervia/pages/lists/create_from_tpl/page_meta.py @ 1439:ac2374c92294

remove old pyjamas workaround
author Goffi <goffi@goffi.org>
date Fri, 18 Jun 2021 15:27:56 +0200
parents a84383c659b4
children 106bae41f5c8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1387
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 from sat.tools.common import data_format
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 from sat.core.log import getLogger
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 from sat.core.i18n import D_
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.core import exceptions
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from libervia.server.constants import Const as C
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat_frontends.bridge.bridge_frontend import BridgeException
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 log = getLogger(__name__)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 name = "list_create_from_tpl"
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 access = C.PAGES_ACCESS_PROFILE
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 template = "list/create_from_template.html"
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 def parse_url(self, request):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 self.getPathArgs(request, ["template_id"])
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 async def prepare_render(self, request):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 data = self.getRData(request)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 template_id = data["template_id"]
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 if not template_id:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 self.pageError(request, C.HTTP_BAD_REQUEST)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 template_data = request.template_data
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 profile = self.getProfile(request)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 tpl_raw = await self.host.bridgeCall(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 "listTemplateGet",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 template_id,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 "",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 profile,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 template = data_format.deserialise(tpl_raw)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 template['id'] = template_id
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 template_data["list_template"] = template
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 async def on_data_post(self, request):
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 data = self.getRData(request)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 template_id = data['template_id']
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 name, access = self.getPostedData(request, ('name', 'access'))
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 if access == 'private':
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 access_model = 'whitelist'
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 elif access == 'public':
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 access_model = 'open'
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 log.warning(f"Unknown access for template creation: {access}")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.pageError(request, C.HTTP_BAD_REQUEST)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 profile = self.getProfile(request)
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 try:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 service, node = await self.host.bridgeCall(
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 "listTemplateCreate", template_id, name, access_model, profile
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 )
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 except BridgeException as e:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 if e.condition == "conflict":
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 raise exceptions.DataError(D_("A list with this name already exists"))
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 else:
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 log.error(f"Can't create list from template: {e}")
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 raise e
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 data["post_redirect_page"] = (
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 self.getPageByName("lists"),
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 service,
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 node or "@",
a84383c659b4 lists: creation, invitation, item deletion:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 )