Skip to main content

A Django app to integrate mosparo into your forms.

Project description

 

mosparo logo contains a bird with the name Mo and the mosparo text

Integration for Django

This Django app offers the needed form, field, and widget class to add mosparo to your Django form.


Description

With this Django app, you can protect your forms with mosparo. Install the app, configure it and add the field to your forms.

How to use

Please see our How to use introduction on our website to learn how to use mosparo in your form.

In step 3 of the how-to-use explanation, you must integrate mosparo into your website. Please follow the Installation part below for this process.

In step 4 of the how-to-use explanation, you must connect your website with your mosparo project. Please follow the Usage part below.

Installation

Install using pip

Install this app by using pip:

pip install mosparo_django

Build from source

You need the module build to build the module from source.

  1. Clone the repository
  2. Build the package
python -m build
  1. Install the package
pip install dist/mosparo_django-1.0.2-py3-none-any.whl

Usage

  1. Create a project in your mosparo installation
  2. Edit the settings.py file of your project
  3. Add the mosparo integration to the list of enabled apps:
INSTALLED_APPS = [
    # ...
    'mosparo_django',
]
  1. Specify the configuration for mosparo:
MOSPARO_HOST = 'https://...'
MOSPARO_UUID = '...'
MOSPARO_PUBLIC_KEY = '...'
MOSPARO_PRIVATE_KEY = '...'
MOSPARO_VERIFY_SSL = True
  1. Add the mosparo field to your form:
from mosparo_django.fields import MosparoField

class Form(forms.Form):
    # Your other fields...
    mosparo = MosparoField(label='Spam protection')
  1. Add the verification (see Verification)
  2. Test your form and verify that everything works correctly and you see the submission in mosparo.

Verification

After the user submits the form, the backend has to verify the form data before you can process them. Since we didn't find a good way to do this automatically, you have to implement one of the following options:

Use the mosparo Form class

Use the mosparo Form class to create your form instead of the django.forms.Form class:

from mosparo_django.forms import MosparoForm
from mosparo_django.fields import MosparoField

class Form(MosparoForm):
    # Your other fields...
    mosparo = MosparoField(label='Spam protection')

Override the clean method

The other option is to override the method clean of the Form class:

from mosparo_django.fields import MosparoField

class Form(forms.Form):
    # Your other fields...
    mosparo = MosparoField(label='Spam protection')

    def clean(self):
        self.fields['mosparo'].verify_data(self)

        return super().clean()

Important: No spam protection will happen if you do not use one of these two things.

Specify the connection details on the field

You can also specify the connection details on the field. For that, please add the field to your form and specify the connection settings by setting the parameters mosparo_host, mosparo_uuid, mosparo_public_key, mosparo_private_key, and mosparo_verify_ssl. If you want to change the UUID, public or private key, you have to specify all these three values because these depend on the project and if you want to connect the field to a different project, all three values will be different.

from mosparo_django.forms import MosparoForm
from mosparo_django.fields import MosparoField

class Form(MosparoForm):
    # Your other fields...
    mosparo = MosparoField(label='Spam protection', mosparo_uuid='123', mosparo_public_key='test_key', mosparo_private_key = 'private_key')

Filter the field types and form data

The MosparoField offers some callback methods to adjust the behavior of the field.

from mosparo_django.forms import MosparoForm
from mosparo_django.fields import MosparoField

class Form(MosparoForm):
    # Your other fields...
    mosparo = MosparoField(callback_ignored_field_types=None, callback_verifiable_field_types=None, callback_after_prepare_form_data=None)
Argument name Description
callback_ignored_field_types Gets and returns a list of class names of field types, which should be ignored (Example: PasswordInput)
callback_verifiable_field_types Gets and returns a list of class names of field types, which are verifiable (Example: TextInput)
callback_after_prepare_form_data Gets the dict with all prepared form data, the required field names, and the verifiable field names as argument and expects the same to be returned.

License

mosparo Integration for Django is open-sourced software licensed under the MIT License. Please see the LICENSE file for the full license.

Contributing

Translate mosparo Integration for Django

We're using Weblate to translate the mosparo Integration for Django. If you want to help translate the mosparo Integration for Django, please head over to our Weblate project: https://hosted.weblate.org/projects/mosparo/integration_django/

List of translators

Language Language Code Contributors
German de mosparo Core Developers
Estonian et jrthwlate
French fr Bamowen
Croatian hr milotype
Korean ko MarongHappy
Tamil ta TamilNeram
Turkish tr mosparo Core Developers
Ukrainian uk kefir2105

Thank you for helping to make the mosparo Integration for Django better.

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

mosparo_django-1.0.8.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

mosparo_django-1.0.8-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file mosparo_django-1.0.8.tar.gz.

File metadata

  • Download URL: mosparo_django-1.0.8.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for mosparo_django-1.0.8.tar.gz
Algorithm Hash digest
SHA256 81fa03a4d9b1173fc22e3015de0c2d7ba7fb1a66594c9ee01f6d2ef86107d9a0
MD5 54edf65268820980ec5bd32ec6328e8b
BLAKE2b-256 8eb2d002c3690c3ae0e3f1251e026d7bfc28ef38ad6986e41ba2bd18e74c4843

See more details on using hashes here.

File details

Details for the file mosparo_django-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: mosparo_django-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.3

File hashes

Hashes for mosparo_django-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9148d17db3958f7635b804693f0aeeab3d14cb3eb46f024c40fcc3982eedf994
MD5 5cbd780f7c5fd9a98f1f74d3bb803369
BLAKE2b-256 a51d1de4afaa6cde423adcc8f153959cd347b84fe568b1ddf12ccc412edf4d9b

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