Skip to content

Commit f86f83f

Browse files
Fix missing options in CloudinaryJsFileField
Fix bug introduced in Django 1.11: https://code.djangoproject.com/ticket/28095 Fixes #190
1 parent 3e8ff14 commit f86f83f

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

cloudinary/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CloudinaryInput(forms.TextInput):
1818
input_type = 'file'
1919

2020
def render(self, name, value, attrs=None, renderer=None):
21-
attrs = self.build_attrs(attrs)
21+
attrs = dict(self.attrs, **attrs)
2222
options = attrs.get('options', {})
2323
attrs["options"] = ''
2424

django_tests/forms.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from django import forms
2+
3+
from cloudinary.forms import CloudinaryJsFileField
4+
5+
6+
class CloudinaryJsTestFileForm(forms.Form):
7+
js_file_field = CloudinaryJsFileField(
8+
attrs={
9+
'style': "margin-top: 30px"
10+
},
11+
options={
12+
'tags': "directly_uploaded",
13+
'crop': 'limit', 'width': 1000, 'height': 1000,
14+
'eager': [{'crop': 'fill', 'width': 150, 'height': 100}]
15+
}
16+
)
Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import os
2-
3-
from mock import mock
4-
5-
import cloudinary
61
from django.core.files.uploadedfile import SimpleUploadedFile
72
from django.test import TestCase
3+
from mock import mock
84

9-
from cloudinary import api, CloudinaryResource
5+
import cloudinary
6+
from cloudinary import CloudinaryResource
107
from cloudinary.forms import CloudinaryFileField
8+
from django_tests.forms import CloudinaryJsTestFileForm
119
from django_tests.helper_test import SUFFIX, TEST_IMAGE, TEST_IMAGE_W, TEST_IMAGE_H
1210

1311
API_TEST_ID = "dj_test_{}".format(SUFFIX)
@@ -17,13 +15,14 @@ class TestCloudinaryFileField(TestCase):
1715
def setUp(self):
1816
self.test_file = SimpleUploadedFile(TEST_IMAGE, b'content')
1917

20-
def test_to_python(self):
18+
def test_file_field(self):
2119
cff_no_auto_save = CloudinaryFileField(autosave=False)
2220
res = cff_no_auto_save.to_python(None)
2321
self.assertIsNone(res)
2422
# without auto_save File is untouched
2523
res = cff_no_auto_save.to_python(self.test_file)
2624
self.assertIsInstance(res, SimpleUploadedFile)
25+
2726
# when auto_save is used, resource is uploaded to Cloudinary and CloudinaryResource is returned
2827
cff_auto_save = CloudinaryFileField(autosave=True, options={"public_id": API_TEST_ID})
2928
mocked_resource = cloudinary.CloudinaryResource(metadata={"width": TEST_IMAGE_W, "height": TEST_IMAGE_H},
@@ -36,5 +35,15 @@ def test_to_python(self):
3635
self.assertIsInstance(res, CloudinaryResource)
3736
self.assertEqual(API_TEST_ID, res.public_id)
3837

38+
def test_js_file_field(self):
39+
js_file_form = CloudinaryJsTestFileForm()
40+
41+
rendered_form = js_file_form.as_p()
42+
43+
self.assertIn("margin-top: 30px", rendered_form)
44+
self.assertIn("directly_uploaded", rendered_form)
45+
self.assertIn("c_fill,h_100,w_150", rendered_form)
46+
self.assertIn("c_limit,h_1000,w_1000", rendered_form)
47+
3948
def tearDown(self):
4049
pass

0 commit comments

Comments
 (0)