django-mathfilters


Namedjango-mathfilters JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/dbrgn/django-mathfilters
SummaryA set of simple math filters for Django
upload_time2020-02-10 12:02:06
maintainer
docs_urlNone
authorDanilo Bargen
requires_python
licenseMIT
keywords django template filters math
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            ##################
django-mathfilters
##################

.. image:: https://github.com/dbrgn/django-mathfilters/workflows/CI/badge.svg
    :alt: Build status
    :target: https://github.com/dbrgn/django-mathfilters/actions?query=branch%3Amaster

.. image:: https://pypip.in/d/django-mathfilters/badge.png
    :alt: PyPI download stats
    :target: https://crate.io/packages/django-mathfilters


django-mathfilters is a Python 3 module that provides different simple math
filters for Django.

Django provides an ``add`` template filter, but no corresponding subtracting,
multiplying or dividing filters.

Django ticket `#361 <https://code.djangoproject.com/ticket/361>`_ has been
closed as *wontfix*, so I had to create an alternative that is easy to install
in a new Django project.

It currently supports ``int``, ``float`` and ``Decimal`` types, or any other
type that can be converted to int or float.


Installation
============

::

    $ pip install django-mathfilters

Then add ``mathfilters`` to your ``INSTALLED_APPS``.


Usage
=====

You need to load ``mathfilters`` at the top of your template. The script
provides the following filters:

* ``sub`` – subtraction
* ``mul`` – multiplication
* ``div`` – division
* ``intdiv`` – integer (floor) division
* ``abs`` – absolute value
* ``mod`` – modulo
* ``addition`` – replacement for the ``add`` filter with support for float /
  decimal types

**Example:**

.. sourcecode:: html

    {% load mathfilters %}

    ...

    <h1>Basic math filters</h1>

    <ul>
        <li>8 + 3 = {{ 8|add:3 }}</li>

        <li>13 - 17 = {{ 13|sub:17 }}</li>

        {% with answer=42 %}
        <li>42 * 0.5 = {{ answer|mul:0.5 }}</li>
        {% endwith %}

        {% with numerator=12 denominator=3 %}
        <li>12 / 3 = {{ numerator|div:denominator }}</li>
        {% endwith %}

        <li>|-13| = {{ -13|abs }}</li>
    </ul>


Version Support
===============

This module officially supports Python 3.5+ as well as PyPy3. Support for Python
3.3 and 3.4 is provided on best-effort basis, but there are no CI tests for it.

Supported Django versions are 1.11+, 2.x and 3.x.


License
=======

`MIT License <http://www.tldrlegal.com/license/mit-license>`_, see LICENSE file.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dbrgn/django-mathfilters",
    "name": "django-mathfilters",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "django template filters math",
    "author": "Danilo Bargen",
    "author_email": "mail@dbrgn.ch",
    "download_url": "https://files.pythonhosted.org/packages/ca/a6/1e8262e52aa3cbfae277bc97c23dd4f1f6c7d7c3adaf45fb41132c312a40/django-mathfilters-1.0.0.tar.gz",
    "platform": "any",
    "description": "##################\ndjango-mathfilters\n##################\n\n.. image:: https://github.com/dbrgn/django-mathfilters/workflows/CI/badge.svg\n    :alt: Build status\n    :target: https://github.com/dbrgn/django-mathfilters/actions?query=branch%3Amaster\n\n.. image:: https://pypip.in/d/django-mathfilters/badge.png\n    :alt: PyPI download stats\n    :target: https://crate.io/packages/django-mathfilters\n\n\ndjango-mathfilters is a Python 3 module that provides different simple math\nfilters for Django.\n\nDjango provides an ``add`` template filter, but no corresponding subtracting,\nmultiplying or dividing filters.\n\nDjango ticket `#361 <https://code.djangoproject.com/ticket/361>`_ has been\nclosed as *wontfix*, so I had to create an alternative that is easy to install\nin a new Django project.\n\nIt currently supports ``int``, ``float`` and ``Decimal`` types, or any other\ntype that can be converted to int or float.\n\n\nInstallation\n============\n\n::\n\n    $ pip install django-mathfilters\n\nThen add ``mathfilters`` to your ``INSTALLED_APPS``.\n\n\nUsage\n=====\n\nYou need to load ``mathfilters`` at the top of your template. The script\nprovides the following filters:\n\n* ``sub`` \u2013 subtraction\n* ``mul`` \u2013 multiplication\n* ``div`` \u2013 division\n* ``intdiv`` \u2013 integer (floor) division\n* ``abs`` \u2013 absolute value\n* ``mod`` \u2013 modulo\n* ``addition`` \u2013 replacement for the ``add`` filter with support for float /\n  decimal types\n\n**Example:**\n\n.. sourcecode:: html\n\n    {% load mathfilters %}\n\n    ...\n\n    <h1>Basic math filters</h1>\n\n    <ul>\n        <li>8 + 3 = {{ 8|add:3 }}</li>\n\n        <li>13 - 17 = {{ 13|sub:17 }}</li>\n\n        {% with answer=42 %}\n        <li>42 * 0.5 = {{ answer|mul:0.5 }}</li>\n        {% endwith %}\n\n        {% with numerator=12 denominator=3 %}\n        <li>12 / 3 = {{ numerator|div:denominator }}</li>\n        {% endwith %}\n\n        <li>|-13| = {{ -13|abs }}</li>\n    </ul>\n\n\nVersion Support\n===============\n\nThis module officially supports Python 3.5+ as well as PyPy3. Support for Python\n3.3 and 3.4 is provided on best-effort basis, but there are no CI tests for it.\n\nSupported Django versions are 1.11+, 2.x and 3.x.\n\n\nLicense\n=======\n\n`MIT License <http://www.tldrlegal.com/license/mit-license>`_, see LICENSE file.",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A set of simple math filters for Django",
    "version": "1.0.0",
    "split_keywords": [
        "django",
        "template",
        "filters",
        "math"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ac6107083a63a564664830e352af330563763654972d27d56e42d9b6e3c744f",
                "md5": "c8087858390f182a258400fd7de2611f",
                "sha256": "64200a21bb249fbf27be601d4bbb788779e09c6e063170c097cd82c4d18ebb83"
            },
            "downloads": -1,
            "filename": "django_mathfilters-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c8087858390f182a258400fd7de2611f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5909,
            "upload_time": "2020-02-10T12:02:09",
            "upload_time_iso_8601": "2020-02-10T12:02:09.819544Z",
            "url": "https://files.pythonhosted.org/packages/8a/c6/107083a63a564664830e352af330563763654972d27d56e42d9b6e3c744f/django_mathfilters-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "caa61e8262e52aa3cbfae277bc97c23dd4f1f6c7d7c3adaf45fb41132c312a40",
                "md5": "924fe18175413cb537403b77da727de9",
                "sha256": "c9b892ef6dfc893683e75cfd0279c187a601ca68f4684c38f9da44657fb64b07"
            },
            "downloads": -1,
            "filename": "django-mathfilters-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "924fe18175413cb537403b77da727de9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5699,
            "upload_time": "2020-02-10T12:02:06",
            "upload_time_iso_8601": "2020-02-10T12:02:06.569715Z",
            "url": "https://files.pythonhosted.org/packages/ca/a6/1e8262e52aa3cbfae277bc97c23dd4f1f6c7d7c3adaf45fb41132c312a40/django-mathfilters-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-02-10 12:02:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "dbrgn",
    "github_project": "django-mathfilters",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "django-mathfilters"
}
        
Elapsed time: 0.20093s