Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django-tinymce and django-filebrowser doesn't comunicate #364

Open
MaxDragonheart opened this issue Jul 4, 2021 · 1 comment
Open

Django-tinymce and django-filebrowser doesn't comunicate #364

MaxDragonheart opened this issue Jul 4, 2021 · 1 comment

Comments

@MaxDragonheart
Copy link

MaxDragonheart commented Jul 4, 2021

I think this is not a bug but my misunderstaning about the setting up between this package and django-filebrowser.

I'm using:

  • django-tinymce 3.3.0
  • django-filebrowser 3.14.1

In settings.py I've this:

INSTALLED_APPS = [
    'grappelli',
    'filebrowser',
    'tinymce',
    'corsheaders',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sitemaps',
    'django.contrib.gis',
    'django.contrib.sites',
    'django.contrib.flatpages',
   .
   .
   .
]

TINYMCE_DEFAULT_CONFIG = {
    "height": "800",
    "menubar": "file edit view insert format tools table help",
    "plugins": "advlist autolink lists link image charmap print preview anchor searchreplace visualblocks code "
                "fullscreen insertdatetime media table paste code help wordcount spellchecker",
    "toolbar": "undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft "
                "aligncenter alignright alignjustify | outdent indent |  numlist bullist checklist | forecolor "
                "backcolor casechange permanentpen formatpainter removeformat | pagebreak | charmap emoticons | "
                "fullscreen  preview save print | insertfile image media pageembed template link anchor codesample | "
                "a11ycheck ltr rtl | showcomments addcomment code",
    "custom_undo_redo_levels": 10,
}
TINYMCE_SPELLCHECKER = False
TINYMCE_FILEBROWSER = True

In urls.py I've this:

from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path

from filebrowser.sites import site

urlpatterns = [
    path('admin-site/', include([
        path('filebrowser/', site.urls),
        path('grappelli/', include('grappelli.urls')),
        path('', admin.site.urls),
        path('tinymce/', include('tinymce.urls')),
    ])),
    .
    .
    .
]

if settings.DEBUG:
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I'm be able to use Tinymce as you can see on the image below
Screenshot from 2021-07-04 09-37-11

But I can't use django-filebrowser.
Screenshot from 2021-07-04 09-37-39

I've created an image field that use django-filebrowser and it is possible to add media without problems.
Screenshot from 2021-07-04 09-38-29

Probably I'm forgot something, but what?

@some1ataplace
Copy link

It seems that there is a communication issue between django-tinymce and django-filebrowser when trying to insert a file using django-filebrowser in the django-tinymce editor.

One suggestion provided in the issue is to check if the URLs for both django-tinymce and django-filebrowser are correctly configured.

Another suggested workaround is to use django-ckeditor instead of django-tinymce, as django-ckeditor is known to work well with django-filebrowser.

It is also recommended to check the versions of django-tinymce and django-filebrowser, as there may be compatibility issues between older versions of the two packages. Updating to the latest versions of both packages may help resolve the issue.


It seems that there is a miscommunication between django-tinymce and django-filebrowser when using the filebrowser plugin in tinymce.

One possible cause of this issue is that the filebrowser plugin is not properly configured to work with django-filebrowser. To fix this, you can try the following steps:

  1. Make sure that django-filebrowser is properly installed and configured in your Django project.

  2. Check that the filebrowser plugin is included in your tinymce configuration:

TINYMCE_DEFAULT_CONFIG = {
    'plugins': 'filebrowser',
    # ...
}
  1. Configure the filebrowser plugin to use django-filebrowser by adding the following settings to your Django project's settings.py file:
# settings.py
FILEBROWSER_DIRECTORY = ''
FILEBROWSER_VERSIONS_BASEDIR = '_versions'
FILEBROWSER_VERSIONS = {
    'admin_thumbnail': {'verbose_name': 'Admin Thumbnail', 'width': 60, 'height': 60, 'opts': 'crop'},
}
  1. Make sure that the filebrowser plugin is properly initialized in your tinymce configuration by adding the following code to your Django project's admin.py file:
# admin.py
from django.contrib import admin
from django.urls import reverse
from django.utils.html import escape
from django.utils.safestring import mark_safe
from tinymce.widgets import TinyMCE

class TinyMCEAdmin(admin.ModelAdmin):
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == 'content':
            return db_field.formfield(widget=TinyMCE(attrs={'file_browser_callback': 'filebrowser'}))
        return super().formfield_for_dbfield(db_field, **kwargs)

    class Media:
        js = ('tiny_mce/tiny_mce.js', 'tiny_mce/textareas.js', 'filebrowser/js/TinyMCEAdmin.js',)
        css = {
            'all': ('filebrowser/css/filebrowser.css',),
        }

    def get_urls(self):
        urls = super().get_urls()
        urls += [
            path('tinymce/', include('tinymce.urls')),
            path('admin/filebrowser/', filebrowser_site.urls),
        ]
        return urls

admin.site.register(MyModel, TinyMCEAdmin)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants