makinacorpus / django-mapentity

Generic CRUD for geographic data
https://django-mapentity.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
42 stars 20 forks source link

✨ [FEAT] Add in TinyMCE Areas possibility for the user to upload a local file #277

Open babastienne opened 1 year ago

babastienne commented 1 year ago

Demonstration of the feature :

mapentity.webm

The local media will be imported into MEDIA_ROOT folder and automatically added to the text area.

Files are store in the media folder and then into the following path : /tinymce/<generated-uuid>/file.ext. The generated uuid allow to avoid conflicts if multiple files with the same name are uploaded.

Everything seems to be working fine.

By default TinyMCE stored a relative path for the uploaded files. I ensure the URL stored for local files are absolute urls therefore GTR3 and others services can exploit data without having to rebuild URLs and API V2 from Geotrek needs no modification either.

One important element not done in this PR: The uploaded files are stored into media but there is no method to delete them if there not used anymore. I'd like some help to find the best strategy to find and remove unused uploaded file. A command that users will need to run ? An asynchrone task ? How can we determine which files are not used ?

codecov-commenter commented 1 year ago

Codecov Report

Patch coverage: 46.66% and project coverage change: -0.28% :warning:

Comparison is base (2f04b5b) 89.08% compared to head (ef724aa) 88.80%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #277 +/- ## ========================================== - Coverage 89.08% 88.80% -0.28% ========================================== Files 31 31 Lines 2373 2386 +13 ========================================== + Hits 2114 2119 +5 - Misses 259 267 +8 ``` | [Files Changed](https://app.codecov.io/gh/makinacorpus/django-mapentity/pull/277?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=makinacorpus) | Coverage Δ | | |---|---|---| | [mapentity/settings.py](https://app.codecov.io/gh/makinacorpus/django-mapentity/pull/277?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=makinacorpus#diff-bWFwZW50aXR5L3NldHRpbmdzLnB5) | `91.66% <ø> (ø)` | | | [mapentity/views/\_\_init\_\_.py](https://app.codecov.io/gh/makinacorpus/django-mapentity/pull/277?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=makinacorpus#diff-bWFwZW50aXR5L3ZpZXdzL19faW5pdF9fLnB5) | `100.00% <ø> (ø)` | | | [mapentity/views/base.py](https://app.codecov.io/gh/makinacorpus/django-mapentity/pull/277?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=makinacorpus#diff-bWFwZW50aXR5L3ZpZXdzL2Jhc2UucHk=) | `74.63% <42.85%> (-3.77%)` | :arrow_down: | | [mapentity/urls.py](https://app.codecov.io/gh/makinacorpus/django-mapentity/pull/277?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=makinacorpus#diff-bWFwZW50aXR5L3VybHMucHk=) | `100.00% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

camillemonchicourt commented 1 year ago

Nice. I had in mind since a long time to activate upload features in Tinymce to make it a lot easier for user to include their images into static pages. 👍 Maybe we should not put "tinymce" in the file path, to have something more generic like "media/uploads/uuid/.."

submarcos commented 1 year ago

Better way to achieve this is to create an attachment to keep naming / categorization logic and possibility to delete it if required

camillemonchicourt commented 7 months ago

To me there will be just a few images uploaded in the WYSIWYG, so it is not crucial to have an orphan deletion mechanism.

In classical CMS, there are thousands of images uploaded in articles and no automatic system to delete unused ones.

So in our case it is secondary as most images are uploaded as objects attachments, and it shouldn't block this PR in my opinion.

marcantoinedupre commented 7 months ago

The use of Attachment model to support the TinyMCE image upload should be considered for the following reasons:

But using Attachment is not straightforward as an instance ID is needed to create an Attachment so we cannot create it when an image is uploaded on the form to create a new entity.

We could create temporary files/attachments in the image_upload handler and create the real Attachement on saving after form validation on the Django side.

Another concern is the absolute URLs which are inserted in the tinymce HTML content. When GTA server configuration changes (for instance with a new domain) all those URLs will be broken.