Skip to content
This repository has been archived by the owner on Mar 1, 2018. It is now read-only.

Commit

Permalink
more filtering on save
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Bardin committed Nov 21, 2016
1 parent d654370 commit f98980a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion jsignature/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
with jSignature jQuery plugin
"""
import json
import yaml
import six

from django.db import models
Expand Down Expand Up @@ -38,7 +39,17 @@ def get_prep_value(self, value):
if value in JSIGNATURE_EMPTY_VALUES:
return None
elif isinstance(value, six.string_types):
return value
# A little light parse assistance, to manage quirkiness in Django
# forms.

# 'u' should never appear as a proper value; just 'x', 'y' and
# numbers. If it's here, it's bad unicode representations, so strip
# it.
safe_value = value.replace('u', '')

# yaml can handle single-quotes better than JSON, so use it to
# clear them out before saving.
return json.dumps(yaml.load(safe_value))
elif isinstance(value, list):
return json.dumps(value)
raise ValidationError('Invalid format.')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pillow==2.9.0
pyquery==1.2.17
six==1.9
Django==1.10
Django>=1.10

0 comments on commit f98980a

Please sign in to comment.