Django tools from WITH
Project description
Django Wools
Django tools from WITH.
That's a collection of things that we at WITH got tired of copy/pasting in every project.
Install
pip install django_wools
Included Wools
Storage
django_wools.storage.GzipManifestStaticFilesStorage
That's a sub-class of the
ManifestStaticFilesStorage
but that makes sure that along with all the files comes a .gz
version which
is easy to pick up for nginx (or other static files server).
Middlewares
django_wools.middlewares.NowMiddleware
Suppose that you have a content that is available up until a given date. When the date is passed then everything related to this content expires. However, in order to do this, you're probably going to make several request, possibly in loosely connected parts of your code. In those cases, when looking at the time, the clock will show different value as the time passes between calls. It means that you could very well end up with one half of your code considering that the object is still valid but the other half that it expired.
In order to prevent this, the simplest is to consider that the time is fixed and that the code executes instantly at the moment of the request. The goal of this middleware is to save the current time at each request and then to provide an easy way to get the current time through the request.
If the middleware is activated, you should be able to get the time like this:
from time import sleep
from django.shortcuts import render
def my_view(request):
print(f"Now is {request.now()}")
sleep(42)
print(f"Now is still {request.now()}")
return render(request, "something.html", {"now": request.now()})
Database
django_wools.db.require_lock
Provides a way to explicitly generate a PostgreSQL lock on a table.
By example:
from django.db.transaction import atomic
from django_wools.db import require_lock
from my_app.models import MyModel
@atomic
@require_lock(MyModel, 'ACCESS EXCLUSIVE')
def myview(request):
# do stuff here
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
File details
Details for the file django_wools-0.1.1.tar.gz
.
File metadata
- Download URL: django_wools-0.1.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/4.19.0-8-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 766baacef0037210e8cb4e848b9a41942bac70823ebd1a41ab49bf73245fd5de |
|
MD5 | 5303bfb00ca4dc61b2d0bf3051f1ef44 |
|
BLAKE2b-256 | e97df1a88a5c11747236d9d74e7b5a72b639e59b25d8d6127648ed889e62c640 |
File details
Details for the file django_wools-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: django_wools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.5 CPython/3.8.2 Linux/4.19.0-8-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59b6d4fadfad5359dd63ab897e118643cb05255d97ac1ef93720ddd9c72edfaf |
|
MD5 | e598888c53f8752a75a2da8eaa098edb |
|
BLAKE2b-256 | e9cd1cf31cb4ced3848b119cec81f3bc4e712d156995989f8c4428d37fa1c10b |