mirror of
https://github.com/Hopiu/django-markdownx.git
synced 2026-03-17 05:50:23 +00:00
Fix _size problem for latest Django (#129)
This commit is contained in:
parent
0074bb250b
commit
4b4efa865d
3 changed files with 29 additions and 2 deletions
|
|
@ -54,7 +54,7 @@ class ImageForm(forms.Form):
|
|||
content_type = image.content_type
|
||||
file_name = image.name
|
||||
image_extension = content_type.split('/')[-1].upper()
|
||||
image_size = getattr(image, '_size')
|
||||
image_size = image.size
|
||||
|
||||
if content_type.lower() != self._SVG_TYPE:
|
||||
# Processing the raster graphic image.
|
||||
|
|
@ -176,7 +176,7 @@ class ImageForm(forms.Form):
|
|||
raise MarkdownxImageUploadError.not_uploaded()
|
||||
|
||||
content_type = upload.content_type
|
||||
file_size = getattr(upload, '_size')
|
||||
file_size = upload.size
|
||||
|
||||
if content_type not in MARKDOWNX_UPLOAD_CONTENT_TYPES:
|
||||
|
||||
|
|
|
|||
BIN
markdownx/tests/static/django-markdownx-preview.png
Normal file
BIN
markdownx/tests/static/django-markdownx-preview.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5 KiB |
|
|
@ -1,4 +1,10 @@
|
|||
import os
|
||||
import re
|
||||
from django.test import TestCase
|
||||
try:
|
||||
from django.urls import reverse
|
||||
except ImportError: # Djanago < 2.0
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
|
|
@ -6,3 +12,24 @@ class SimpleTest(TestCase):
|
|||
def test_me(self):
|
||||
response = self.client.get('/testview/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_upload(self):
|
||||
url = reverse('markdownx_upload')
|
||||
with open('markdownx/tests/static/django-markdownx-preview.png', 'rb') as fp:
|
||||
response = self.client.post(url, {'image': fp}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
|
||||
try:
|
||||
json = response.json()
|
||||
except AttributeError: # Django < 1.9
|
||||
import json
|
||||
json = json.loads(response.content.decode('utf-8'))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn('image_code', json)
|
||||
|
||||
match = re.findall(r'(markdownx/[\w\-]+\.png)', json['image_code'])
|
||||
try:
|
||||
if match:
|
||||
os.remove(match[0])
|
||||
except OSError:
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in a new issue