Skip to content

Generic Views

The ckanext.tables.generics module provides a ready-to-use view class that can render tables without writing custom view code.

GenericTableView

The GenericTableView is a Flask MethodView that automatically renders any registered table definition.

Basic Usage

from flask import Blueprint

from ckanext.tables.shared import GenericTableView
from ckanext.tables_demo.table import PeopleTable

bp = Blueprint("tables_demo", __name__, url_prefix="/tables-demo")

bp.add_url_rule("/people", view_func=GenericTableView.as_view("people", table=PeopleTable))

Constructor Parameters

  • table (type[TableDefinition], required): The table definition class to be rendered.
  • breadcrumb_label (str, optional): Label shown in breadcrumbs. Defaults to "Table"
  • page_title (str, optional): Page title shown in the browser/header. Defaults to empty string

Access Control

The GenericTableView delegates access control to the table definition's check_access() method. Make sure your table definitions implement proper authorization:

class PeopleTable(TableDefinition):
    ...

    @classmethod
    def check_access(cls, context: Context) -> None:
        """Only allow sysadmins to view this table."""
        tk.check_access("sysadmin", context)