Skip to content

Commit f36c0d4

Browse files
committed
Initial commit
0 parents  commit f36c0d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+31764
-0
lines changed

.gitignore

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
*.log
2+
*.pot
3+
*.pyc
4+
__pycache__
5+
db.sqlite3
6+
media
7+
.DS_Store
8+
9+
# Distribution / packaging
10+
.Python build/
11+
develop-eggs/
12+
dist/
13+
downloads/
14+
eggs/
15+
.eggs/
16+
lib/
17+
lib64/
18+
parts/
19+
sdist/
20+
var/
21+
wheels/
22+
*.egg-info/
23+
.installed.cfg
24+
*.egg
25+
*.manifest
26+
*.spec
27+
28+
# Installer logs
29+
pip-log.txt
30+
pip-delete-this-directory.txt
31+
32+
# Unit test / coverage reports
33+
htmlcov/
34+
.tox/
35+
.coverage
36+
.coverage.*
37+
.cache
38+
.pytest_cache/
39+
nosetests.xml
40+
coverage.xml
41+
*.cover
42+
.hypothesis/
43+
44+
# Environments
45+
.env
46+
.venv
47+
env/
48+
venv/
49+
ENV/
50+
env.bak/
51+
venv.bak/
52+
53+
# mkdocs documentation
54+
/site
55+
56+
# Visual Studio Code #
57+
.vscode/*
58+
!.vscode/settings.json
59+
!.vscode/tasks.json
60+
!.vscode/launch.json
61+
!.vscode/extensions.json
62+
.history

.vscode/launch.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Run Django",
6+
"type": "python",
7+
"request": "attach",
8+
"pathMappings": [
9+
{
10+
"localRoot": "${workspaceFolder}/",
11+
"remoteRoot": "/code/wagtailtables/"
12+
}
13+
],
14+
"port": 3000,
15+
"host": "localhost",
16+
}
17+
]
18+
}

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Use an official Python runtime as a parent image
2+
FROM python:3.8-bullseye
3+
LABEL maintainer="hello@wagtail.org"
4+
5+
# Set environment varibles
6+
ENV PYTHONUNBUFFERED 1
7+
8+
# Install libenchant and create the requirements folder.
9+
RUN apt-get update -y \
10+
&& apt-get install -y libenchant-2-dev postgresql-client \
11+
&& mkdir -p /code/requirements
12+
13+
# Install the wagtailtables_demo project's dependencies into the image.
14+
COPY ./wagtailtables_demo/requirements.txt /code/requirements.txt
15+
RUN --mount=type=cache,target=/root/.cache/pip pip install --upgrade pip \
16+
&& pip install -r /code/requirements.txt
17+
18+
# Install wagtailtables from the host. This folder will be overwritten by a volume mount during run time (so that code
19+
# changes show up immediately), but it also needs to be copied into the image now so that wagtailtables can be pip install'd.
20+
RUN mkdir /code/wagtailtables
21+
COPY ./wagtailtables /code/wagtailtables/wagtailtables
22+
COPY ./setup.py /code/wagtailtables/
23+
COPY ./README.md /code/wagtailtables/
24+
25+
RUN cd /code/wagtailtables/ \
26+
&& pip install -e .

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Overcast Software
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include README.md LICENSE
2+
recursive-include wagtailtables *.py *.html *.js *.css

README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Wagtail Charts
2+
Chart.js charts in Wagtail, edited and customised from the Wagtail admin
3+
4+
## Getting started
5+
6+
Assuming you have a Wagtail project up and running:
7+
8+
`pip install wagtailtables`
9+
10+
Add `wagtailtables` to your settings.py in the INSTALLED_APPS section, before the core wagtail packages:
11+
12+
```python
13+
INSTALLED_APPS = [
14+
# ...
15+
'wagtailtables',
16+
# ...
17+
]
18+
```
19+
20+
Add a wagtailtables ChartBlock to one of your StreamFields:
21+
22+
```python
23+
from wagtailtables.blocks import ChartBlock
24+
25+
class ContentBlocks(StreamBlock):
26+
chart_block = ChartBlock()
27+
```
28+
29+
Include your streamblock in one of your pages
30+
31+
```python
32+
class HomePage(Page):
33+
body = StreamField(ContentBlocks())
34+
35+
content_panels = Page.content_panels + [
36+
StreamFieldPanel('body'),
37+
]
38+
```
39+
40+
Add the `wagtailtables_tags` templatetag to your template and call the `render_charts` tag just before your `</body>` closing tag.
41+
Please note that you must render your chart block so that the `render_charts` tag can detect the charts.
42+
Here is a tiny example of a page rendering template:
43+
44+
```django
45+
{% load wagtailcore_tags wagtailtables_tags %}
46+
47+
{% block content %}
48+
<div class="container-fluid">
49+
<div class="row">
50+
<div class="col-6">
51+
<h1>{{self.title}}</h1>
52+
<div class="excerpt">{{self.excerpt|richtext}}</div>
53+
</div>
54+
</div>
55+
{% for block in self.body %}
56+
{% include_block block %}
57+
{% endfor %}
58+
</div>
59+
{% endblock %}
60+
61+
{% block extra_js %}
62+
{% render_charts %}
63+
{% endblock %}
64+
```
65+
66+
## Configuration
67+
68+
`ChartBlock` accepts a few extra arguments in addition to the standard `StructBlock` arguments.
69+
70+
### `colors`
71+
A tuple of color tuples defining the available colors in the editor.
72+
73+
```python
74+
from wagtailtables.blocks import ChartBlock
75+
76+
COLORS = (
77+
('#ff0000', 'Red'),
78+
('#00ff00', 'Green'),
79+
('#0000ff', 'Blue'),
80+
)
81+
82+
class ContentBlocks(StreamBlock):
83+
chart_block = ChartBlock(colors=COLORS)
84+
```
85+
86+
### `chart_types`
87+
88+
You can override the default chart types available for your `ChartBlock` instance:
89+
90+
```python
91+
from wagtailtables.blocks import ChartBlock
92+
93+
CHART_TYPES = (
94+
('line', 'Custom title for line chart'),
95+
)
96+
97+
class ContentBlocks(StreamBlock):
98+
chart_block = ChartBlock(chart_types=CHART_TYPES)
99+
```
100+
101+
The default types are:
102+
103+
```python
104+
CHART_TYPES = (
105+
('line', 'Line Chart'),
106+
('bar', 'Vertical Bar Chart'),
107+
('bar_horizontal', 'Horizontal Bar Chart'),
108+
('area', 'Area Chart'),
109+
('multi', 'Combo Line/Bar/Area Chart'),
110+
('pie', 'Pie Chart'),
111+
('doughnut', 'Doughnut Chart'),
112+
('radar', 'Radar Chart'),
113+
('polar', 'Polar Chart'),
114+
)
115+
```
116+
117+
118+
## Dependencies
119+
* This project relies on [Jspreadsheet Community Edition](https://bossanova.uk/jspreadsheet/v4/) for data entry and manipulation.
120+
* Charts are rendered using [Chart.js](https://www.chartjs.org/).
121+
* 100% stacked bar charts use a plugin [https://github.com/y-takey/chartjs-plugin-stacked100](https://github.com/y-takey/chartjs-plugin-stacked100)

docker-compose.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: '3'
2+
3+
volumes:
4+
postgres-data:
5+
node_modules:
6+
7+
services:
8+
web:
9+
container_name: "wagtailtablesweb"
10+
build: ./
11+
working_dir: /code/wagtailtables_demo
12+
command: bash -c "./manage.py migrate && ./manage.py runserver 0.0.0.0:8000"
13+
restart: "no"
14+
volumes:
15+
- ./wagtailtables_demo:/code/wagtailtables_demo:delegated,rw
16+
- ./wagtailtables:/code/wagtailtables/wagtailtables:delegated,rw
17+
ports:
18+
- "8000:8000"
19+
- 3000:3000
20+
environment:
21+
DATABASE_URL: "postgres://wagtail:changeme@db/wagtail"
22+
PYTHONPATH: "/code/wagtail:/code/wagtailtables_demo:$PYTHONPATH"
23+
depends_on:
24+
- db
25+
db:
26+
container_name: "wagtailtablesdb"
27+
image: postgres:12.3-alpine
28+
environment:
29+
POSTGRES_USER: wagtail
30+
POSTGRES_DB: wagtail
31+
POSTGRES_PASSWORD: changeme
32+
volumes:
33+
- postgres-data:/var/lib/postgresql/data
34+
restart: "no"
35+
expose:
36+
- "5432"

setup.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
3+
from setuptools import setup
4+
5+
with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
6+
README = readme.read()
7+
8+
# allow setup.py to be run from any path
9+
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
10+
11+
# Package dependencies
12+
install_requires = [
13+
'wagtail>=1.8',
14+
]
15+
16+
# Testing dependencies
17+
testing_extras = [
18+
]
19+
20+
# Documentation dependencies
21+
documentation_extras = [
22+
]
23+
24+
setup(
25+
name='wagtailtables',
26+
version='0.1',
27+
packages=['wagtailtables'],
28+
include_package_data=True,
29+
license='MIT',
30+
description='jSpreadsheet table blocks for Wagtail',
31+
long_description=README,
32+
url='https://github.com/overcast/wagtailtables/',
33+
author='Overcast',
34+
author_email='hallo@overcast.is',
35+
long_description_content_type="text/markdown",
36+
classifiers=[
37+
'Environment :: Web Environment',
38+
'Framework :: Django',
39+
'Intended Audience :: Developers',
40+
'License :: OSI Approved :: MIT License',
41+
'Operating System :: OS Independent',
42+
'Programming Language :: Python',
43+
'Programming Language :: Python :: 2',
44+
'Programming Language :: Python :: 2.7',
45+
'Programming Language :: Python :: 3',
46+
'Programming Language :: Python :: 3.4',
47+
'Programming Language :: Python :: 3.5',
48+
'Programming Language :: Python :: 3.6',
49+
'Topic :: Internet :: WWW/HTTP',
50+
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
51+
],
52+
install_requires=install_requires,
53+
extras_require={
54+
'testing': testing_extras,
55+
'docs': documentation_extras
56+
},
57+
)

wagtailtables/__init__.py

Whitespace-only changes.

wagtailtables/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class WagtailTablesConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'wagtailtables'

0 commit comments

Comments
 (0)