From 9998f92cc05e6061a81af6cf194c3caa4d0759c1 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 7 Jul 2019 16:19:02 -0700 Subject: [PATCH] Updated custom facet docs, closes #482 --- docs/plugins.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/plugins.rst b/docs/plugins.rst index 3b3653cc..faa27daf 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -712,9 +712,9 @@ Each Facet subclass implements a new type of facet operation. The class should l # This key must be unique across all facet classes: type = "special" - async def suggest(self, sql, params, filtered_table_rows_count): + async def suggest(self): + # Use self.sql and self.params to suggest some facets suggested_facets = [] - # Perform calculations to suggest facets suggested_facets.append({ "name": column, # Or other unique name # Construct the URL that will enable this facet: @@ -726,8 +726,9 @@ Each Facet subclass implements a new type of facet operation. The class should l }) return suggested_facets - async def facet_results(self, sql, params): - # This should execute the facet operation and return results + async def facet_results(self): + # This should execute the facet operation and return results, again + # using self.sql and self.params as the starting point facet_results = {} facets_timed_out = [] # Do some calculations here... @@ -752,7 +753,7 @@ Each Facet subclass implements a new type of facet operation. The class should l return facet_results, facets_timed_out -See ``datasette/facets.py`` for examples of how these classes can work. +See `datasette/facets.py `__ for examples of how these classes can work. The plugin hook can then be used to register the new facet class like this: