How to use the datasette.hookimpl function in datasette

To help you get started, we’ve selected a few datasette examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simonw / russian-ira-facebook-ads-datasette / plugins / regexp.py View on Github external
@hookimpl
def prepare_connection(conn):
    conn.create_function("regexp", 2, regexp)
github simonw / datasette-auth-github / datasette_auth_github / __init__.py View on Github external
@hookimpl
def asgi_wrapper(datasette):
    config = datasette.plugin_config("datasette-auth-github") or {}
    client_id = config.get("client_id")
    client_secret = config.get("client_secret")
    disable_auto_login = bool(config.get("disable_auto_login"))
    allow_users = config.get("allow_users")
    allow_orgs = config.get("allow_orgs")
    allow_teams = config.get("allow_teams")
    cookie_ttl = config.get("cookie_ttl") or 60 * 60
    cookie_version = config.get("cookie_version")

    # require_auth defaults to True unless set otherwise
    require_auth = True
    if "require_auth" in config:
        require_auth = config["require_auth"]
github simonw / datasette-pretty-json / datasette_pretty_json / __init__.py View on Github external
@hookimpl(trylast=True)
def render_cell(value):
    if not isinstance(value, str):
        return None
    stripped = value.strip()
    if not (
        (stripped.startswith("{") and stripped.endswith("}"))
        or (stripped.startswith("[") and stripped.endswith("]"))
    ):
        return None
    try:
        data = json.loads(value)
    except ValueError:
        return None
    return jinja2.Markup(
        '<pre>{data}</pre>'.format(
            data=jinja2.escape(json.dumps(data, indent=4))
github simonw / russian-ira-facebook-ads-datasette / plugins / regexp.py View on Github external
@hookimpl
def table_filter():
    async def inner(view, name, table, request):
        # Hacky thing for ?_regexp=
        try:
            regexp = request.args["_regexp"][0]
        except (KeyError, IndexError):
            return None
        return TableFilter(
            human_description_extras=[
                'regexp matches "{}"'.format(regexp),
            ],
            where_clauses=[
                "text regexp :regexp"
            ],
            params={
                "regexp": regexp
github simonw / datasette / datasette / publish / heroku.py View on Github external
@hookimpl
def publish_subcommand(publish):
    @publish.command()
    @add_common_publish_arguments_and_options
    @click.option(
        "-n",
        "--name",
        default="datasette",
        help="Application name to use when deploying",
    )
    def heroku(
        files,
        metadata,
        extra_options,
        branch,
        template_dir,
        plugins_dir,
github simonw / datasette / datasette / publish / cloudrun.py View on Github external
@hookimpl
def publish_subcommand(publish):
    @publish.command()
    @add_common_publish_arguments_and_options
    @click.option(
        "-n",
        "--name",
        default="datasette",
        help="Application name to use when deploying",
    )
    @click.option("--spatialite", is_flag=True, help="Enable SpatialLite extension")
    def cloudrun(
        files,
        metadata,
        extra_options,
        branch,
        template_dir,
github simonw / datasette / datasette / publish / now.py View on Github external
@hookimpl
def publish_subcommand(publish):
    @publish.command()
    @add_common_publish_arguments_and_options
    @click.option(
        "-n",
        "--name",
        default="datasette",
        help="Application name to use when deploying",
    )
    @click.option("--force", is_flag=True, help="Pass --force option to now")
    @click.option("--token", help="Auth token to use for deploy")
    @click.option("--alias", help="Desired alias e.g. yoursite.now.sh")
    @click.option("--spatialite", is_flag=True, help="Enable SpatialLite extension")
    def now(
        files,
        metadata,
github simonw / datasette-auth-github / datasette_auth_github / __init__.py View on Github external
@hookimpl
def extra_template_vars(request):
    return {"auth": request.scope.get("auth") if request else None}