Skip to main content

A Wagtail StreamField block powered by TinyMCE and its table plugin

Project description

A table block for Wagtail StreamField powered by TinyMCE

License: BSD-3-Clause Ruff PyPI version Build status

Links

TinyTableBlock is a StreamField block powered by TinyMCE and its table plugin.

Wagtail provides TableBlock and TypedTableBlock which are good options if you want basic tables with some cell merging capability or StreamField-powered cell, but they have their limitations:

  • TableBlock is using an old version of handsontable. It doesn't support multi-row header, column headers, nor pasting complex tables.
  • TypedTableBlock gets complex quickly depending on the types of blocks you add, and pasting is limited to single cells.

Wagtail TinyTableBlock (this package) provides the TinyMCE table editor which has improved copy/paste, multi-row and column headers, external link support and more. It does not currently support the Wagtail rich text data format for page and document links, nor does it support embedding images.

Installation

In your project's Django settings, add the app your INSTALLED_APPS list (at the end is fine):

INSTALLED_APPS = [
  # ...
  "wagtail_tinytableblock",
]

Add the TinyTableBlock model to your StreamField definition. For example

# yourapp/models.py
from wagtail.fields import StreamField
from wagtail.models import Page

from wagtail_tinytableblock.blocks import TinyTableBlock


class WonderfulPage(Page):
    body = StreamField([
        # ...
        ("table", TinyTableBlock()),
    ])

Finally, run Django's makemigrations and migrate commands to apply any model field changes to your project

$ python manage.py makemigrations
$ python manage.py migrate

Configuration

TinyTableBlock accepts an allow_links keyword argument which allows enabling the TinyMCE link plugin. Note: this currently only works with external URLs.

from wagtail.blocks import StreamBlock
from wagtail_tinytableblock.blocks import TinyTableBlock

class ContentBlocks(StreamBlock):
    table_block = TinyTableBlock(allow_links=True)

By default, we disable the TinyMCE contextual menu to allow the browser native one. If you want to use TinyMCE one, pass enable_context_menu=True:

from wagtail.blocks import StreamBlock
from wagtail_tinytableblock.blocks import TinyTableBlock

class ContentBlocks(StreamBlock):
    table_block = TinyTableBlock(enable_context_menu=True)

Data representation

The table data is saved as a JSON-serialized dictionary with the following keys:

{
   "headers": [],
   "rows": [],
   "html": the_sanitised_html
}

headers / rows are lists of lists with cell values. Each cell is a dictionary with the following keys

key value notes
value The cell value
type "td" or "th"
rowspan if set
colspan if set
scope if set
align if set

Contributing

All contributions are welcome! See CONTRIBUTING.md

Supported versions:

  • Python 3.12, 3.13
  • Django 4.2, 5.1
  • Wagtail 6.3 (LTS), 6.4

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail_tinytableblock-0.4.1.tar.gz (479.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wagtail_tinytableblock-0.4.1-py3-none-any.whl (532.0 kB view details)

Uploaded Python 3

File details

Details for the file wagtail_tinytableblock-0.4.1.tar.gz.

File metadata

  • Download URL: wagtail_tinytableblock-0.4.1.tar.gz
  • Upload date:
  • Size: 479.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for wagtail_tinytableblock-0.4.1.tar.gz
Algorithm Hash digest
SHA256 dc301368d2acc6cf1ed42ee356d4faf783138a1aefd4a0c8da1219672bee51c6
MD5 652e3f32cf4c4f9e01cd76a3a25d6d6b
BLAKE2b-256 2693fbe2c5fceb9ef73de46c938b82380eaaf94541e6a880bb5cf39dcdc94d76

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_tinytableblock-0.4.1.tar.gz:

Publisher: publish.yml on torchbox/wagtail-tinytableblock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wagtail_tinytableblock-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_tinytableblock-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf0a4e0bb6fd6258a1b7259945f279cdd11605447fb773daba008e2107dcfef0
MD5 8cd2f2f357ac8003fa421de9de100b1b
BLAKE2b-256 dad7ec17f6ca61780bfd0d7f4face8fabc02cdda345e42ae35730270b6e8b6cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_tinytableblock-0.4.1-py3-none-any.whl:

Publisher: publish.yml on torchbox/wagtail-tinytableblock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page