Metadata-Version: 2.4
Name: django-nifty-layout
Version: 0.1.1
Summary: A flexible data composition tool to simplify writing templates.
Author-email: J Fall <email@example.com>
License: MIT License
        
        Copyright (c) 2025 Joseph
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/powderflask/django-nifty-layout
Project-URL: Repository, https://github.com/powderflask/django-nifty-layout
Keywords: django-nifty-layout,nifty_layout
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Framework :: Django
Requires-Python: <4.0,>=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: django
Provides-Extra: format
Requires-Dist: black; extra == "format"
Requires-Dist: isort; extra == "format"
Provides-Extra: lint
Requires-Dist: flake8; extra == "lint"
Requires-Dist: flake8-bugbear; extra == "lint"
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-django; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: pytest-sugar; extra == "test"
Provides-Extra: utils
Requires-Dist: tox; extra == "utils"
Requires-Dist: invoke; extra == "utils"
Requires-Dist: bumpver; extra == "utils"
Requires-Dist: pip-tools; extra == "utils"
Provides-Extra: build
Requires-Dist: build; extra == "build"
Requires-Dist: twine; extra == "build"
Dynamic: license-file

# django-nifty-layout

[![PyPI Version](https://img.shields.io/pypi/v/nifty_layout.svg)](https://pypi.python.org/pypi/django-nifty-layout) ![Test with tox](https://github.com/powderflask/django-nifty-layout/actions/workflows/tox.yaml/badge.svg) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/powderflask/django-nifty-layout)

Version: 0.1.1

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

1. Install the `django-nifty-layout` package from PyPI
    ```bash
    $ pip install django-nifty-layout
    ```

2. 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: None 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"),
                ),
                dict(
                    name="reported_by_name",
                    contact_methods=Seq("reported_by_phone_num", "reported_by_email"),
                    ),
                )
            ),
            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.children %}
      <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.children %}
      <div class="col">
        {% include "contact_card.html" %}
      </div>
    {% endfor %}
  </div>
   ...
</div>   
```

## Get Me Some of That
* [Source Code](https://github.com/powderflask/django-nifty-layout)

* [Issues](https://github.com/powderflask/django-nifty-layout/issues)
* [PyPI](https://pypi.org/project/django-nifty-layout)

[MIT License](https://github.com/powderflask/django-nifty-layout/blob/master/LICENSE)

### Check Out the Demo App  ** coming soon **

1. `pip install -e git+https://github.com/powderflask/django-nifty-layout.git#egg=django-nifty-layout`
1. `python django-nifty-layout/manage.py install_demo`
1. `python django-nifty-layout/manage.py runserver`


### Acknowledgments
This project would be impossible to maintain without the help of our generous [contributors](https://github.com/powderflask/django-nifty-layout/graphs/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`](https://www.cookiecutter.io/) 
and the [`cookiecutter-powder-pypackage`](https://github.com/JacobTumak/CookiePowder) project template.


## For Developers
Install `invoke`, `pip-tools`, `tox` for all the CLI goodness
  ```bash
   pip install invoke pip-tools tox
   ```

Initialise the development environment using the invoke task
   ```bash
   inv tox.venv
   ```
Or create it with tox directly
   ```bash
   tox d -e dev .venv
   ```
Or build and install the dev requirements with pip
   ```bash
   inv deps.compile-dev
   pip install -r requirements_dev.txt
   ```

### Tests
   ```bash
   pytest
   ```
or
   ```bash
   tox r
   ```
or run tox environments in parallel using
   ```bash
   tox p
   ```

### Code Style / Linting
   ```bash
   $ isort
   $ black
   $ flake8
   ```

### Versioning
 * [Semantic Versioning](https://semver.org/)
   ```bash
   $ bumpver show
   ```

### Build / Deploy Automation
 * [invoke](https://www.pyinvoke.org/)
   ```bash
   $ invoke -l
   ```
 * [GitHub Actions](https://docs.github.com/en/actions) (see [.github/workflows](https://github.com/powderflask/django-nifty-layout/tree/master/.github/workflows))
 * [GitHub Webhooks](https://docs.github.com/en/webhooks)  (see [settings/hooks](https://github.com/powderflask/django-nifty-layout/settings/hooks))
