django-pragmatic


Namedjango-pragmatic JSON
Version 6.0.3 PyPI version JSON
download
home_pagehttps://github.com/PragmaticMates/django-pragmatic
SummaryPragmatic tools and utilities for Django projects
upload_time2024-11-21 11:42:48
maintainerPragmatic Mates
docs_urlNone
authorPragmatic Mates
requires_pythonNone
licenseBSD License
keywords django pragmatic tools utils
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            .. image:: https://travis-ci.org/PragmaticMates/django-pragmatic.svg?branch=master
    :target: https://travis-ci.org/PragmaticMates/django-pragmatic

django-pragmatic
================

Pragmatic tools and utilities for Django projects

Tested on Django 1.5 up to Django 1.10.2


Requirements
------------
- Django

Some utilities require additional libraries as:

- django_filters
- fpdf
- Pillow/PIL
- pyBarcode


Installation
------------

1. Install python library using pip: pip install django-pragmatic

2. Add ``pragmatic`` to ``INSTALLED_APPS`` in your Django settings file


Usage
-----

Templates
'''''''''
``pragmatic/helpers/breadcrumbs.html``
    Template helper for **django-breadcrumbs** app.

``pragmatic/helpers/confirm_delete.html``
    Form for delete confirmation.

``pragmatic/helpers/messages.html``
    Template helper for django messages framework.

``pragmatic/helpers/pagination.html``
    Template helper for paginating objects in ListViews.

``pragmatic/helpers/pagination-listview.html``
    Template helper for paginating objects in ListViews.

``maintenance_mode.html``
    Template for maintenance mode. See **MaintenanceModeMiddleware** below.


Template tags
'''''''''''''
``{% load pragmatic_tags %}``

``def klass(obj)``
    Returns string of instance class name.

``def translate(obj)``
    Returns translated string of input value (string or any object).

``def filename(obj)``
    Returns name of the file without its path (basename).

``def bootstrap3_field(field)``
    Adds *form-control* class to field widget classes.

``def filtered_objects_counts(filtered, all)``
    Returns translatable percentage description of value filtered/all in this format:
    *'<strong>%d (%.2f%%)</strong> filtered, from a total of %d' % (filtered, percent, all)'*

``def qrcode(value, alt=None)``
    Outputs generated QR code using Google charts API from a given string and adds alternative description to it.

``def barcode(code, args=None)``:
    Outputs generated barcode using pyBarcode library from a given string.

``def paginator(context, objects, page_ident='page', anchor=None, adjacent=2)``
    Pagination template tag.

``def divide(value, arg)``
    Divides the value by argument.

``def multiply(value, arg)``
    Multiplies the value by argument.

``def add(value, arg)``
    Adds the arg to the value.

``def subtract(value, arg)``
    Subtracts the arg to the value.

``def capture(parser, token)``
    Capture contents of block into context.


Context processors
''''''''''''''''''
``def date_formats(request)``
    Returns a lazy 'date formats' context variables DATE_FORMAT_JS, DATE_FORMAT_TAG, DATE_FORMAT_FULLMONTH_TAG,
    from settings file.

``def installed_apps(request)``
    Returns a lazy 'INSTALLED_APPS' context variable.


Decorators
''''''''''
``def permissions_required(app_label, login_url=None, raise_exception=False)``
    Decorator for views that checks whether a user has at least one app permission
    enabled, redirecting to the log-in page if necessary.
    If the raise_exception parameter is given the PermissionDenied exception
    is raised and app label of missing permission is stored in user instance.

``def permission_required(perm, login_url=None, raise_exception=False)``
    Decorator for views that checks whether a user has a particular permission
    enabled, redirecting to the log-in page if necessary.
    If the raise_exception parameter is given the PermissionDenied exception
    is raised and missing permission is stored in user instance.

``def receiver_subclasses(signal, sender, dispatch_uid_prefix, **kwargs)``
    A decorator for connecting receivers and all receiver's subclasses to signals.


Fields
''''''
``class RangeField(forms.Field)``
    Form field which expects input to be a number or number range (2 numbers divided with '-').

``class MultiSelectField(models.Field)``
    Model field which stores multiple choices as a comma-separated list of values, using the normal CHOICES attribute.

``class MultiSelectFormField(forms.MultipleChoiceField)``
    Form field for model field above (MultiSelectField).

``class TruncatedModelChoiceField(forms.ModelChoiceField)``
    ModelChoiceField is a form field which truncates overflowed characters from instance label
    and adds '...' instead of them.


Filters
'''''''
``class TruncatedModelChoiceFilter(forms.ModelChoiceField)``
    Filter field for TruncatedModelChoiceField.

``class OneFieldRangeFilter(django_filters.Filter)``
    Filter field for RangeField.


Middleware
''''''''''
``class MaintenanceModeMiddleware(object)``
    It looks for ``settings.MAINTENANCE_MODE`` attribute.
    If it is set to True, template **maintenance_mode.html** will render for each request.


Loghandlers
'''''''''''
``class AlternativeAdminEmailHandler(AdminEmailHandler)``
    Same as ``django.utils.log import AdminEmailHandler``, but uses ``ALTERNATE_EMAIL_HOST_PASSWORD``,
    ``ALTERNATE_EMAIL_HOST_USER``,  ``ALTERNATE_EMAIL_HOST``, ``ALTERNATE_EMAIL_PORT`` and
    ``ALTERNATE_EMAIL_USE_TLS`` as connection settings.


Mixins
''''''
``class ReadOnlyFormMixin(forms.BaseForm)``
    Adds 'readonly and 'disabled' attributes to fields specified in ``read_only`` form attribute.

``class DeleteObjectMixin(object)``
    Mixin for object delete confirmation. Implement ``get_parent()`` method or ``get_success_url()``
    and ``get_back_url()`` methods instead.

``class PickadateFormMixin(object)``
    Mixin which fixes **pickadate.js** inputs and adds *data-value* attribute to them if you use your own date formats.

``class FPDFMixin(object)``
    Mixin helper for generating PDF outputs in Django using fpdf library.


Widgets
'''''''
``class GroupedCheckboxSelectMultiple(CheckboxSelectMultiple)``
    Advanced form field widget for grouping multiple choices into custom groups.
    Use it with **static/js/grouped-checkboxes.js**


Thirdparty
''''''''''
``class BarcodeImageWriter(ImageWriter)``
    Fixed version of barcode.writer.ImageWriter.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PragmaticMates/django-pragmatic",
    "name": "django-pragmatic",
    "maintainer": "Pragmatic Mates",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": "info@pragmaticmates.com",
    "keywords": "django pragmatic tools utils",
    "author": "Pragmatic Mates",
    "author_email": "info@pragmaticmates.com",
    "download_url": "https://files.pythonhosted.org/packages/b0/d6/2ec8984f486cc56bf0d5c98b389642b973198d2014e9ef0132374ee5894d/django_pragmatic-6.0.3.tar.gz",
    "platform": null,
    "description": ".. image:: https://travis-ci.org/PragmaticMates/django-pragmatic.svg?branch=master\n    :target: https://travis-ci.org/PragmaticMates/django-pragmatic\n\ndjango-pragmatic\n================\n\nPragmatic tools and utilities for Django projects\n\nTested on Django 1.5 up to Django 1.10.2\n\n\nRequirements\n------------\n- Django\n\nSome utilities require additional libraries as:\n\n- django_filters\n- fpdf\n- Pillow/PIL\n- pyBarcode\n\n\nInstallation\n------------\n\n1. Install python library using pip: pip install django-pragmatic\n\n2. Add ``pragmatic`` to ``INSTALLED_APPS`` in your Django settings file\n\n\nUsage\n-----\n\nTemplates\n'''''''''\n``pragmatic/helpers/breadcrumbs.html``\n    Template helper for **django-breadcrumbs** app.\n\n``pragmatic/helpers/confirm_delete.html``\n    Form for delete confirmation.\n\n``pragmatic/helpers/messages.html``\n    Template helper for django messages framework.\n\n``pragmatic/helpers/pagination.html``\n    Template helper for paginating objects in ListViews.\n\n``pragmatic/helpers/pagination-listview.html``\n    Template helper for paginating objects in ListViews.\n\n``maintenance_mode.html``\n    Template for maintenance mode. See **MaintenanceModeMiddleware** below.\n\n\nTemplate tags\n'''''''''''''\n``{% load pragmatic_tags %}``\n\n``def klass(obj)``\n    Returns string of instance class name.\n\n``def translate(obj)``\n    Returns translated string of input value (string or any object).\n\n``def filename(obj)``\n    Returns name of the file without its path (basename).\n\n``def bootstrap3_field(field)``\n    Adds *form-control* class to field widget classes.\n\n``def filtered_objects_counts(filtered, all)``\n    Returns translatable percentage description of value filtered/all in this format:\n    *'<strong>%d (%.2f%%)</strong> filtered, from a total of %d' % (filtered, percent, all)'*\n\n``def qrcode(value, alt=None)``\n    Outputs generated QR code using Google charts API from a given string and adds alternative description to it.\n\n``def barcode(code, args=None)``:\n    Outputs generated barcode using pyBarcode library from a given string.\n\n``def paginator(context, objects, page_ident='page', anchor=None, adjacent=2)``\n    Pagination template tag.\n\n``def divide(value, arg)``\n    Divides the value by argument.\n\n``def multiply(value, arg)``\n    Multiplies the value by argument.\n\n``def add(value, arg)``\n    Adds the arg to the value.\n\n``def subtract(value, arg)``\n    Subtracts the arg to the value.\n\n``def capture(parser, token)``\n    Capture contents of block into context.\n\n\nContext processors\n''''''''''''''''''\n``def date_formats(request)``\n    Returns a lazy 'date formats' context variables DATE_FORMAT_JS, DATE_FORMAT_TAG, DATE_FORMAT_FULLMONTH_TAG,\n    from settings file.\n\n``def installed_apps(request)``\n    Returns a lazy 'INSTALLED_APPS' context variable.\n\n\nDecorators\n''''''''''\n``def permissions_required(app_label, login_url=None, raise_exception=False)``\n    Decorator for views that checks whether a user has at least one app permission\n    enabled, redirecting to the log-in page if necessary.\n    If the raise_exception parameter is given the PermissionDenied exception\n    is raised and app label of missing permission is stored in user instance.\n\n``def permission_required(perm, login_url=None, raise_exception=False)``\n    Decorator for views that checks whether a user has a particular permission\n    enabled, redirecting to the log-in page if necessary.\n    If the raise_exception parameter is given the PermissionDenied exception\n    is raised and missing permission is stored in user instance.\n\n``def receiver_subclasses(signal, sender, dispatch_uid_prefix, **kwargs)``\n    A decorator for connecting receivers and all receiver's subclasses to signals.\n\n\nFields\n''''''\n``class RangeField(forms.Field)``\n    Form field which expects input to be a number or number range (2 numbers divided with '-').\n\n``class MultiSelectField(models.Field)``\n    Model field which stores multiple choices as a comma-separated list of values, using the normal CHOICES attribute.\n\n``class MultiSelectFormField(forms.MultipleChoiceField)``\n    Form field for model field above (MultiSelectField).\n\n``class TruncatedModelChoiceField(forms.ModelChoiceField)``\n    ModelChoiceField is a form field which truncates overflowed characters from instance label\n    and adds '...' instead of them.\n\n\nFilters\n'''''''\n``class TruncatedModelChoiceFilter(forms.ModelChoiceField)``\n    Filter field for TruncatedModelChoiceField.\n\n``class OneFieldRangeFilter(django_filters.Filter)``\n    Filter field for RangeField.\n\n\nMiddleware\n''''''''''\n``class MaintenanceModeMiddleware(object)``\n    It looks for ``settings.MAINTENANCE_MODE`` attribute.\n    If it is set to True, template **maintenance_mode.html** will render for each request.\n\n\nLoghandlers\n'''''''''''\n``class AlternativeAdminEmailHandler(AdminEmailHandler)``\n    Same as ``django.utils.log import AdminEmailHandler``, but uses ``ALTERNATE_EMAIL_HOST_PASSWORD``,\n    ``ALTERNATE_EMAIL_HOST_USER``,  ``ALTERNATE_EMAIL_HOST``, ``ALTERNATE_EMAIL_PORT`` and\n    ``ALTERNATE_EMAIL_USE_TLS`` as connection settings.\n\n\nMixins\n''''''\n``class ReadOnlyFormMixin(forms.BaseForm)``\n    Adds 'readonly and 'disabled' attributes to fields specified in ``read_only`` form attribute.\n\n``class DeleteObjectMixin(object)``\n    Mixin for object delete confirmation. Implement ``get_parent()`` method or ``get_success_url()``\n    and ``get_back_url()`` methods instead.\n\n``class PickadateFormMixin(object)``\n    Mixin which fixes **pickadate.js** inputs and adds *data-value* attribute to them if you use your own date formats.\n\n``class FPDFMixin(object)``\n    Mixin helper for generating PDF outputs in Django using fpdf library.\n\n\nWidgets\n'''''''\n``class GroupedCheckboxSelectMultiple(CheckboxSelectMultiple)``\n    Advanced form field widget for grouping multiple choices into custom groups.\n    Use it with **static/js/grouped-checkboxes.js**\n\n\nThirdparty\n''''''''''\n``class BarcodeImageWriter(ImageWriter)``\n    Fixed version of barcode.writer.ImageWriter.\n",
    "bugtrack_url": null,
    "license": "BSD License",
    "summary": "Pragmatic tools and utilities for Django projects",
    "version": "6.0.3",
    "project_urls": {
        "Homepage": "https://github.com/PragmaticMates/django-pragmatic"
    },
    "split_keywords": [
        "django",
        "pragmatic",
        "tools",
        "utils"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b0d62ec8984f486cc56bf0d5c98b389642b973198d2014e9ef0132374ee5894d",
                "md5": "c40c9ffdf2049c1aeac77b459396e6eb",
                "sha256": "f55fcdfecc23f98fbc825716555a0aaa84d6fb6fe481d3e50aec5d614a6add76"
            },
            "downloads": -1,
            "filename": "django_pragmatic-6.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "c40c9ffdf2049c1aeac77b459396e6eb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 47827,
            "upload_time": "2024-11-21T11:42:48",
            "upload_time_iso_8601": "2024-11-21T11:42:48.900219Z",
            "url": "https://files.pythonhosted.org/packages/b0/d6/2ec8984f486cc56bf0d5c98b389642b973198d2014e9ef0132374ee5894d/django_pragmatic-6.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-21 11:42:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PragmaticMates",
    "github_project": "django-pragmatic",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-pragmatic"
}
        
Elapsed time: 0.38077s