Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harrislapiroff/wagtail-foliage
Utilities for programmatically building page trees in Wagtail.
https://github.com/harrislapiroff/wagtail-foliage
Last synced: about 2 months ago
JSON representation
Utilities for programmatically building page trees in Wagtail.
- Host: GitHub
- URL: https://github.com/harrislapiroff/wagtail-foliage
- Owner: harrislapiroff
- License: bsd-3-clause
- Created: 2018-12-20T17:13:00.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-02T08:40:21.000Z (9 months ago)
- Last Synced: 2024-06-11T20:38:20.416Z (7 months ago)
- Language: Python
- Homepage:
- Size: 21.5 KB
- Stars: 17
- Watchers: 4
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-wagtail - Wagtail Foliage - Utilities for programmatically building page trees in Wagtail. (Apps / Testing)
README
# Wagtail Foliage
[![CircleCI](https://circleci.com/gh/harrislapiroff/wagtail-foliage.svg?style=svg)](https://circleci.com/gh/harrislapiroff/wagtail-foliage)
Utilities for programmatically building page trees in Wagtail for automated
tests, default site structures, and more.## Requirements
Wagtail Foliage supports:
* Python 3.4, 3.5, 3.6, and 3.7
* Django 1.11, 2.0, and 2.1
* Wagtail 1.13, 2.3, and 2.4These are the currently supported versions for each project as of December
2018, excepting the exclusion of Python 2.7 from this list.## Installation
```bash
pip install wagtail-foliage
```## Usage
### Use as a context manager
```python
from django.db import TestCase
from foliage.contextmanagers import page_treefrom myapp.models import HomePage, InsidePage
class MyAppTestCase(TestCase):
def test_with_pages(self):
PAGES = [
(HomePage(title='Home Page'), [
InsidePage(title='Inside Page'),
(InsidePage(title='Inside Page With Children'), [
InsidePage(title='Third Level Page'),
InsidePage(title='Another Third Level Page')
])
])
]
with page_tree(PAGES):
# Tests that rely on that page tree go here. The context manager
# will automatically set the top level page as the Wagtail site's
# root page
```### Use as a decorator
```python
from django.db import TestCase
from foliage.contextmanagers import page_treefrom myapp.models import HomePage, InsidePage
PAGES = [
(HomePage(title='Home Page'), [
InsidePage(title='Inside Page'),
(InsidePage(title='Inside Page With Children'), [
InsidePage(title='Third Level Page'),
InsidePage(title='Another Third Level Page')
])
])
]class MyAppTestCase(TestCase):
@page_tree(PAGES)
def test_with_pages(self):
# Tests that rely on that page tree go here. The context manager
# will automatically set the top level page as the Wagtail site's
# root page
```### Use the low-level API
```python
from foliage.utils import build_page_treefrom myapp.models import HomePage, InsidePage
new_pages = build_page_tree([
(HomePage(title='Home Page'), [
InsidePage(title='Inside Page'),
(InsidePage(title='Inside Page With Children'), [
InsidePage(title='Third Level Page'),
InsidePage(title='Another Third Level Page')
])
])
])
```