Mercurial > libervia-web
comparison libervia/pages/lists/view/page_meta.py @ 1389:ac4173fff71d
pages (lists/view): add `list_type` to `template_data`:
when a service/node is used for the first time, schema is retrieved, and `list_type` is
put in cache and used in template. This allows the template to have specialised views
depending on the kind of list user is opening.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 27 Feb 2021 20:58:22 +0100 |
parents | a84383c659b4 |
children | 4ccf42d8aab7 |
comparison
equal
deleted
inserted
replaced
1388:68ffd60a58a5 | 1389:ac4173fff71d |
---|---|
33 template_data = request.template_data | 33 template_data = request.template_data |
34 service, node = data["service"], data["node"] | 34 service, node = data["service"], data["node"] |
35 profile = self.getProfile(request) or C.SERVICE_PROFILE | 35 profile = self.getProfile(request) or C.SERVICE_PROFILE |
36 | 36 |
37 self.checkCache(request, C.CACHE_PUBSUB, service=service, node=node, short="tickets") | 37 self.checkCache(request, C.CACHE_PUBSUB, service=service, node=node, short="tickets") |
38 | |
39 try: | |
40 lists_types = self.getPageData(request, "lists_types") | |
41 if lists_types is None: | |
42 lists_types = {} | |
43 self.setPageData(request, "lists_types", lists_types) | |
44 list_type = lists_types[(service, node)] | |
45 except KeyError: | |
46 ns_tickets_type = self.host.ns_map["tickets_type"] | |
47 schema_raw = await self.host.bridgeCall( | |
48 "psSchemaDictGet", | |
49 service.full(), | |
50 node or self.host.ns_map["tickets"], | |
51 profile | |
52 ) | |
53 schema = data_format.deserialise(schema_raw) | |
54 try: | |
55 list_type_field = next( | |
56 f for f in schema["fields"] if f["type"] == "hidden" | |
57 and f.get("name") == ns_tickets_type | |
58 ) | |
59 except StopIteration: | |
60 list_type = lists_types[(service, node)] = None | |
61 else: | |
62 if list_type_field.get("value") is None: | |
63 list_type = None | |
64 else: | |
65 list_type = list_type_field["value"].lower().strip() | |
66 lists_types[(service, node)] = list_type | |
67 | |
68 data["list_type"] = template_data["list_type"] = list_type | |
38 | 69 |
39 extra = self.getPubsubExtra(request) | 70 extra = self.getPubsubExtra(request) |
40 extra["labels_as_list"] = C.BOOL_TRUE | 71 extra["labels_as_list"] = C.BOOL_TRUE |
41 self.handleSearch(request, extra) | 72 self.handleSearch(request, extra) |
42 | 73 |
84 self.exposeToScripts( | 115 self.exposeToScripts( |
85 request, | 116 request, |
86 lists_ns=self.host.ns_map["tickets"], | 117 lists_ns=self.host.ns_map["tickets"], |
87 pubsub_service=service.full(), | 118 pubsub_service=service.full(), |
88 pubsub_node=node, | 119 pubsub_node=node, |
120 list_type=list_type, | |
89 ) | 121 ) |