Skip to main content

A set of tools and abstractions for Django projects.

Project description

wt-django-tools

Pytest codecov

Tools and abstractions for Django projects.

Installation

This project isn't yet published on PyPI. To install directly from GitHub using pip:

pip install "wt-django-tools @ git+https://github.com/ian-wt/wt-django-tools.git@master"

Once installed, add wt_tools to INSTALLED_APPS in your settings module.

INSTALLED_APPS = [
  ...
  'wt_tools',
]

Use

Pagination Tags

To use the pagination_tags templatetags library in your project, first load the tags with {% load pagination_tags %}.

To use the relative_url tag, you need to pass to the tag a page index. This could be a number or the string 'last' if the index is in the final position of the paginated QuerySet. The tag additionally accepts optional arguments for field_name and urlencode.

Most often, you'll leave the field_name parameter alone since the default value of 'page' is fairly semantic as it is. But, this value can be overridden in your views so make sure your views and the field_name arg passed to the tag are consistent.

Last, the urlencode parameter is used when a query string may be present. If your view won't ever handle a query string, then you can leave the default value of None alone.

Example

{% extends 'base.html' %}
{% load pagination_tags %}
<h1>Hello World!</h1>
<a href="{% relative_url page_obj.next_page_number %}"

To extend this example further we can supply values to override the defaults:

{% extends 'base.html' %}
{% load pagination_tags %}
<h1>Hello World!</h1>
<a href="{% relative_url page_obj.next_page_number 'page' request.GET.urlencode %}"

Note

To use this tag alone, adding wt_tools to INSTALLED_APPS isn't completely necessary. You could alternatively update TEMPLATES to include pagination_tags directly:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                ...
            ],
            'libraries': {
                'pagination_tags': 'wt_tools.templatetags.pagination_tags',
            }
        },
    },
]

However, I only recommend taking this approach if you're certain you'll use no other features (which may need explicit installation) from this package.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wt_django_tools-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wt_django_tools-1.0.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file wt_django_tools-1.0.0.tar.gz.

File metadata

  • Download URL: wt_django_tools-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for wt_django_tools-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6d03e8501f1694123d058713cd5604fc297c943113ed934bf445f500d37cffea
MD5 d615e7b2c21a57cec36a69f120587eba
BLAKE2b-256 7a214a57a4ae466a20fa3d1ec8637e033ad8f09c9c2f9e20c1f8b60ba1c9c0a5

See more details on using hashes here.

File details

Details for the file wt_django_tools-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wt_django_tools-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0150741c308303c59eeb4646e90e61c08d641b076d750e89f71b75808824d2c
MD5 bb6a6ebf47fc7d0b7ac4d54ce04a4d67
BLAKE2b-256 bc64650fe4db40393548c231e6fcb2814ff32449082a1bb36fe77cb7778934a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page