Welcome to Nim Django Helpers documentation!

Context Processors

General context processors for NDH.

ndh.context_processors.settings_constants(request: HttpRequest) dict[str, str]

Set constants from settings to template contexts.

Forms

General Form-related helpers for NDH.

class ndh.forms.AccessibleDateTimeField(*, input_date_formats=None, input_time_formats=None, **kwargs)

Set date & time HTML types.

class ndh.forms.DatalistField(datalist=None, **kwargs)

A CharField with datalist options.

Mixins

General view Mixins for NDH.

class ndh.mixins.AttrContextMixin

Mixin to add view attributes to context.

get_context_data(**kwargs)

Update context from attributes.

class ndh.mixins.NDHDeleteMixin

Mixin setting a default template for delete views.

class ndh.mixins.NDHFormMixin

Mixin setting a default form template and title.

get_success_url()

Redirect to current page if continue_edit.

class ndh.mixins.SuperUserRequiredMixin

Mixin that allow access only to superusers.

test_func()

Check that the user has superuser access.

Models

Helpers for models.

A mixin to get links.

get_absolute_url() str

Get the absolute url for a queryset or an instance.

get_admin_url() str

Get the admin url for an instance.

classmethod get_create_url(app=True) str

Get the absolute url to create an instance of this model.

get_delete_url(app=True) str

Get the absolute url to delete an instance of this model.

get_detail_url(app=True) str

Get the absolute url to detail an instance of this model.

get_full_admin_url() str

Get the protocol + domain + admin_url.

Get the full HTML link for this absolute_url.

Get the full Markdown link for this absolute_url.

get_full_url() str

Get the protocol + domain + absolute_url.

Get the HTML link for this absolute_url.

classmethod get_list_url(app=True) str

Get the absolute url to list instances of this model.

Get the Markdown link for this absolute_url.

get_pk_or_slug()

Provide the right kwargs for reverse().

get_update_url(app=True) str

Get the absolute url to update an instance of this model.

classmethod get_view_name(suffix, app=True) str

Provide the common view name prefix.

class ndh.models.NamedModel(*args, **kwargs)

Mixin to name and slugify a model.

class Meta

Meta.

class ndh.models.TimeStampedModel(*args, **kwargs)

Mixin to timestamp a model.

class Meta

Meta.

Query Sets

General QuerySets for NDH.

class ndh.querysets.NameOrderedQuerySet(model=None, query=None, using=None, hints=None)

Order a queryset on the “name” field.

name_ordered() QuerySet

Order by name.

Template Tags

Django template tags for NDH.

ndh.templatetags.ndh.admin_url(obj) str

Get the admin url of a Model or QuerySet instance.

ndh.templatetags.ndh.navbar_item(context, view_name: str, link: str) str

Get a navbar item, activated if its url is in the current request path.

ndh.templatetags.ndh.show_email(context: dict, mail: str) str

Show an email as a link to connected users, and obfuscated for others.

ndh.templatetags.ndh.user_smcp(user)

Get user’s capitalized first_name + capitalized & small-capsed last_name.

Utils

General utils for NDH.

ndh.utils.full_url(url: str = '', domain: str | None = None, protocol: str = 'https') str

Prepend protocol and domain name to an url.

ndh.utils.get_env(env_file: str = '.env') None

Set default environment variables from .env file.

ndh.utils.query_sum(queryset: QuerySet | RelatedManager, field: str, output_field: Field | None = None) Numeric

Let the DBMS perform a sum on a queryset.

Changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

v6.2.0 - 2023-04-06

  • Add ndh.tests.TestNDHLinks

v6.1.0 - 2023-04-03

  • improve Links with getters for create, delete, detail, list & update urls

v6.0.0 - 2023-03-24

  • :warning: require python 3.10

  • add AttrContextMixin

  • update tooling

v5.12.1 - 2023-02-02

  • typo

v5.12.0 - 2023-02-02

  • utils.get_env() works in main dir or subdir, for use in manage.py, wsgi.py and asgi.py

  • utils.get_env() discard lines starting with #

v5.11.3 - 2022-10-16

  • update unit tests

v5.11.2 - 2022-10-16

  • navbar with more flex and less floats

v5.11.1 - 2022-10-16

  • fix navbar responsiveness

v5.11.0 - 2022-10-16

  • add template tags to docs

  • add user_smcp filter, for capitalized first_name + capitalized & small-capsed last_name

v5.10.0 - 2022-10-11

  • add templates/ndh/dt.html to represent a datetime

v5.9.1 - 2022-10-10

  • clarify delete.html

v5.9.0 - 2022-10-07

  • add ndh_form_action variable in ndh/form.html

v5.8.2 - 2022-09-24

  • fix tables template for non paginated ones

v5.8.1 - 2022-09-08

  • update bootstrap to 5.2.1

  • update django-bootstrap5 to 22.1

v5.8.0 - 2022-08-30

  • add datalist support

v5.7.4 - 2022-08-29

  • fix previous release

v5.7.3 - 2022-08-29

  • fix AccessiblDateTimeField for localized date initial value

v5.7.2 - 2022-08-26

  • fix NDHFormMixin.get_success_url

v5.7.1 - 2022-08-26

  • implement NDHFormMixin.continue_edit for formsets

v5.7.0 - 2022-08-26

  • added NDHFormMixin.continue_edit

v5.6.0 - 2022-08-25

  • added Links.get_md_link

  • added Links.get_full_link

  • added Links.get_full_md_link

v5.5.5 - 2022-08-19

  • Allow ManyRelatedManager in Links

  • Remove mypy

v5.5.4 - 2022-03-16

  • update tools configuration

  • fix 88 col line length

  • remove uselesse button in password reset complete

v5.5.3 - 2022-03-13

  • extraneous block in registration

v5.5.2 - 2022-03-13

  • missing load in registration

v5.5.1 - 2022-03-12

  • typo

  • model fields translations

v5.5.0 - 2022-03-11

  • templates: add formset & tables over django_tables2/bootstrap4.html for pagination

  • style: bigger buttons

v5.4.2 - 2022-02-28

  • fix missing load i18n in templates

v5.4.1 - 2022-02-28

v5.4.0 - 2022-02-28

  • translations

  • add pyupgrade

v5.3.0 - 2022-02-23

  • add Links.get_full_admin_url

v5.2.0 - 2022-02-23

  • fix typing for related manager

  • yapf → black

  • move most tooling conf from setup.cfg to pyproject.toml

  • CI: check python 3.10

  • set __version__ / __version_tuple__ from release.sh

v5.1.2 - 2021-12-20

  • fix docs

v5.1.1 - 2021-12-20

  • release: typo

v5.1.0 - 2021-12-20

  • remove obsolete boostrap 4 css

  • remove setuptools & setup.py

v5.0.1 - 2021-09-17

  • fix README

v5.0.0 - 2021-09-17

  • :warning: BREAKING :warning: require python >= 3.8

  • fix doc generation

v4.0.0 - 2021-09-17

v3.12.6 - 2021-08-07

  • fix release action

v3.12.5 - 2021-08-07

  • fix release action

v3.12.4 - 2021-08-07

  • fix release action

v3.12.3 - 2021-08-07

  • fix release action

v3.12.2 - 2021-08-07

  • fix release action

v3.12.1 - 2021-08-07

  • fix release action

v3.12.0 - 2021-08-07

  • fix docs generation

  • fix tags name in CHANGELOG

  • setup github release from github actions

v3.11.1 - 2021-07-25

  • add README on PyPI

v3.11.0 - 2021-07-25

  • :warning: deprecated enum_to_choices, as a better version is available in django 3.0.

  • added output_field argument for query_sum, and a unit test

  • added documentation

  • added changelog

  • setup automatic publication on PyPI & Docker Hub

  • internaly fixed W042

  • internaly switched from pipenv to poetry

  • internaly switched from travis to github actions

  • internaly switched from coveralls to codecov

v3.10.4 - 2020-02-03

  • more type hints

  • update CI

v3.10.3 - 2020-01-11

  • use setuptools-scm

v3.10.2 - 2020-01-11

  • Add mypy to pre-commit

  • pep-561 compliance

v3.10.1 - 2020-01-06

  • Improve tooling with:

    • mypy

    • pydocstyle

    • pre-commit

  • Update:

    • Python 3.8

    • Django 3.0

v3.10.0 - 2020-01-06

v3.9.4 - 2019-02-24

  • fix the regex to get the requirements right.

v3.9.3 - 2019-02-24

v3.9.2 - 2019-02-24

v3.9.1 - 2019-02-24

  • Use django-autoslug again

v3.9.0 - 2018-09-05

  • Add navbar_item templatetag

v3.8.1 - 2018-08-08

  • Fix packaging for python 3.6 & 3.7

v3.8.0 - 2018-08-08

  • update dependencies (bootstrap 4.0.0 -> 4.1.3)

  • add semantic blocks (<header> & <main>)

  • allow customisation by adding xblocks header_navbar & main_content

v3.7.1 - 2018-08-04

  • Fix packaging

v3.7.0 - 2018-08-04

  • use only Pipfile

  • add NDHDeleteMixin

  • fix compatibility with Django 2.1

v3.6.0 - 2018-07-13

  • NamedModel querysets can now be ordered by name with NamedModel.objects.name_ordered()

v3.5.1 - 2018-04-01

v3.5.0 - 2018-04-01

v3.4.0 - 2018-03-31

v3.3.0 - 2018-03-26

v2.1.0 - 2018-03-12

  • backport utils.get_env in v2

v3.2.1 - 2018-03-10

v3.2.0 - 2018-03-05

v3.1.0 - 2018-03-01

v3.0.3 - 2018-02-17

v3.0.2 - 2018-02-17

v3.0.1 - 2018-02-17

v3.0.0 - 2018-02-17

v2.0.0 - 2018-01-12

Indices and tables