Skip to main content

Generic reusable bits for Django projects

Project description

djinntoux 🐧

Generic reusable bits for Django projects

Disclaimer

This package is only intended for my own personal use, install at your own risk

Rebuild

Assumes twine is installed and an API token is stored in a .pypirc file:

rm -rfv dist/ && python -m build && twine upload --verbose dist/*

Installation

pip install djinntoux

Usage

Environment Variables

The following are expected to be set in your environment, a .env file, or a .envrc file:

DATABASE_URL            # no default
DJANGO_SECRET_KEY       # no default
DJANGO_DEBUG            # defaults to false
DJANGO_ENV_NAME         # defaults to prod
DJANGO_ADMIN_HEADER_BG  # defaults to red

dproj

settings_reuse

In your own project settings, use like so:

from djinntoux.dproj.settings_reuse import *  # noqa

...

INSTALLED_APPS = BASE_APPS + []

This reusable settings module expects DJANGO_SECRET_KEY to be set in your environment. For example, if you are just running your project locally, you could use an .envrc file for your development environment ...

...
export 'DJANGO_SECRET_KEY'='django-insecure-321-do-not-use-this!!!'
...

... and then use a systemd unit file for a mock production environment ...

...
[Service]
Environment='DJANGO_SECRET_KEY'='django-insecure-321-do-not-use-this!!!'
...

urls_reuse

In your project root URLconf, use like so:

urlpatterns = [
    path('', include('djinntoux.dproj.urls_reuse')),
    ...
]

Abstract Models

https://github.com/venteto/djinntoux/blob/main/djinntoux/abstract/ab_mod.py

As an example in a models.py file:

from djinntoux.abstract.ab_mod import EditLink, Timestamps, UUIDpk7

...

class Account(Timestamps, EditLink):

EditLink

Set ADMIN_PATH in project settings (do not add a leading slash), e.g. to keep the Django default path without using an environment variable:

ADMIN_PATH = 'admin/'

Then in templates you can use like so:

<a target="_blank" href="{{ obj.get_edit_path }}">Edit</a>

Custom Users App

https://github.com/venteto/djinntoux/tree/main/djinntoux/dapp_users

In project settings add djinntoux.dapp_users to INSTALLED_APPS and set AUTH_USER_MODEL = 'zy_users.User'

The admin.py file is copied verbatim from upstream, tweaked to replace the stock first_name and last_name conventions from with slightly more international options, lightly inspired by the Cookiecutter Django project. The custom user model also includes a new timezone field.

Renames

https://github.com/venteto/djinntoux/blob/main/djinntoux/dproj/rename.py

In project settings make sure INSTALLED_APPS reflects something akin to this:

    'djinntoux.dproj.rename.ContribAuth',   # replaces 'django.contrib.auth',
    'djinntoux.dproj.rename.ContribSites',  # replaces 'django.contrib.sites',

Scraping

https://github.com/venteto/djinntoux/blob/main/djinntoux/utils/scrape.py

from djinntoux.utils.scrape import get_host_and_title

Then use like so:

    def save(self, *args, **kwargs):
        if not self.link_title:
            self.link_title = get_host_and_title(self)[1]
        super(Link, self).save(*args, **kwargs)

TODO (Includes, But Not Limited To)

  • dapp_ttags (or make dproj itself an app in addition to a project directory?)
  • templates dir (including admin overrides)
  • static files? or just link to a pseudo-CDN in base template?
    • compressor?
  • robots.txt view
  • error views
  • favicon view
  • aggregation util
  • abstract view and admin classes

See Also

https://github.com/venteto/djinntoux/blob/main/READMORE.md

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

djinntoux-0.0.8.16.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

djinntoux-0.0.8.16-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file djinntoux-0.0.8.16.tar.gz.

File metadata

  • Download URL: djinntoux-0.0.8.16.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.2

File hashes

Hashes for djinntoux-0.0.8.16.tar.gz
Algorithm Hash digest
SHA256 6ddaabb5f2292aa00b5bb90be6ac03b6ac8b919727ac0c5891b47000797c804e
MD5 9d6e7a4adf7c2b5aeeea5a3474a0433d
BLAKE2b-256 f0bf20ef2f14f07ffe496c6dcb963ad9ceb7ef2cbc923d029aaa335cfa7cba64

See more details on using hashes here.

File details

Details for the file djinntoux-0.0.8.16-py3-none-any.whl.

File metadata

  • Download URL: djinntoux-0.0.8.16-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.2

File hashes

Hashes for djinntoux-0.0.8.16-py3-none-any.whl
Algorithm Hash digest
SHA256 c23ca34be5f6f46de64b2fdaa07e6ce89b361cc514a46c0d520e564a17c5fd11
MD5 86f41ea9b0556601515580d18cba0553
BLAKE2b-256 86579757c5d8ee317271296ac4e5a8ae50c4ee50cb789caa524138d870e39013

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