# HG changeset patch # User Goffi # Date 1614455902 -3600 # Node ID ac4173fff71dc6d947934968cc97d6d72cf7a721 # Parent 68ffd60a58a5a2dcdf7ba0ebd6c14f0dcdcba09a 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. diff -r 68ffd60a58a5 -r ac4173fff71d libervia/pages/lists/view/page_meta.py --- 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, )