A reusable Django app with small set of utilities for urls, viewsets, commands and more
Project description
utils-plus
A simple reusable Django app with various mixins and utility functions.
Installation
install the package using the below command
pip install django-utils-plus
or install the development version using
pip install git://github.com/jnoortheen/django-utils-plus.git@master#egg=django-utils-plus
Utils
Management Commands
- clear_records
- create_admin
- test_mail
- cleardata
- create_middleware
Template tags
serve static files using npm
it is convenient to keep track of all external js libraries in project using
a package.json. It is used to keep latest version of available packages.
The following template tags can be used to serve these packages right from CDN on production and
node_modules during development
unpkg
Alternative to standard static template tag. When you are using external static files/libraries
like bootstrap, jquery you may want to load them from CDNs instead of managing them yourself in production.
This tag helps you to do that. When settings.DEBUG is false, this will return paths that resolved from
package.json to versioned unpkg.com. Otherwise it will resolve to node_modules locally.
jsdelivr
like `unpkg` adds support for using https://www.jsdelivr.com/
Usage:
load the template tags and use unpkg like static tag,
{% load static utils_plus_tags %}
<link rel="stylesheet" type="text/css" href="{% unpkg 'bootstrap/dist/css/bootstrap.min.css' %}"/>
<script src="{% unpkg 'bootstrap/dist/js/bootstrap.min.js' %}"></script>
<script src="{% unpkg 'jquery/dist/jquery.min.js' %}"></script>
Note:
- the package.json should be present in the project ROOT DIR.
- When DEBUG is True the packages must be installed and should be available already inside
node_modules.
Middleware
- login_required_middleware
Urls & Routing with ease
An elegant and DRY way to define urlpatterns. It has easier to nest many levels deeper and still have the readability. It is just a wrapper behind the standard url(), include() methods.
This is how your urls.py may look
### urls.py ###
urlpatterns = [
url(r'^studenteditordocument/(?P<doc_pk>\d+)/edit/$', EditView.as_view(), name='edit-student-doc'),
url(r'^studenteditordocument/(?P<doc_pk>\d+)/export/$', ExportView.as_view(), name='export-editore-doc'),
url(r'^docs/$', Docs.as_view(), name='student-documents'),
url(r'^publish/$', PulishOrDelete.as_view(), {'action': 'publish'}, name="publish_document"),
url(r'^delete/$', PulishOrDelete.as_view(), name='delete_document'),
]
after using Url
### urls.py ###
from utils_plus.router import url
urlpatterns = list(
url('editor')[
url.int('doc_pk')[
url('edit', DocEditorView.as_view(), 'edit-doc'),
url('export', DocExporterView.as_view(), 'export-doc'),
]
]
+ url('docs', Docs.as_view(), 'student-documents')
+ url('publish', DeleteOrPublistDocument.as_view(), 'publish_document', action='publish')
+ url('delete', DeleteOrPublistDocument.as_view(), 'delete_document')
see tests/test_router.py for more use cases
Model
-
CheckDeletableModelMixinadds ais_deletablemethod which then can be used to check any affected related records before actually deleting them. originally it is copied from this gist -
ChoicesEnumEnumerator class for use with the django ORM choices field -
QueryManagerA DRYer way to set select_related, prefetch_related & filters to queryset.- this has
first_or_createmethod similar to get_or_create
- this has
from django.db import models
from utils_plus.models import QueryManager
class Post(models.Model):
author = models.ForeignKey('Author')
comments = models.ManyToManyField('Comment')
published = models.BooleanField()
pub_date = models.DateField()
# custom managers
objects = QueryManager() # equivalent to models.Manager
public_posts = QueryManager(published=True).order_by('-pub_date')
rel_objects = QueryManager().selects('author').prefetches('comments')
Config Option
URL_GROUP_TRAIL_SLASH- By default all the urls generated by this class will have trailing slash
- Set this to False in settings.py to change this behaviour
Views
- CreateUpdateView:
- combines CreateView and UpdateView
Testing the project
- clone the repo and run migrations after installing dependencies
- `inv test` will run all the test for the app
Development
Install dependencies
uv sync
make lint test
Release
To publish a new release:
- Create a new release on GitHub and tag it with a version number (e.g., v0.7.5)
- The workflow will automatically run tests, linting, and publish to PyPI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-utils-plus-0.7.6.tar.gz.
File metadata
- Download URL: django-utils-plus-0.7.6.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
229209060eb8d60a72c8b1f8eb06d9c5ca689c464a14f20ff62c606b40e9f39f
|
|
| MD5 |
5ede55c5c55580be8cf7a9f278e5f5b1
|
|
| BLAKE2b-256 |
19b2f93be2a63611db9edff1ef751eccdb2a5c3096e5a977e527d3728fee2914
|
Provenance
The following attestation bundles were made for django-utils-plus-0.7.6.tar.gz:
Publisher:
ci.yml on jnoortheen/django-utils-plus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_utils_plus-0.7.6.tar.gz -
Subject digest:
229209060eb8d60a72c8b1f8eb06d9c5ca689c464a14f20ff62c606b40e9f39f - Sigstore transparency entry: 239728864
- Sigstore integration time:
-
Permalink:
jnoortheen/django-utils-plus@56778ed49c476a934793c3886dd5be93b441aec3 -
Branch / Tag:
refs/tags/v0.7.6 - Owner: https://github.com/jnoortheen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@56778ed49c476a934793c3886dd5be93b441aec3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_utils_plus-0.7.6-py3-none-any.whl.
File metadata
- Download URL: django_utils_plus-0.7.6-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
708174b15a9b619a38e79e1a1c7658501cab29e0d77f5b3c37984855128261ea
|
|
| MD5 |
311ddd0235c3affa2d2e454cb4e8c92d
|
|
| BLAKE2b-256 |
203823131700fd7d289b803a830400916279d74c5a9c064465b4d0792d98f339
|
Provenance
The following attestation bundles were made for django_utils_plus-0.7.6-py3-none-any.whl:
Publisher:
ci.yml on jnoortheen/django-utils-plus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_utils_plus-0.7.6-py3-none-any.whl -
Subject digest:
708174b15a9b619a38e79e1a1c7658501cab29e0d77f5b3c37984855128261ea - Sigstore transparency entry: 239728870
- Sigstore integration time:
-
Permalink:
jnoortheen/django-utils-plus@56778ed49c476a934793c3886dd5be93b441aec3 -
Branch / Tag:
refs/tags/v0.7.6 - Owner: https://github.com/jnoortheen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@56778ed49c476a934793c3886dd5be93b441aec3 -
Trigger Event:
push
-
Statement type: