You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

django-nifty-layout

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

django-nifty-layout

A flexible data composition tool to simplify writing templates.

0.1.1
pipPyPI
Maintainers
1

django-nifty-layout

PyPI Version Test with tox Code style: black

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

  • Install the django-nifty-layout package 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: 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

MIT License

Check Out the Demo App ** coming soon **

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

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

Build / Deploy Automation

Keywords

django-nifty-layout

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts