Flake8
This commit is contained in:
committed by
Sébastien Corbin
parent
63c3d7d2dc
commit
382c824cca
16
.github/workflows/actions.yml
vendored
16
.github/workflows/actions.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
- '2.2'
|
||||
- '3.2'
|
||||
- '4.0'
|
||||
python_version:
|
||||
python-version:
|
||||
- 3.6
|
||||
- 3.7
|
||||
- 3.8
|
||||
@@ -19,13 +19,13 @@ jobs:
|
||||
- "3.10"
|
||||
exclude:
|
||||
- django_version: '2.2'
|
||||
python_version: '3.10'
|
||||
python-version: '3.10'
|
||||
|
||||
- django_version: '4.0'
|
||||
python_version: '3.6'
|
||||
python-version: '3.6'
|
||||
|
||||
- django_version: '4.0'
|
||||
python_version: '3.7'
|
||||
python-version: '3.7'
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -33,17 +33,17 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Python ${{ matrix.python_version }}
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python_version: ${{ matrix.python_version }}
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Cache pip
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
# This path is specific to Ubuntu
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ matrix.python_version }}-${{ matrix.django_version }}
|
||||
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ matrix.django_version }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
@@ -58,7 +58,7 @@ jobs:
|
||||
- name: Test Django
|
||||
run: |
|
||||
python -W error::DeprecationWarning -W error::PendingDeprecationWarning \
|
||||
-m coverage run runtests.py
|
||||
-m coverage run ./runtests.py
|
||||
|
||||
- name: Coverage
|
||||
if: ${{ success() }}
|
||||
|
||||
@@ -18,13 +18,13 @@ class JSignatureField(Field):
|
||||
widget = JSignatureWidget()
|
||||
|
||||
def to_python(self, value):
|
||||
"""
|
||||
Validates that the input can be red as a JSON object.
|
||||
Returns a Python list (JSON object unserialized).
|
||||
"""
|
||||
if value in JSIGNATURE_EMPTY_VALUES:
|
||||
return None
|
||||
try:
|
||||
return json.loads(value)
|
||||
except ValueError:
|
||||
raise ValidationError('Invalid JSON format.')
|
||||
"""
|
||||
Validates that the input can be red as a JSON object.
|
||||
Returns a Python list (JSON object unserialized).
|
||||
"""
|
||||
if value in JSIGNATURE_EMPTY_VALUES:
|
||||
return None
|
||||
try:
|
||||
return json.loads(value)
|
||||
except ValueError:
|
||||
raise ValidationError('Invalid JSON format.')
|
||||
|
||||
@@ -14,9 +14,13 @@ def draw_signature(data, as_file=False):
|
||||
`data` can be a json object (list in fact) or a json string
|
||||
if `as_file` is True, a temp file is returned instead of Image instance
|
||||
"""
|
||||
|
||||
def _remove_empty_pts(pt):
|
||||
return {'x': list(filter(lambda n: n is not None, pt['x'])), 'y': list(filter(lambda n: n is not None, pt['y']))}
|
||||
|
||||
return {
|
||||
'x': list(filter(lambda n: n is not None, pt['x'])),
|
||||
'y': list(filter(lambda n: n is not None, pt['y']))
|
||||
}
|
||||
|
||||
if type(data) is str:
|
||||
drawing = json.loads(data, object_hook=_remove_empty_pts)
|
||||
elif type(data) is list:
|
||||
@@ -29,13 +33,13 @@ def draw_signature(data, as_file=False):
|
||||
height = int(round(max(chain(*[d['y'] for d in drawing])))) + 10
|
||||
|
||||
# Draw image
|
||||
im = Image.new("RGBA", (width*AA, height*AA))
|
||||
im = Image.new("RGBA", (width * AA, height * AA))
|
||||
draw = ImageDraw.Draw(im)
|
||||
for line in drawing:
|
||||
len_line = len(line['x'])
|
||||
points = [(line['x'][i]*AA, line['y'][i]*AA)
|
||||
points = [(line['x'][i] * AA, line['y'][i] * AA)
|
||||
for i in range(0, len_line)]
|
||||
draw.line(points, fill="#000", width=2*AA)
|
||||
draw.line(points, fill="#000", width=2 * AA)
|
||||
im = ImageOps.expand(im)
|
||||
# Smart crop
|
||||
bbox = im.getbbox()
|
||||
|
||||
Reference in New Issue
Block a user