예제 #1
0
    def value_from_datadict(self, data, files, name):
        config = get_config()
        value = data.get(name, None)

        if value in config['empty']:
            return None

        return value
예제 #2
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        context['id'] = self.kwargs['id']
        context['id_safe'] = self.kwargs['id'].replace('-', '_')
        context['css'] = self.css
        context['js'] = self.js
        context['config'] = get_config()

        return context
예제 #3
0
    def summernote_settings(self):
        lang = get_proper_language()

        summernote_settings = get_config().get('summernote', {}).copy()
        summernote_settings.update({
            'lang': lang,
            'url': {
                'language': static('summernote/lang/summernote-' + lang + '.min.js'),
                'upload_attachment': reverse('django_summernote-upload_attachment'),
            },
        })
        return summernote_settings
예제 #4
0
    def formfield_for_dbfield(self, db_field, *args, **kwargs):
        summernote_widget = SummernoteWidget if get_config(
        )['iframe'] else SummernoteInplaceWidget

        if self.summernote_fields == '__all__':
            if isinstance(db_field, models.TextField):
                kwargs['widget'] = summernote_widget
        else:
            if db_field.name in self.summernote_fields:
                kwargs['widget'] = summernote_widget

        return super().formfield_for_dbfield(db_field, *args, **kwargs)
예제 #5
0
 def _media(self):
     config = get_config()
     return forms.Media(
         css={
             'all': (
                 (config['codemirror_css'] if has_codemirror_config() else ())
                 + config['default_css']
                 + config['css_for_inplace']
             )
         },
         js=(
             (config['codemirror_js'] if has_codemirror_config() else ())
             + config['default_js']
             + config['js_for_inplace']
         ))
예제 #6
0
    def render(self, name, value, attrs=None, **kwargs):
        summernote_settings = self.summernote_settings()
        summernote_settings.update(self.attrs.get('summernote', {}))

        html = super().render(name, value, attrs=attrs, **kwargs)
        context = {
            'id': attrs['id'],
            'id_safe': attrs['id'].replace('-', '_'),
            'attrs': self.final_attr(attrs),
            'config': get_config(),
            'settings': json.dumps(summernote_settings),
            'CSRF_COOKIE_NAME': django_settings.CSRF_COOKIE_NAME,
        }

        html += render_to_string('django_summernote/widget_inplace.html', context)
        return mark_safe(html)
예제 #7
0
    def __init__(self):
        super().__init__()
        config = get_config()

        static_default_css = tuple(static(x) for x in config['default_css'])
        static_default_js = tuple(static(x) for x in config['default_js'])
        self.css = \
            config['base_css'] \
            + (config['codemirror_css'] if has_codemirror_config() else ()) \
            + static_default_css \
            + config['css']

        self.js = \
            config['base_js'] \
            + (config['codemirror_js'] if has_codemirror_config() else ()) \
            + static_default_js \
            + config['js']

        self.config = config
예제 #8
0
from django.urls import path

from django_summernote.utils import get_config
from django_summernote.views import (SummernoteEditor,
                                     SummernoteUploadAttachment)

urlpatterns = [
    path('editor/<id>/',
         SummernoteEditor.as_view(),
         name='django_summernote-editor'),
]

if not get_config()['disable_attachment']:
    urlpatterns += [
        path('upload_attachment/',
             SummernoteUploadAttachment.as_view(),
             name='django_summernote-upload_attachment'),
    ]
예제 #9
0
 def __init__(self):
     super().__init__()
     self.config = get_config()
예제 #10
0
 def test_func(self):
     return get_config()['test_func_upload_view'](self.request)