Metadata-Version: 2.4
Name: django_additional_tools
Version: 0.1.1
Summary: A collection of reusable Django utilities, middleware and app components.
Author: Fraqment
License: ## MIT-License
        
        Copyright © 2026 Paul Hudelmaier
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project-URL: Homepage, https://github.com/Hipposmile/django_additional_tools
Project-URL: Source, https://github.com/Hipposmile/django_additional_tools
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Django>=4.2
Dynamic: license-file

# django_additional_tools

A collection of reusable Django utilities, middleware and app components.

## Requirements

Python 3.10+

Django 4.2+ (or any newer LTS)

Works with WSGI and ASGI projects

## Installation

```bash
pip install django_additional_tools
```

## Features

Production‑only and development‑only decorators

Production/development template tags

Production/development boolean helpers

CSP nonce middleware

Configurable CSP settings

## Production / Development Only

Imagine you are coding a new feature but don´t want it to be available for users yet. But you need to fix bugs etc. the same time so you have to push updates. This library solves this problem: There are different features that make specific code only available in production or development use, specified by django´s very own DEBUG setting.

```python
INSTALLED_APPS += ['django_additional_tools']
```

### Views
Use
```python
from django_additional_tools.django_production_development_only.tags import production_only

@production_only
def my_view(request):
    return render(request, 'my_template')
```
or
```python
from django_additional_tools.django_production_development_only.tags import development_only

@development_only
def my_view(request):
    return render(request, 'my_template')
```
to make a whole view only available in production or development mode.

### Templates
Use
```html
{% load production %}

{% if production %}
    <h1>You´re in production mode</h1>
{% endif %}
```
or
```html
{% load development %}

{% if development %}
    <h1>You´re in development mode</h1>
{% endif %}
```
to make a whole view only available in production or development mode.

### If-Clauses
Use
```python
from django_additional_tools.django_production_development_only.ifs import production_only

def my_view(request):
    if production_only:
        print('You´re in production mode')
    return render(request, 'my_template')
```
or
```python
from django_additional_tools.django_production_development_only.ifs import development_only

def my_view(request):
    if development_only:
        print('You´re in development mode')
    return render(request, 'my_template')
```

## Content Security Policy

Add a content security policy to your website to secure it.

```python
MIDDLEWARE += ['django_additional_tools.middleware.generate_csp_nonce_middleware']
# Add your configuration data here, e.g. the allowed script sources
```
```python
# Your CSP will look like this
csp = (
    "default-src 'self'; "
    f"script-src 'self' 'nonce-{script_nonce}' {settings.CSP_ALLOWED_SCRIPT_DATA}; "
    f"style-src 'self' 'nonce-{style_nonce}' {settings.CSP_ALLOWED_SCRIPT_DATA}; "
    f"img-src 'self' {settings.CSP_ALLOWED_IMG_DATA}; "
    f"frame-src {settings.CSP_ALLOWED_FRAME_DATA}; "
    f"connect-src 'self' {settings.CSP_CONNECT_DATA}; "
    f"media-src {settings.CSP_ALLOWED_MEDIA_DATA}"
)
# You can configure CSP_ALLOWED_SCRIPT_DATA etc. in the settings.
```

## License

Copyright © 2026 Paul Hudelmaier

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
