Skip to main content

Reusable functionality

Project description

About

A reusable DRF library that provides reusable components.

Installation

pip install django-pycorpkit

Quick start

  1. Add “django-pycorpkit” to your INSTALLED_APPS setting:

    INSTALLED_APPS = [
        ...
        "pycorpkit.common",
        "pycorpkit.accountx",
        "pycorpkit.org_structure",
    ]
  2. Include the django_sample_lib URLconf in your project urls.py:

    path('api/', include('pycorpkit.urls')),
  3. Run migrations:

    python manage.py migrate
  4. Add exception handler and default backend filter:

    REST_FRAMEWORK = {
        "EXCEPTION_HANDLER": "pycorpkit.common.utils.exception_handler.custom_exception_handler",
        "DEFAULT_PERMISSION_CLASSES": [
            "pycorpkit.accountx.permissions.enforce.EnforceDRFViewPermission",
        ],
        "DEFAULT_FILTER_BACKENDS": (
            "pycorpkit.common.filters.base.OrganisationFilterBackend",
        ),
    }
  5. Add required variables in settings file:

    PERMISSIONS_PATH = "testapp.perms"
    APP_NAME = "PyCorpKit"
    CLIENT_DOMAIN = "http://domain.com/"
    AUTH_USER_MODEL = "accountx.User"
    DEFAULT_FROM_EMAIL = "admin@example.com"
    SIMPLE_JWT = {
        "ACCESS_TOKEN_LIFETIME": timedelta(seconds=3600),
        "REFRESH_TOKEN_LIFETIME": timedelta(days=7),
    }
  6. INCLUDE django_rest_passwordreset in installed apps

    INSTALLED_APPS = (
        'django_rest_passwordreset',
    )
  7. Add PhoneModelBackend to AUTHENTICATION_BACKENDS

    AUTHENTICATION_BACKENDS = [
        'django.contrib.auth.backends.ModelBackend',
        # add the below after `ModelBackend`
        'pycorpkit.common.utils.phone_backend.PhoneModelBackend',
    ]
  8. Add organisation middleware

    MIDDLEWARE = [
        "pycorpkit.common.utils.middleware.OrganisationIDMiddleware",
    ]
  9. Define DEFAULT_ROLES in settings

    DEFAULT_ROLES = {
        "Organisation Admin": ORGANISATION_ADMIN,
        "Branch Admin": BRANCH_ADMIN,
        "Department Admin": DEPARTMENT_ADMIN,
        "User": PROFILE_ADMIN,
    }

Development

To set up the development environment:

  1. Clone the repository

  2. Create a virtual environment and activate it

  3. Install development dependencies:

    pip install -e ".[dev]"
  4. Run tests:

    python -m pytest tests
    # OR
    pytest tests/

Install test dependencies

pip install -e ".[test]"

Making migrations

python testapp/manage.py makemigrations
python testapp/manage.py makemigrations <app_name> --empty

Migrate

python testapp/manage.py migrate

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_pycorpkit-1.0.3.tar.gz (70.7 kB view details)

Uploaded Source

Built Distribution

django_pycorpkit-1.0.3-py2.py3-none-any.whl (69.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django_pycorpkit-1.0.3.tar.gz.

File metadata

  • Download URL: django_pycorpkit-1.0.3.tar.gz
  • Upload date:
  • Size: 70.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for django_pycorpkit-1.0.3.tar.gz
Algorithm Hash digest
SHA256 2eeeff0739db9f52f46ff56baf89d9834facc1020ab9296b2fad36f0baa8c635
MD5 b41fa6033ee0ac605744c437aa043ffe
BLAKE2b-256 c25ca4635f626714fdee03af930355e7446b34915f4bfb42a8063a8949e7ecbf

See more details on using hashes here.

File details

Details for the file django_pycorpkit-1.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_pycorpkit-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 005802510f1cd37316d05192baa23a75ff737dbaa712d1f307c02bfff46b4537
MD5 05dd9e3b3190f1ec688f1f5e4510401d
BLAKE2b-256 97fc237d52befc3855048926221bb4320911a50954af57584df893173dc7e79d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page