Add React Taxonomy component to a wagtail page and store it as a json in the db.
- Add "wagtailreacttaxonomy" to your INSTALLED_APPS:
INSTALLED_APPS = [
'wagtailreacttaxonomy',
...
]
from django.db import models
from django.db.models.signals import pre_save
from wagtail.admin.panels import FieldPanel, TabbedInterface, ObjectList, PageChooserPanel
from wagtail.core.models import Page
from wagtailreacttaxonomy.models import TaxonomyMixin, PageTaxonomyPermissionsMixin,\
ModelTaxonomyPermissionsMixin, format_permissions_json
from wagtailreacttaxonomy.edit_handlers import TaxonomyPanel, PermissionsPanel
- Add
TaxonomyMixin
to your wagtail Page model - Add to the page
taxonomy_json
usingTaxonomyPanel
Example:
class TestPage(Page, TaxonomyMixin):
taxonomy_term_panels = [
TaxonomyPanel('taxonomy_json', taxonomy_terms_id='test_taxonomy'),
]
edit_handler = TabbedInterface([
ObjectList(Page.content_panels, heading='Content'),
ObjectList(taxonomy_term_panels, heading='Taxonomy'),
])
- Add
PageTaxonomyPermissionsMixin
to your wagtail Page model - Add to the page
global_permission
usingFieldPanel
- Add to the page
inherit_permission
usingFieldPanel
- Add to the page
permissions_json
usingPermissionsPanel
Example:
class TestPage(Page, PageTaxonomyPermissionsMixin):
permission_inherit_page = models.ForeignKey(
'TestPage',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
)
taxonomy_permission_panels = [
FieldPanel('global_permission', classname='global_permission'),
FieldPanel('inherit_permission', classname='inherit_permission'),
PageChooserPanel('permission_inherit_page'),
PermissionsPanel(
'permissions_json',
permission_terms_id='test_permissions_taxonomy',
permission_actions=['action1', 'action2'],
permission_type='page',
),
]
edit_handler = TabbedInterface([
ObjectList(Page.content_panels, heading='Content'),
ObjectList(taxonomy_permission_panels, heading='Permissions'),
])
pre_save.connect(format_permissions_json, sender=TestPage)
- Add
ModelTaxonomyPermissionsMixin
to your model - Add to the page
permissions_json
usingPermissionsPanel
Example:
class TestModel(ModelTaxonomyPermissionsMixin):
panels = [
PermissionsPanel(
'permissions_json',
permission_terms_id='test_permissions_taxonomy',
permission_actions=['action1', 'action2'],
permission_type='model',
),
FieldPanel('permissions_json_formatted'),
]
pre_save.connect(format_permissions_json, sender=TestModel)
- Open repository folder in container
- Docker
- docker-compose
You'll get all this lot installed nicely with https://docs.docker.com/docker-for-mac/install.
./scripts/install-hooks.sh
Now you are set
docker-compose build
docker-compose run --rm web python manage.py createsuperuser
docker-compose up
Browse to http://localhost:8000/admin and make your changes with live reload
- Log in as superuser
- You will see a Taxonomy Terms entry in the admin menu
- Use this entry to upload and save the JSON text of your taxonomy
- Taxonomies are stored in your Django media folder (media in the test configuration)
docker-compose run --rm web python manage.py test