A flexible data composition tool to simplify writing templates.
Project description
django-nifty-layout
Version: 0.2.0
A simple but flexible layout tool for composing and transforming data for structured template components.
Inspired by crispy-forms Layout, but without the forms.
django-nifty-layout is free software distributed under the MIT License.
Quick Start
-
Install the
django-nifty-layoutpackage from PyPI$ pip install django-nifty-layout
-
Go grab a drink, you are all done!
Sample Usage
layout.py
from django.utils.formats import date_format
from nifty_layout.components import (
DictCompositeNode as Dct,
FieldNode as Fld,
Seq,
)
# ----- Safe Date Formatter ----- #
date_formatter = lambda val, **kwargs: "" if val is None else date_format(val, SHORT_DATE_FORMAT)
layout = Dct(
dict(
overview=Seq(
"title",
Fld("date", formatter=date_formatter),
report_type",
"location",
labeller="Overview",
),
contacts=Seq(
Dct(dict(
name="contact_name",
contact_methods=Seq("contact_email"),
), labeller="Primary Contact"
),
Dct(dict(
name="reported_by_name",
contact_methods=Seq("reported_by_phone_num", "reported_by_email"),
), labeller="Reported By"
),
labeller="Contacts",
),
...
)
)
views.py
def report_view(request, pk):
...
obj = Report.objects.get(pk=pk)
...
return render(request, "template.html", dict(report=layout.bind(obj)))
template.html
...
<div class="report>
<h2>report.overview.label</h2>
{% for node in report.overview %}
<div class="row">
<div class="col label">{{ node.label }}</div>
<div class="col value">{{ node.value|default:"" }}</div>
{% endfor %}
</div>
{% endfor %}
<div class="row">
{% for contact in report.contacts %}
<div class="col">
{% include "contact_card.html" %}
</div>
{% endfor %}
</div>
...
</div>
Get Me Some of That
Check Out the Demo App
pip install -e git+https://github.com/powderflask/django-nifty-layout.git#egg=django-nifty-layoutinv demo.install** coming soon **python demo_app/manage.py runserver
See demo_app/README
Acknowledgments
This project would be impossible to maintain without the help of our generous contributors
Technology Colophon
Without django and the django dev team, the universe would have fewer rainbows and ponies.
This package was originally created with cookiecutter
and the cookiecutter-powder-pypackage project template.
For Developers
Install invoke, pip-tools, tox for all the CLI goodness
pip install invoke pip-tools tox
Initialise the development environment using the invoke task
inv tox.venv
Or create it with tox directly
tox d -e dev .venv
Or build and install the dev requirements with pip
inv deps.compile-dev
pip install -r requirements_dev.txt
Tests
pytest
or
tox r
or run tox environments in parallel using
tox p
Code Style / Linting
$ isort
$ black
$ flake8
Versioning
- Semantic Versioning
$ bumpver show
Build / Deploy Automation
- invoke
$ invoke -l
- GitHub Actions (see .github/workflows)
- GitHub Webhooks (see settings/hooks)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_nifty_layout-0.2.0.tar.gz.
File metadata
- Download URL: django_nifty_layout-0.2.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9d136c48a0d97ade08852cbea05d8d5d5fe2e092a81a86e23d389b2a766a806
|
|
| MD5 |
3af97dee0d5d5ae4bdafdccad74f7d6c
|
|
| BLAKE2b-256 |
bc041c860a8e6b416b603f2adb4c02f7a62daeb54e048350856ca420614d9272
|
Provenance
The following attestation bundles were made for django_nifty_layout-0.2.0.tar.gz:
Publisher:
release.yaml on powderflask/django-nifty-layout
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_nifty_layout-0.2.0.tar.gz -
Subject digest:
c9d136c48a0d97ade08852cbea05d8d5d5fe2e092a81a86e23d389b2a766a806 - Sigstore transparency entry: 774326004
- Sigstore integration time:
-
Permalink:
powderflask/django-nifty-layout@ec2251248d9769c4ed2018df04d915b1e09f4467 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/powderflask
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@ec2251248d9769c4ed2018df04d915b1e09f4467 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_nifty_layout-0.2.0-py3-none-any.whl.
File metadata
- Download URL: django_nifty_layout-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c3a8ab76a3b46a65ca1d5b798c719bbbd1402963983f4b3dbfc8ea3ad46fef7
|
|
| MD5 |
95aaaa8f49031c2dcf2d476d1a63aa1e
|
|
| BLAKE2b-256 |
e8327fc3a4ddabfa4d9b349e256558da9ac1b9a31452e83b88e23bd4472e82bb
|
Provenance
The following attestation bundles were made for django_nifty_layout-0.2.0-py3-none-any.whl:
Publisher:
release.yaml on powderflask/django-nifty-layout
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_nifty_layout-0.2.0-py3-none-any.whl -
Subject digest:
5c3a8ab76a3b46a65ca1d5b798c719bbbd1402963983f4b3dbfc8ea3ad46fef7 - Sigstore transparency entry: 774326006
- Sigstore integration time:
-
Permalink:
powderflask/django-nifty-layout@ec2251248d9769c4ed2018df04d915b1e09f4467 -
Branch / Tag:
refs/tags/0.2.0 - Owner: https://github.com/powderflask
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@ec2251248d9769c4ed2018df04d915b1e09f4467 -
Trigger Event:
push
-
Statement type: