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.

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 -r requirements.txt

# setup environment
pip install -e .

# 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.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

django_generic_contact-1.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_generic_contact-1.1.0.tar.gz
Algorithm Hash digest
SHA256 9c7cafb8c9772dedcb39b4c67d84a7820d9247e823d1fbd6b1683396e99d5c6f
MD5 f3d83d0fdcf5df2e2b55a39a0acd0726
BLAKE2b-256 a335a9019680a0dc54e6c2033a8c192c87c3da44264f4d5f42bb49a5c790a1d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_generic_contact-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00ccd86d76a0522804bb57644edf56c6738c469716b414b5fc1ed378359071e4
MD5 74d9a6bd79a504eb5ea4b5e2e56332be
BLAKE2b-256 e3cb663c933b738308ba415287e9306b7b09d779ec523a49aea997fd9bd36314

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