Skip to main content

Django module to store contact request in a structured yet generic manner.

Project description

Django Generic Contact

PyPI version Run linter and tests Codecov

Django module to store contact request in a structured yet generic manner within the database.

Supported versions (from endoflife.date):

  • Python: 3.10, 3.11, 3.12, 3.13, 3.14
  • Django: 4.2 (LTS), 5.2 (LTS), 6.0

Installation

  1. Install using pip:
pip install django-generic-contact
  1. Integrate django_generic_contact into your settings.py
INSTALLED_APPS = [
    # ...
    'django_generic_contact',
    # ...
]

Usage

The package provides you with a Contact model which expects data (dict) and the name of the requester, an optional message can be added:

from django_generic_contact.models import Contact

contact = Contact.objects.create(
    name="Mr. Tester",
    message="Please contact me via email or phone.",
    data={
        "email": "mr@tester.com",
        "phone": "123456",
    }
)

JSON Schema validation

The contents of data will be validated against a json schema defined in your project's settings.py (if provided). If needed you can define GENERIC_CONTACT_DATA_SCHEMA to check all relevant input according to the expected structure, e.g.:

GENERIC_CONTACT_DATA_SCHEMA = {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "email": {"type": "string", "format": "email"},
        "phone": {"type": "integer"},
    },
}

See more examples of GENERIC_CONTACT_DATA_SCHEMA in tests/testapp/tests/test_model.py.

Customizing the Contact model

The base model GenericContact only requires the data. Thus, you can let your own models inherit from this and extend it according to your project's needs, e.g.:

from django_generic_contact.models import GenericContact

class CustomContact(GenericContact):
    birth_date = models.Datetime(_("birth date"))
    zip = models.CharField(_("zip"))

Unit Tests

See folder tests/. The provided tests cover these criteria:

  • success:
    • Contact model instance creation
    • project's jsonschema validation
  • failure:
    • project's jsonschema validation
    • exemplary custom jsonschema validation

Follow below instructions to run the tests. You may exchange the installed Django and DRF versions according to your requirements. :warning: Depending on your local environment settings you might need to explicitly call python3 instead of python.

# install dependencies
python -m pip install --upgrade pip
pip install -e .[dev]

# run tests
cd tests && python manage.py test

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

See LICENSE 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_generic_contact-1.2.2.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

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

django_generic_contact-1.2.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file django_generic_contact-1.2.2.tar.gz.

File metadata

  • Download URL: django_generic_contact-1.2.2.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for django_generic_contact-1.2.2.tar.gz
Algorithm Hash digest
SHA256 55821e56f4a879874895622c4161f2e43be65aaf06fe7f333f0106b259460565
MD5 7d581b43d85ff0eeff31f5157b44a9ba
BLAKE2b-256 8abf07b32ab53185252065a80d28021097b9bc5393e6ca92a8f7cf1837d41ef0

See more details on using hashes here.

File details

Details for the file django_generic_contact-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_generic_contact-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 efdc6586daa558c42932afef75fef2913bca0b29687a0e515aabfa7da280072a
MD5 97d365bf13a0ac18bb8a5e6806509bbe
BLAKE2b-256 b766c41f4a370149aea02e7f92c9f455d5742c7dc936db52d62b93aa4db29b75

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