django-tinymce icon indicating copy to clipboard operation
django-tinymce copied to clipboard

Does not work with ManifestFiles

Open selected-pixel-jameson opened this issue 5 years ago • 4 comments

I'm using the ManifestFilesMixin along with the Django-Storages to collect static files and upload them to S3.

This is working for all of the other plugins that I use. But for some reason the tinymce.min.js file is not rewritten when it is included in the admin site.

This throws a 404 error and doesn't load the WYSIWIG because it fails to find TinyMCE.

Screen Shot 2020-05-05 at 9 05 09 AM

I'm loading TinyMCE via the widget property in a custom form.

class PromoForm(forms.ModelForm):

  description = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))

  class Meta:
    model = Promo
    exclude = []

I'm using the following versions.

Django 2.2.12 django-tinymce 3.0.2

As I stated I have various other libraries that I'm implementing in the same way and not having this issue. (i.e. django-autocomplete-light 3.5.0). Which has lead me to believe it is an issue with this library and not django-storages or the manifest files.

selected-pixel-jameson avatar May 05 '20 14:05 selected-pixel-jameson

I ended up hardcoding this. Not an ideal solution.

selected-pixel-jameson avatar May 05 '20 18:05 selected-pixel-jameson

Have you tried to set the TINYMCE_JS_URL setting?

The complexity with this tinymce project is that you need to enable people to add tinymce plugins. I guess we should change the way it worked in the past and only support static files but previsouly we were supporting MEDIA_URL too.

Natim avatar May 26 '20 06:05 Natim

Hey,

i'm having the same problem. We're using S3 for our Static and Media files. But it has to sign the URLs.

TINYMCE_EXTRA_MEDIA = {
        "css": {"all": ["tinymce/skins/ui/oxide/skin.min.css"]},
        "js": ["tinymce/tinymce.min.js", "tinymce/themes/silver/theme.min.js"],
    }
TINYMCE_JS_URL = ''    

This works perfectly fine, signing our URLs and everything. But with default config it just prints the S3 URL without the signature.

FabianClemenz avatar Oct 21 '21 12:10 FabianClemenz

This issue might be caused because the tinymce.min.js file is not being properly rewritten by the ManifestFilesMixin when collecting static files. To fix this issue, you can try the following steps:

  1. First, make sure that you have properly configured the ManifestFilesMixin and Django-Storages settings in your Django project.

  2. Ensure that the django-tinymce package is installed and added to the INSTALLED_APPS list in your Django project settings.

  3. In your Django project settings, add the following code to rewrite the TinyMCE path:

   from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
   from django.core.files.storage import default_storage

   class TinyMCEManifestStaticFilesStorage(ManifestStaticFilesStorage):
       def hashed_name(self, name, content=None, filename=None):
           if 'tinymce.min.js' in name:
               name = name.replace('tinymce.min.js', 'tinymce/tinymce.min.js')
           return super().hashed_name(name, content, filename)

   # Replace the default storage with the custom one
   if not isinstance(default_storage, TinyMCEManifestStaticFilesStorage):
       default_storage.__class__ = TinyMCEManifestStaticFilesStorage
  1. In your Django project settings, make sure to use the custom storage class for static files:

STATICFILES_STORAGE = 'your_project_name.settings.TinyMCEManifestStaticFilesStorage'

  1. Run python manage.py collectstatic to collect static files and upload them to S3.

  2. Clear your browser cache and reload the admin site to see if the issue is resolved.

If the issue still persists after following these steps, consider checking the following:

  1. Double-check the S3 bucket permissions and CORS (Cross-Origin Resource Sharing) settings to ensure that your browser can properly access the tinymce.min.js file.

  2. Inspect your browser's developer console for any error messages or network issues related to loading the tinymce.min.js file. This can provide more information on possible problems and help you debug the issue further.

  3. Verify that other static files are being served correctly from your S3 bucket. If not, there might be a more general issue with your Django-Storages and S3 configuration that needs to be addressed.

some1ataplace avatar Mar 31 '23 00:03 some1ataplace