{"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-996958442", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 996958442, "node_id": "IC_kwDOBm6k_c47bGDq", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-17T18:59:27Z", "updated_at": "2021-12-17T18:59:27Z", "author_association": "OWNER", "body": "I'm happy with how the prototype that used this plugin in `datasette-leaflet-freedraw` turned out: https://github.com/simonw/datasette-leaflet-freedraw/blob/e8a16a0fe90656b8d655c02881d23a2b9833281d/datasette_leaflet_freedraw/__init__.py", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-996345233", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 996345233, "node_id": "IC_kwDOBm6k_c47YwWR", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-17T01:20:31Z", "updated_at": "2021-12-17T18:13:01Z", "author_association": "OWNER", "body": "I could use this hook to add table filtering on a map to the existing `datasette-leaflet-freedraw` plugin.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-996484551", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 996484551, "node_id": "IC_kwDOBm6k_c47ZSXH", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-17T07:02:21Z", "updated_at": "2021-12-17T07:04:23Z", "author_association": "OWNER", "body": "The one slightly weird thing about this hook is how it adds `extra_context` without an obvious way for plugins to add extra HTML to the templates based on that context.\r\n\r\nMaybe I need the proposed mechanism from\r\n- #1191\r\n\r\nWhich has an in-progress PR:\r\n- #1204", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-996286199", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 996286199, "node_id": "IC_kwDOBm6k_c47Yh73", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-17T00:00:22Z", "updated_at": "2021-12-17T00:00:22Z", "author_association": "OWNER", "body": "Documentation for that hook in the PR branch: https://github.com/simonw/datasette/blob/54e9b3972f277431a001e685f78e5dd6403a6d8d/docs/plugin_hooks.rst#filters_from_requestrequest-database-table-datasette", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-996275108", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 996275108, "node_id": "IC_kwDOBm6k_c47YfOk", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-16T23:32:22Z", "updated_at": "2021-12-16T23:32:30Z", "author_association": "OWNER", "body": "This filter design can only influence the `where` component of the SQL clause - it's not able to modify the `SELECT` columns or adjust the `ORDER BY` or `OFFSET LIMIT` parts. I think that's OK.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-996267817", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 996267817, "node_id": "IC_kwDOBm6k_c47Ydcp", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-12-16T23:17:52Z", "updated_at": "2021-12-16T23:19:00Z", "author_association": "OWNER", "body": "I revisited this idea in #1518 and came up with a slightly different name and design for the hook:\r\n\r\n```python\r\n@hookspec\r\ndef filters_from_request(request, database, table, datasette):\r\n \"\"\"\r\n Return FilterArguments(\r\n where_clauses=[str, str, str],\r\n params={},\r\n human_descriptions=[str, str, str],\r\n extra_context={}\r\n ) based on the request\"\"\"\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-496339819", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 496339819, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5NjMzOTgxOQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-28T02:13:44Z", "updated_at": "2019-05-28T02:13:44Z", "author_association": "OWNER", "body": "I'm leaning towards supporting both hooks.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-496339574", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 496339574, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5NjMzOTU3NA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-28T02:12:13Z", "updated_at": "2019-05-28T02:13:07Z", "author_association": "OWNER", "body": "Here's an older version of what that custom table filtering plugin might look like: https://github.com/simonw/datasette/commit/5116c4ec8aed5091e1f75415424b80f613518dc6\r\n\r\n```python\r\nfrom datasette.utils import TableFilter\r\n\r\n@hookimpl\r\ndef table_filter():\r\n async def inner(view, name, table, request):\r\n extra_human_descriptions = []\r\n where_clauses = []\r\n params = {}\r\n # ... build those things here\r\n return TableFilter(\r\n human_description_extras=extra_human_descriptions,\r\n where_clauses=where_clauses,\r\n params=params,\r\n )\r\n return inner\r\n```\r\n\r\nI built this for the https://github.com/simonw/russian-ira-facebook-ads-datasette project.\r\n\r\nIt's pretty neat. Maybe I should go with that?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-496338808", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 496338808, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5NjMzODgwOA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-28T02:07:23Z", "updated_at": "2019-05-28T02:07:23Z", "author_association": "OWNER", "body": "Assuming I do go ahead with this plugin hook, the existing `InFilter` makes for a nice simple example that illustrates the two key methods: `.where_clause()` and `.human_clause()`:\r\n\r\n```python\r\nclass InFilter(Filter):\r\n key = \"in\"\r\n display = \"in\"\r\n\r\n def split_value(self, value):\r\n if value.startswith(\"[\"):\r\n return json.loads(value)\r\n else:\r\n return [v.strip() for v in value.split(\",\")]\r\n\r\n def where_clause(self, table, column, value, param_counter):\r\n values = self.split_value(value)\r\n params = [\":p{}\".format(param_counter + i) for i in range(len(values))]\r\n sql = \"{} in ({})\".format(escape_sqlite(column), \", \".join(params))\r\n return sql, values\r\n\r\n def human_clause(self, column, value):\r\n return \"{} in {}\".format(column, json.dumps(self.split_value(value)))\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-496338666", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 496338666, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5NjMzODY2Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-28T02:06:23Z", "updated_at": "2019-05-28T02:06:23Z", "author_association": "OWNER", "body": "I'm having trouble coming up with interesting column-based filters which don't make sense to ship as default behaviour.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-496338533", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 496338533, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5NjMzODUzMw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-28T02:05:39Z", "updated_at": "2019-05-28T02:05:39Z", "author_association": "OWNER", "body": "I wonder if this is the right hook?\r\n\r\nThe more likely case is that we need a hook that registers a new type of lookup entirely - `?_spatial_within={geojson}` for example. These aren't necessarily attached to a specific column and may have entirely custom syntax - but they still need to be able to influence the query (like the `_where=` clause does) and the human-readable description of the page.\r\n\r\nIs there a strong case for supporting both custom filter plugins AND custom table where plugins, or could those where plugins cover both bases?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-496337533", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 496337533, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5NjMzNzUzMw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-28T01:59:19Z", "updated_at": "2019-05-28T01:59:19Z", "author_association": "OWNER", "body": "It would be nice if this plugin was passed the current database/table so it can decide to enable new filters only for specific tables. This will require a bit of refactoring because the filters list is static at the moment - it would instead have to be returned by a function that runs when the table view is rendered.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/473#issuecomment-493781417", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/473", "id": 493781417, "node_id": "MDEyOklzc3VlQ29tbWVudDQ5Mzc4MTQxNw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2019-05-19T18:45:15Z", "updated_at": "2019-05-19T18:45:15Z", "author_association": "OWNER", "body": "This expands on the refactoring work from https://github.com/simonw/datasette/commit/6da567dda953c7ac0e5500f17d8e220467a3499e", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 445850934, "label": "Plugin hook: filters_from_request"}, "performed_via_github_app": null}