Skip to main content

Utilities for Django project.

Project description

Getting Started

Installation

  1. Install package

    pip install django-gajo-utils
    
  2. Add GajoDebugUtilsMiddleware to project settings before all other none-dev related middlewares.

    MIDDLEWARE = [
        'gajo_utils.middleware.GajoDebugUtilsMiddleware',
        ... other apps
    ]
    
  3. Add gajo_utils to INSTALLED_APPS.

    INSTALLED_APPS = [
        ...other apps
        'gajo_utils',
    ]
    
  4. 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": True prints in terminal how much time it needed for request/response cycle to finish.

  • "REQUEST_DELAY": True adds 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": True prints in terminal request cookies.

  • "RESPONSE_COOKIES": True prints in terminal response cookies.

  • "RESPONSE_CONTENT": True prints in terminal response content.

  • "RESPONSE_QUERIES": True prints 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 with select_related or prefetch_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 like apps.dummy.tests.test_dummies.DummyTest.test_dummy. You can instead just specify DummyTest or test_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 dumpfixtures this management command needs extra configuration in settings.py. You can specify which models you want to be dumped into database in GAJO_UTILS_CONFIG. Every model is than dumped in json format at ROOT_DIR/fixtures/app_name/ModelName.json.

    GAJO_UTILS_CONFIG = {
        "DUMP_FIXTURES": [
            "dummy.Model1",
            "dummy.Model2",
        ]
    }
    
  • ./manage.py loadfixtures this management command needs extra configuration in settings.py. You can specify which models you want to be loaded into database in GAJO_UTILS_CONFIG. There must be file created at correct path: ROOT_DIR/fixtures/app_name/ModelName.json

    GAJO_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_gajo_utils-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

django_gajo_utils-0.1.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

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

Hashes for django_gajo_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8238e518ad0e9e8293e63994b0351cc3f676960ef223896efbfe1bd6f8917648
MD5 bcd18c2f199a873aaea0a9455934f313
BLAKE2b-256 dbf6caa91c067712e4ac70a3423db09b8f24e09cde7cf252395936b8faad770a

See more details on using hashes here.

File details

Details for the file django_gajo_utils-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_gajo_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ad9d5914dc66e7560dee1c7c4d1bc9a9d358f95c883a722e259ac26159bfc70
MD5 71d85d3bffd1e4838a09f24f37c5b61a
BLAKE2b-256 912866e256a9f4fd1c2eb4e4b682acca4a4d136d13733a62124b3571c6c83db7

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