Mercurial > libervia-web
changeset 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 | 68ffd60a58a5 |
children | 3e482795630c |
files | libervia/pages/lists/view/page_meta.py |
diffstat | 1 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/pages/lists/view/page_meta.py Sat Feb 27 20:55:35 2021 +0100 +++ b/libervia/pages/lists/view/page_meta.py Sat Feb 27 20:58:22 2021 +0100 @@ -36,6 +36,37 @@ self.checkCache(request, C.CACHE_PUBSUB, service=service, node=node, short="tickets") + try: + lists_types = self.getPageData(request, "lists_types") + if lists_types is None: + lists_types = {} + self.setPageData(request, "lists_types", lists_types) + list_type = lists_types[(service, node)] + except KeyError: + ns_tickets_type = self.host.ns_map["tickets_type"] + schema_raw = await self.host.bridgeCall( + "psSchemaDictGet", + service.full(), + node or self.host.ns_map["tickets"], + profile + ) + schema = data_format.deserialise(schema_raw) + try: + list_type_field = next( + f for f in schema["fields"] if f["type"] == "hidden" + and f.get("name") == ns_tickets_type + ) + except StopIteration: + list_type = lists_types[(service, node)] = None + else: + if list_type_field.get("value") is None: + list_type = None + else: + list_type = list_type_field["value"].lower().strip() + lists_types[(service, node)] = list_type + + data["list_type"] = template_data["list_type"] = list_type + extra = self.getPubsubExtra(request) extra["labels_as_list"] = C.BOOL_TRUE self.handleSearch(request, extra) @@ -86,4 +117,5 @@ lists_ns=self.host.ns_map["tickets"], pubsub_service=service.full(), pubsub_node=node, + list_type=list_type, )