Mercurial > libervia-web
comparison libervia/pages/lists/create_from_tpl/page_meta.py @ 1387:a84383c659b4
lists: creation, invitation, item deletion:
this big patch includes:
- reorganisation of pages for consistency, discovery is now the main list page, and list
overview is now in `view` while item view is moved to `view_item`
- lists from lists of interest are now shown in discovery page
- list deletion from discory page
- list can now be created, using templates now available from backend
- invitation manager can now be used from list overview
- list item can now be deleted from `view_item`
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 20 Feb 2021 14:07:22 +0100 |
parents | |
children | 106bae41f5c8 |
comparison
equal
deleted
inserted
replaced
1386:83be300d17e3 | 1387:a84383c659b4 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 from sat.tools.common import data_format | |
4 from sat.core.log import getLogger | |
5 from sat.core.i18n import D_ | |
6 from sat.core import exceptions | |
7 from libervia.server.constants import Const as C | |
8 from sat_frontends.bridge.bridge_frontend import BridgeException | |
9 | |
10 log = getLogger(__name__) | |
11 | |
12 name = "list_create_from_tpl" | |
13 access = C.PAGES_ACCESS_PROFILE | |
14 template = "list/create_from_template.html" | |
15 | |
16 | |
17 def parse_url(self, request): | |
18 self.getPathArgs(request, ["template_id"]) | |
19 | |
20 async def prepare_render(self, request): | |
21 data = self.getRData(request) | |
22 template_id = data["template_id"] | |
23 if not template_id: | |
24 self.pageError(request, C.HTTP_BAD_REQUEST) | |
25 | |
26 template_data = request.template_data | |
27 profile = self.getProfile(request) | |
28 tpl_raw = await self.host.bridgeCall( | |
29 "listTemplateGet", | |
30 template_id, | |
31 "", | |
32 profile, | |
33 ) | |
34 template = data_format.deserialise(tpl_raw) | |
35 template['id'] = template_id | |
36 template_data["list_template"] = template | |
37 | |
38 async def on_data_post(self, request): | |
39 data = self.getRData(request) | |
40 template_id = data['template_id'] | |
41 name, access = self.getPostedData(request, ('name', 'access')) | |
42 if access == 'private': | |
43 access_model = 'whitelist' | |
44 elif access == 'public': | |
45 access_model = 'open' | |
46 else: | |
47 log.warning(f"Unknown access for template creation: {access}") | |
48 self.pageError(request, C.HTTP_BAD_REQUEST) | |
49 profile = self.getProfile(request) | |
50 try: | |
51 service, node = await self.host.bridgeCall( | |
52 "listTemplateCreate", template_id, name, access_model, profile | |
53 ) | |
54 except BridgeException as e: | |
55 if e.condition == "conflict": | |
56 raise exceptions.DataError(D_("A list with this name already exists")) | |
57 else: | |
58 log.error(f"Can't create list from template: {e}") | |
59 raise e | |
60 data["post_redirect_page"] = ( | |
61 self.getPageByName("lists"), | |
62 service, | |
63 node or "@", | |
64 ) |