Skip to content

Commit

Permalink
Merge pull request #1 from ethanhann/bug/0003_alter_attachment_id_doe…
Browse files Browse the repository at this point in the history
…s_not_exists

Bug/0003 alter attachment id does not exists
  • Loading branch information
alexdeathway authored Jun 7, 2024
2 parents d299168 + 8a52bec commit f00f5f4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ SUMMERNOTE_CONFIG = {
# You can completely disable the attachment feature.
'disable_attachment': False,

# Set to `True` to return attachment paths in absolute URIs.
'attachment_absolute_uri': False,
# Set to `False` to return attachment paths in relative URIs.
'attachment_absolute_uri': True,

# test_func in summernote upload view. (Allow upload images only when user passes the test)
# https://docs.djangoproject.com/en/2.2/topics/auth/default/#django.contrib.auth.mixins.UserPassesTestMixin
Expand Down
3 changes: 2 additions & 1 deletion django_summernote/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class DjangoSummernoteConfig(AppConfig):
name = 'django_summernote'
verbose_name = 'Django Summernote'
default_auto_field = 'django.db.models.AutoField'

theme = 'bs3'
config = {}
Expand All @@ -34,7 +35,7 @@ def get_default_config(self):
'attachment_filesize_limit': 1024 * 1024,
'attachment_require_authentication': False,
'attachment_model': 'django_summernote.Attachment',
'attachment_absolute_uri': False,
'attachment_absolute_uri': True,

# additional test_func, for example you want to check if user is in specific group:
# https://docs.djangoproject.com/en/2.2/topics/auth/default/#django.contrib.auth.mixins.UserPassesTestMixin
Expand Down
3 changes: 2 additions & 1 deletion django_summernote/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from django.db import models
from django_summernote.utils import get_attachment_storage, get_attachment_upload_to

from django_summernote.utils import get_attachment_storage, get_attachment_upload_to

__all__ = ['AbstractAttachment', 'Attachment', ]


class AbstractAttachment(models.Model):
id = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")
name = models.CharField(max_length=255, null=True, blank=True, help_text="Defaults to filename, if left blank")
file = models.FileField(
upload_to=get_attachment_upload_to(),
Expand Down
6 changes: 5 additions & 1 deletion django_summernote/test_django_summernote.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def test_attachment_require_authentication(self):

@patch('django_summernote.views.logger')
def test_attachment_disable_attachment(self, mock_logging):
from django_summernote.widgets import SummernoteWidget

url = reverse('django_summernote-upload_attachment')
self.summernote_config['disable_attachment'] = True

Expand All @@ -279,6 +281,8 @@ def test_attachment_disable_attachment(self, mock_logging):
self.assertDictEqual(response.json(), {"status": "false", "message": "Attachment module is disabled"})
self.assertTrue(mock_logging.error.called)

self.assertNotIn('upload_attachment', SummernoteWidget().summernote_settings()['url'])

self.summernote_config['disable_attachment'] = False

@patch('django_summernote.views.logger')
Expand All @@ -303,7 +307,7 @@ def test_wrong_attachment(self, mock_logging):
)
self.assertTrue(mock_logging.error.called)
except ImportError:
# Without PIL, we cannot check the uploaded attachement has image format or not
# Without PIL, we cannot check the uploaded attachment has image format or not
with open(IMAGE_FILE, 'rb') as fp:
response = self.client.post(url, {'files': [fp]})
self.assertEqual(response.status_code, 200)
Expand Down
3 changes: 2 additions & 1 deletion django_summernote/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ def summernote_settings(self):
'lang': lang,
'url': {
'language': static('summernote/lang/summernote-' + lang + '.min.js'),
'upload_attachment': reverse('django_summernote-upload_attachment'),
},
})
if not get_config().get('disable_attachment', False):
summernote_settings['url']['upload_attachment'] = reverse('django_summernote-upload_attachment')
return summernote_settings

def value_from_datadict(self, data, files, name):
Expand Down

0 comments on commit f00f5f4

Please sign in to comment.