Metadata-Version: 1.2
Name: django-shouty-templates
Version: 0.1.5
Summary: Applies a monkeypatch which forces Django's template language to error far more loudly about invalid assumptions
Home-page: https://github.com/kezabelle/django-shouty-templates
Author: Keryn Knight
Author-email: django-shouty-templates@kerynknight.com
Maintainer: Keryn Knight
Maintainer-email: django-shouty-templates@kerynknight.com
License: BSD License
Description: django-shouty-templates
        =======================
        
        :author: Keryn Knight
        :version: 0.1.5
        
        
        Rationale
        ---------
        
        Given a template like this::
        
            <html><head></head>
            <body>
            {% if chef.can_add_cakes %}
                <label class="alert alert-{{ chef.is_cake_chef|yesno:"success,danger,default" }}
            {% endif %}
        
        everything works fine, until any of the following happens:
        
        - ``chef`` is no longer the name of the variable.
        - ``can_add_cakes`` is refactored to be called ``can_add_pastries``
        - ``is_cake_chef`` is renamed ``is_pastry_king``
        
        If those happen, the template will either silently display nothing, or will
        display the label incorrectly.
        
        This app applies a monkeypatch which forces Django's template language to error
        far more loudly about invalid assumptions.
        
        Specifically:
        
        - ``chef`` would raise an exception if the variable were called ``sous_chef``
        - ``chef.can_add_cakes`` would raise an exception if ``can_add_cakes`` was no longer a valid attribute/property/method of ``chef``
        - ``chef.is_cake_chef`` would raise an exception for the same reasons.
        
        Thus you can refactor somewhat more freely, knowing that if the template renders
        it's OK. It ain't compile time safety, but it's better than silently swallowing
        errors because you forgot something!
        
        Setup
        -----
        
        Add ``shouty`` or ``shouty.Shout`` to your ``settings.INSTALLED_APPS``
        
        Optional configuration
        ^^^^^^^^^^^^^^^^^^^^^^
        
        A list of values which may be set in your project's settings module:
        
        settings.SHOUTY_VARIABLES
        +++++++++++++++++++++++++
        
        May be ``True|False`` and determines if the exception is raised when trying to
        use a variable which doesn't exist.
        
        Defaults to ``True``.
        
        
        settings.SHOUTY_URLS
        ++++++++++++++++++++
        
        May be ``True|False`` and determines if an exception is raised when
        doing ``{% url 'myurl' as my_var %}`` and ``myurl`` doesn't actually resolve to a view.
        
        Defaults to ``True``.
        
        settings.SHOUTY_VARIABLE_BLACKLIST
        ++++++++++++++++++++++++++++++++++
        
        Useful for if you are trying to fix up an existing project, or ignore problems
        in third-party templates.
        
        Expects a ``tuple`` of ``str`` where each one represents a template usage to ignore::
        
            SHOUTY_VARIABLE_BLACKLIST = ("chef.can_add_cakes", "my_sometimes_set_variable")
        
        May also be a ``dict`` of ``str`` keys and a sequence (eg: ``tuple`` or ``list``) of templates in which to ignore it::
        
            SHOUTY_VARIABLE_BLACKLIST = {
                "chef.can_add_cakes": ("*",),
                "my_sometimes_set_variable": ["admin/custom_view.html", "admin/custom_view_detail.html"],
                "random_in_memory_template": ["<unknown source>"],
            }
        
        settings.SHOUTY_URL_BLACKLIST
        +++++++++++++++++++++++++++++
        
        A ``tuple`` of ``2-tuple`` to prevent certain URLs and their output variables f
        rom shouting at you loudly. Useful forexisting projects or third-party apps which are less strict.
        
        By way of example, ``{% url "myurl" as my_var %}`` may be suppressed with::
        
            SHOUTY_URL_BLACKLIST = (
                ('myurl', 'my_var'),
            )
        
        which would still let ``{% url "myurl as "my_other_var %}`` raise an exception.
        
        Default configuration
        ^^^^^^^^^^^^^^^^^^^^^
        
        There's a hard-coded blacklist of variables and URLs to make sure the Django admin and
        django-debug-toolbar work.
        
        Tests
        -----
        
        Just run ``python3 -m shouty`` and hope for the best. I usually do.
        
        The license
        -----------
        
        It's `FreeBSD`_. There's should be a ``LICENSE`` file in the root of the repository, and in any archives.
        
        .. _FreeBSD: http://en.wikipedia.org/wiki/BSD_licenses#2-clause_license_.28.22Simplified_BSD_License.22_or_.22FreeBSD_License.22.29
        
        
        ----
        
        Copyright (c) 2019, Keryn Knight
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
        
        ----
        
        Change history for django-shouty-templates
        ------------------------------------------
        0.1.5
        ^^^^^^
        * Feature: system check to validate any `SHOUTY_VARIABLE_BLACKLIST` in your settings.
        * Feature: Attempt to highlight the exception location in any subtemplate, better than Django currently does.
        * Feature: Update exception message with any potential typo candidates.
        * Feature: Silencing missing variables on a per-template basis.
        * Feature: Deep inspection of ``{% if ... %} {% elif ... %}``` nodes for any which are variables which don't exist.
        * Bugfix: Patch methods hidden from the debug error page should now be consistently hidden always, rather than dependant on hitting the expected branch.
        * Bugfix: Unit tests now exist to demonstrate how it should behave, at least on Django 2.2~
        
        0.1.4
        ^^^^^^
        * Feature: the patch methods themselves (``new_resolve_lookup`` and ``new_url_render``) are skipped during rendering the debug error page. The exception message and functionality remain the same.
        * Feature: exception messages now attempt to clarify what template name (loader relative) was rendering when the missing variable was encountered.
        * Chore: Updated the ``mypy`` type signatures for some of the variables and methods to indicate the only values I'm expecting to accept.
        
        0.1.3
        ^^^^^^
        * Feature: Silenced errors when using `debug` or `sql_queries` in a template, as they're conditionally set by `django.template.context_processors.debug`
        
        0.1.2
        ^^^^^^
        * Feature: Added 11 new tokens to the default blacklist, covering more of the default Django admin and the default exception reporter.
        * Bugfix: Changed the syntax of the `AppConfig.ready` method to be py2 type annotation compatible.
        
        0.1.1
        ^^^^^^
        * Initial release
        
Keywords: django templates DTL exception
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Natural Language :: English
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Framework :: Django
