Utilities for Django project.
Project description
Getting Started
Installation
-
Install package
pip install django-gajo-utils
-
Add
GajoDebugUtilsMiddlewareto project settings before all other none-dev related middlewares.MIDDLEWARE = [ 'gajo_utils.middleware.GajoDebugUtilsMiddleware', ... other apps ]
-
Add
gajo_utilstoINSTALLED_APPS.INSTALLED_APPS = [ ...other apps 'gajo_utils', ]
-
Turn on any of the utils by settings its value to
True(by default all utils are disabled)GAJO_UTILS_CONFIG = { "REQUEST_TIMER": False, "REQUEST_DELAY": False, "REQUEST_COOKIES": False, "RESPONSE_COOKIES": False, "RESPONSE_CONTENT": False, "RESPONSE_QUERIES": False, "DUMP_FIXTURES": [ "dummy.Model1", "dummy.Model2", ], "LOAD_FIXTURES": [ "dummy.Model1", "dummy.Model2", ], }
Usage
Middleware Configuration
-
"REQUEST_TIMER": Trueprints in terminal how much time it needed for request/response cycle to finish. -
"REQUEST_DELAY": Trueadds random delay (50ms - 300ms) to every request and than prints in terminal how much was request delayed. This config is used to simulate latency on server. -
"REQUEST_COOKIES": Trueprints in terminal request cookies. -
"RESPONSE_COOKIES": Trueprints in terminal response cookies. -
"RESPONSE_CONTENT": Trueprints in terminal response content. -
"RESPONSE_QUERIES": Trueprints all queries that were made in response/request cycle with time for each one. It also prints total time for all queries and number of similar queries (queries that can be probably optimized withselect_relatedorprefetch_related).
Decorators
Decorator for timing how much time took for view to run. If you want to time whole
request/response cycle than you should use REQUEST_TIMER configuration.
from gajo_utils.decorators import timeview
@timeview
def example_view(request):
return ...
Function time (function_name): 43.22ms
Management Commands
gajo_utils adds three extra commands to your django app.
-
./manage.py testsingle {test_name}offers you option to test single function test or test single TestCase class without needing to providing full path to test likeapps.dummy.tests.test_dummies.DummyTest.test_dummy. You can instead just specifyDummyTestortest_dummy.If command finds two functions or classes with same name in different app it will test both separately (with two commands executed).
-
./manage.py dumpfixturesthis management command needs extra configuration insettings.py. You can specify which models you want to be dumped into database inGAJO_UTILS_CONFIG. Every model is than dumped in json format atROOT_DIR/fixtures/app_name/ModelName.json.GAJO_UTILS_CONFIG = { "DUMP_FIXTURES": [ "dummy.Model1", "dummy.Model2", ] }
-
./manage.py loadfixturesthis management command needs extra configuration insettings.py. You can specify which models you want to be loaded into database inGAJO_UTILS_CONFIG. There must be file created at correct path:ROOT_DIR/fixtures/app_name/ModelName.jsonGAJO_UTILS_CONFIG = { "LOAD_FIXTURES": [ "dummy.Model1", "dummy.Model2", ] }
Versioning
This package is using Semantic Versioning. You can find informations about it here: https://semver.org/.
License
Distributed under the MIT License. See LICENSE.txt for more information.
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_gajo_utils-0.1.0.tar.gz.
File metadata
- Download URL: django_gajo_utils-0.1.0.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8238e518ad0e9e8293e63994b0351cc3f676960ef223896efbfe1bd6f8917648
|
|
| MD5 |
bcd18c2f199a873aaea0a9455934f313
|
|
| BLAKE2b-256 |
dbf6caa91c067712e4ac70a3423db09b8f24e09cde7cf252395936b8faad770a
|
File details
Details for the file django_gajo_utils-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_gajo_utils-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ad9d5914dc66e7560dee1c7c4d1bc9a9d358f95c883a722e259ac26159bfc70
|
|
| MD5 |
71d85d3bffd1e4838a09f24f37c5b61a
|
|
| BLAKE2b-256 |
912866e256a9f4fd1c2eb4e4b682acca4a4d136d13733a62124b3571c6c83db7
|