Handle both admin and not admin usages
This commit is contained in:
@@ -82,6 +82,13 @@ USAGE
|
|||||||
# or as a file
|
# or as a file
|
||||||
signature_file_path = draw_signature(signature, as_file=True)
|
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
|
CUSTOMIZATION
|
||||||
==================
|
==================
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ from .forms import (
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
string_types = six.string_types
|
string_types = six.string_types
|
||||||
except ImportError:
|
except ImportError:
|
||||||
string_types = str
|
string_types = str
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class JSignatureField(models.Field):
|
class JSignatureField(models.Field):
|
||||||
"""
|
"""
|
||||||
A model field handling a signature captured with jSignature
|
A model field handling a signature captured with jSignature
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ JSIGNATURE_UNDO_BUTTON = getattr(
|
|||||||
JSIGNATURE_RESET_BUTTON = getattr(
|
JSIGNATURE_RESET_BUTTON = getattr(
|
||||||
settings, 'JSIGNATURE_RESET_BUTTON', True)
|
settings, 'JSIGNATURE_RESET_BUTTON', True)
|
||||||
|
|
||||||
|
JSIGNATURE_JQUERY = getattr(
|
||||||
|
settings, 'JSIGNATURE_JQUERY', 'custom')
|
||||||
|
|
||||||
JSIGNATURE_DEFAULT_CONFIG = {
|
JSIGNATURE_DEFAULT_CONFIG = {
|
||||||
'width': JSIGNATURE_WIDTH,
|
'width': JSIGNATURE_WIDTH,
|
||||||
'height': JSIGNATURE_HEIGHT,
|
'height': JSIGNATURE_HEIGHT,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
$(document).ready(function() {
|
(function($) {
|
||||||
|
$(document).ready(function() {
|
||||||
$(".jsign-container").each(function(){
|
$(".jsign-container").each(function(){
|
||||||
var config = $(this).data('config');
|
var config = $(this).data('config');
|
||||||
var value = $(this).data('initial-value');
|
var value = $(this).data('initial-value');
|
||||||
@@ -17,5 +18,5 @@ $(document).ready(function() {
|
|||||||
$(".jsign-wrapper input").on("click", function(e) {
|
$(".jsign-wrapper input").on("click", function(e) {
|
||||||
$(this).siblings('.jsign-container').jSignature('reset');
|
$(this).siblings('.jsign-container').jSignature('reset');
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
})(jQuery || django.jQuery)
|
||||||
|
|||||||
4
jsignature/static/js/jsignature_admin_init.js
Normal file
4
jsignature/static/js/jsignature_admin_init.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
if (django && django.jQuery) {
|
||||||
|
var jQuery = django.jQuery;
|
||||||
|
var $ = django.jQuery;
|
||||||
|
}
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.forms.widgets import HiddenInput
|
from django import forms
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from jsignature.settings import JSIGNATURE_DEFAULT_CONFIG
|
from jsignature.settings import JSIGNATURE_DEFAULT_CONFIG, JSIGNATURE_JQUERY
|
||||||
|
|
||||||
JSIGNATURE_EMPTY_VALUES = validators.EMPTY_VALUES + ('[]', )
|
JSIGNATURE_EMPTY_VALUES = validators.EMPTY_VALUES + ('[]', )
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ except ImportError:
|
|||||||
string_types = str
|
string_types = str
|
||||||
|
|
||||||
|
|
||||||
class JSignatureWidget(HiddenInput):
|
class JSignatureWidget(forms.HiddenInput):
|
||||||
"""
|
"""
|
||||||
A widget handling a signature capture field with with jSignature
|
A widget handling a signature capture field with with jSignature
|
||||||
"""
|
"""
|
||||||
@@ -32,10 +32,21 @@ class JSignatureWidget(HiddenInput):
|
|||||||
# normal field, not a hidden one
|
# normal field, not a hidden one
|
||||||
is_hidden = False
|
is_hidden = False
|
||||||
|
|
||||||
class Media:
|
@property
|
||||||
js = ('admin/js/jquery.init.js',
|
def media(self):
|
||||||
|
files = ()
|
||||||
|
if JSIGNATURE_JQUERY == 'admin':
|
||||||
|
files = (
|
||||||
|
'admin/js/jquery.init.js',
|
||||||
|
'js/jsignature_admin_init.js',
|
||||||
|
)
|
||||||
|
elif JSIGNATURE_JQUERY != 'custom':
|
||||||
|
files = (JSIGNATURE_JQUERY,)
|
||||||
|
files += (
|
||||||
'js/jSignature.min.js',
|
'js/jSignature.min.js',
|
||||||
'js/django_jsignature.js')
|
'js/django_jsignature.js',
|
||||||
|
)
|
||||||
|
return forms.Media(js=files)
|
||||||
|
|
||||||
def __init__(self, attrs=None, jsignature_attrs=None):
|
def __init__(self, attrs=None, jsignature_attrs=None):
|
||||||
super(JSignatureWidget, self).__init__(attrs)
|
super(JSignatureWidget, self).__init__(attrs)
|
||||||
|
|||||||
Reference in New Issue
Block a user