Skip to main content

Use jSignature jQuery plugin in your django projects

Project description

A simple way to use jSignature jQuery plugin in your Django projects.

It provides:

  • A form field and a form widget to handle jquery plugin through a Django form;

  • A model field to store a captured signature;

  • A mixin adding two fields (signature / signature_date) in any of your Django models.

Latest PyPI version Build status Coverage status https://github.com/fle/django-jsignature/blob/master/screen.png

INSTALL

For now:

pip install django-jsignature

USAGE

  • Add jsignature to your INSTALLED_APPS:

# settings.py
INSTALLED_APPS = (
    ...
    'jsignature',
)
  • Use provided form field and widget:

# forms.py
from django import forms
from jsignature.forms import JSignatureField

class SignatureForm(forms.Form):
    signature = JSignatureField()
  • In your template

{{ form.media }}
<form action="." method="POST">
    {% for field in form %}
        {{ field.label_tag }}
        {{ field }}
    {% endfor %}
    <input type="submit" value="Save"/>
    {% csrf_token %}
</form>
  • Render image after form validation:

# views.py
from jsignature.utils import draw_signature
from myapp.forms import SignatureForm

def my_view(request):
    form = SignatureForm(request.POST or None)
    if form.is_valid():
        signature = form.cleaned_data.get('signature')
        if signature:
            # as an image
            signature_picture = draw_signature(signature)
            # or as a file
            signature_file_path = draw_signature(signature, as_file=True)
  • By default, jSignature is made to work outside of admin, requiring that you include the jQuery library in your <head>.

    If you want to use jSignature in the Django admin site, set the JSIGNATURE_JQUERY setting to admin. Otherwise if set to any url pointing to jQuery, it will be automatically included.

CUSTOMIZATION

JSignature plugin options are available in python:

  • Globally, in your settings:

# settings.py
JSIGNATURE_WIDTH = 500
JSIGNATURE_HEIGHT = 200
  • Specifically, in your form:

# forms.py
from jsignature.forms import JSignatureField
from jsignature.widgets import JSignatureWidget

JSignatureField(widget=JSignatureWidget(jsignature_attrs={'color': '#CCC'}))

Available settings are:

  • JSIGNATURE_WIDTH (width)

  • JSIGNATURE_HEIGHT (height)

  • JSIGNATURE_COLOR (color)

  • JSIGNATURE_BACKGROUND_COLOR (background-color)

  • JSIGNATURE_DECOR_COLOR (decor-color)

  • JSIGNATURE_LINE_WIDTH (lineWidth)

  • JSIGNATURE_UNDO_BUTTON (UndoButton)

  • JSIGNATURE_RESET_BUTTON (ResetButton)

IN YOUR MODELS

If you want to store signatures, provided mixin gives a signature and a signature_date that update themselves:

from django.db import models
from jsignature.mixins import JSignatureFieldsMixin

class JSignatureModel(JSignatureFieldsMixin):
    name = models.CharField()

Example project

If you want to have a demo of this package, just use the example project:

git clone https://github.com/fle/django-jsignature.git
cd django-jsignature
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -e .
cd example_project
./manage.py migrate
./manage.py createsuperuser

Fill the user info, launch django with ./manage.py runserver and head over to http://127.0.0.1:8000/ and login with the credentials your provided.

AUTHORS

makinacom

CHANGELOG

0.9 (2020-04-18)

** New **

  • Add support for Django 2+

  • Drop support for Django<1.11

  • Add a JSIGNATURE_JQUERY settings to handle usage in admin in Django 2.1+

0.8 (2014-12-04)

** New **

  • Add support for Python 3 (@Gagaro)

  • Add support for Django 1.7 (@Gagaro)

0.7.6 (2014-11-26)

** New features **

  • A setting to display (or not) the reset button has been added (@jsayles)

** Internal changes **

  • Rendering is now based on a template (@andybak)

  • Javascript is properly initialized (@andybak)

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-jsignature-0.9.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

django_jsignature-0.9-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

Details for the file django-jsignature-0.9.tar.gz.

File metadata

  • Download URL: django-jsignature-0.9.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for django-jsignature-0.9.tar.gz
Algorithm Hash digest
SHA256 7923d96fd4f61186b64f9e52c5029324446c232f4f8490f92d718ebd62c20271
MD5 3f354b5da1b278d1fa0ebe6763c40c1c
BLAKE2b-256 7b9b38c2434a6789c62a52e213b58c62d75067ed6734ad8ec5eae68cf6ad55a6

See more details on using hashes here.

File details

Details for the file django_jsignature-0.9-py3-none-any.whl.

File metadata

  • Download URL: django_jsignature-0.9-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for django_jsignature-0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 35ed3889fd30c5e484327389c924e927e40cb5f71b894e4bb37f127b3e5ba773
MD5 1970a0b74c9a85cbd7a70b7ad06a1b55
BLAKE2b-256 0f638c6a71058a6746366aff2c1fde0ed3d5063ff847236a6b1143a7c200bfd2

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