Metadata-Version: 2.5
Name: django-page-tours
Version: 0.3.0
Summary: Guided tours of a page for Django sites, shown with Driver.js
Project-URL: Homepage, https://github.com/django-mvp/django-page-tours
Project-URL: Repository, https://github.com/django-mvp/django-page-tours
Project-URL: Documentation, https://django-mvp.github.io/django-page-tours/
Project-URL: Issues, https://github.com/django-mvp/django-page-tours/issues
Author-email: Samuel Jennings <samuel.scott.jennings@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: django,driver.js,guided tour,onboarding,tour
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 5.2
Classifier: Framework :: Django :: 6.0
Classifier: Framework :: Django :: 6.1
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Requires-Python: <4.0,>=3.12
Requires-Dist: django>=5.2
Description-Content-Type: text/markdown

# django-page-tours

[![Tests](https://github.com/django-mvp/django-page-tours/actions/workflows/tests.yml/badge.svg)](https://github.com/django-mvp/django-page-tours/actions/workflows/tests.yml)
[![Build](https://github.com/django-mvp/django-page-tours/actions/workflows/build.yml/badge.svg)](https://github.com/django-mvp/django-page-tours/actions/workflows/build.yml)
[![Docs](https://github.com/django-mvp/django-page-tours/actions/workflows/docs.yml/badge.svg)](https://github.com/django-mvp/django-page-tours/actions/workflows/docs.yml)
[![Publish](https://github.com/django-mvp/django-page-tours/actions/workflows/publish.yml/badge.svg)](https://github.com/django-mvp/django-page-tours/actions/workflows/publish.yml)
[![Coverage](https://codecov.io/gh/django-mvp/django-page-tours/branch/main/graph/badge.svg)](https://codecov.io/gh/django-mvp/django-page-tours)
[![PyPI](https://img.shields.io/pypi/v/django-page-tours)](https://pypi.org/project/django-page-tours/)
[![Development status](https://img.shields.io/pypi/status/django-page-tours)](https://pypi.org/project/django-page-tours/)
[![Python](https://img.shields.io/pypi/pyversions/django-page-tours)](https://pypi.org/project/django-page-tours/)
[![Django](https://img.shields.io/pypi/djversions/django-page-tours)](https://pypi.org/project/django-page-tours/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Licence](https://img.shields.io/github/license/django-mvp/django-page-tours)](https://github.com/django-mvp/django-page-tours/blob/main/LICENSE)

Guided tours of a page for Django sites, shown with [Driver.js](https://driverjs.com/).

A new visitor to an application often can't tell what a page is for or where its important
controls are. A short tour fixes that: a few steps, each pointing at one part of the page with a
sentence about it. Building one by hand means wiring a JavaScript library into templates, writing
the steps in JavaScript far from the view they describe, and remembering who has already seen it.
django-page-tours moves the steps into Python, next to the page, and handles the rest.

> **Status:** alpha. Every feature on the roadmap is in place, and the API may still change
> before 1.0.

## Scope & philosophy

**What it is.** A tour belongs to one page. A developer declares its steps in Python, each one
pointing at an element on the page with a title and a short description. The first time someone opens
the page, the tour plays. They can step through it, skip it or close it, and once they have seen
it, their browser remembers and it does not play again unless they ask for it. When the tour
changes enough to matter, the developer gives it a new version, and people who saw the old one
see the new one once.

**What it deliberately is not.**

- **Not a design.** The package ships Driver.js's own styling, in the lowest cascade layer on the
  page, and nothing more. A site gives the tour its look with its own CSS.
- **Not a store of progress per account.** Whether someone has seen a tour is kept in their
  browser. The package adds no database tables.
- **Not tours across several pages.**
- **Not dependent on a CDN.** Driver.js ships inside the package, so a tour works on a site with a
  strict content security policy or no outside network access.

**When a choice is close:**

1. Lean on Driver.js for anything it already does, rather than reimplementing it.
2. A tour that fails must leave the page exactly as usable as it was without one.
3. Fewer settings beat more. Each one has to earn its place.

## Quickstart

```bash
pip install django-page-tours
```

Add `page_tours` to `INSTALLED_APPS`.

Include the package's stylesheet and scripts once, in the `<head>` of your base template:

```django
{% load static %}
<head>
  ...
  <link rel="stylesheet" href="{% static 'page_tours/page-tours.css' %}">
  <script src="{% static 'page_tours/vendor/driver.js-1.11.0/driver.js.iife.js' %}" defer></script>
  <script src="{% static 'page_tours/page-tours.js' %}" defer></script>
</head>
```

On a page with no tour they do nothing.

Declare a tour and put it in a view's context, like any other value:

```python
from django.views.generic import TemplateView

from page_tours import Tour, TourStep

DASHBOARD_TOUR = Tour(
    name="dashboard",
    steps=[
        TourStep(title="Welcome", description="A quick look around."),
        TourStep(title="Projects", description="Your work is here.", element="#projects"),
    ],
)


class DashboardView(TemplateView):
    template_name = "dashboard.html"
    extra_context = {"tour": DASHBOARD_TOUR}
```

Output it in the page's template, `dashboard.html`:

```django
{% extends "base.html" %}
{% block content %}
  <ul id="projects">...</ul>
  {{ tour }}
{% endblock content %}
```

`{{ tour }}` outputs the tour's steps, the way `{{ form.media }}` outputs a form's assets, and
the package's script plays them over the page.

The tour plays the first time a browser opens the page, and not again in that browser, which
remembers it by its name. A function-based view passes the tour in the context it renders with:
`render(request, "dashboard.html", {"tour": DASHBOARD_TOUR})`.

To let visitors play it again, place a button of your own marked `data-page-tour-replay` on the
page. The package's script makes it start the tour:

```html
<button type="button" class="btn" data-page-tour-replay>Show the tour</button>
```

`Tour` mirrors Driver.js's configuration object, so a tour sets Driver.js options as fields named
as Driver.js names them, such as `Tour(showProgress=True)`. See the
[Driver.js configuration reference](https://driverjs.com/docs/configuration) for each option.
Options that take a function are not available.

The package also puts hints on a page: markers a visitor opens in any order and dismisses for good
in their browser. `Hints` declares them, and `{{ hints }}` renders them. See the
[documentation](https://django-mvp.github.io/django-page-tours/developer/hints.html).

It also puts a checklist on a page: a panel of items a visitor works through, each starting a
tour, opening a page or ticked by the app, with the visitor's ticks kept in their browser.
`Checklist` declares it, and `{{ checklist }}` renders it. See the
[documentation](https://django-mvp.github.io/django-page-tours/developer/checklists.html).

A project can replace the tour of an installed app, or turn it off, from its own settings with
`PAGE_TOURS_OVERRIDES`, keyed by the tour's name, without editing the app. It can also word the
buttons and progress text of every tour, set of hints and checklist at once with
`PAGE_TOURS_TEXT`, which a tour, hints or checklist that sets its own text overrides.

The [documentation](https://django-mvp.github.io/django-page-tours/) covers naming a tour, function-based views,
steps attached to elements, tour versions, replaying a tour and tours that play only on request,
tours from reusable apps, Driver.js options, styling, and translation.

## Styling

Every part of a shown tour step has a documented class name: `page-tour-box`, `page-tour-title`,
`page-tour-text`, `page-tour-progress`, `page-tour-previous`, `page-tour-next`, `page-tour-done`,
`page-tour-close` and `page-tour-highlight`. Style them from your own stylesheet, or give parts
classes of your own with the `PAGE_TOURS_CLASSES` setting. A design system installed as an app
can supply classes for the parts as defaults with `AppConfig.page_tour_classes`, and the project's
setting replaces them part by part. Django's `check` command reports a wrong entry with
`page_tours.W003` or `page_tours.W004`. The
[styling page](https://django-mvp.github.io/django-page-tours/developer/styling-tours.html)
has the details.

## Requirements

- Python 3.12 or 3.13
- Django 5.2, 6.0 or 6.1

## Prior art

| Package | Why it isn't this |
|---|---|
| [django-tour](https://github.com/ambitioninc/django-tour) | No release since 2015 |
| [django-driverjs](https://github.com/iwalucas/django-driverjs) | No release since 2022, no licence |
| [django-tours](https://github.com/wilmerm/django-tours) | Built on Shepherd.js, which is AGPL-licensed. Loads its script from a CDN and keeps tours in the database |

## Licence

MIT. Driver.js is also MIT-licensed.
