jonasundderwolf / django-image-cropping

Django helper application to easily and non-destructively crop arbitrarily large images in admin and frontend.
Other
553 stars 130 forks source link

Editing images with pencil symbol broken #109

Closed philippze closed 4 years ago

philippze commented 7 years ago

In the admin, usual Django ForeignKey fields have a little pencil symbol next to them that acts as a direct link to the chosen object.

After I replace the usual widget for ForeignKeys with an ImageCropWidget, the pencil becomes a bit transparent and does no more work.

I've found a workaround: Override the static file admin/js/related-widget-wrapper.js with a copy where you've added the following line:

container.find('.related-widget-wrapper input.crop-thumb').each(updateLinks);

I don't know if there's a better way.

(I use Django version 1.8 and django-image-cropping version 1.0.3)

philippze commented 7 years ago

Some details about this problem.

It is about this file (which ceases after version 1.8): https://github.com/django/django/blob/aa10ba096169dcbd3e47303f6b6de59acfe883c1/django/contrib/admin/static/admin/js/related-widget-wrapper.js

There happen 2 things in this file:

  1. Open a popup when the user clicks on a pencil
  2. Most pencils are links but have no href attribute. The code in the file creates this attribute if it finds an appropriate select field. As the ImageCropWidget does not use a select field, this code will not be executed, and hence, the pencil link has no href and will not work.
anrie commented 7 years ago

What seems to be happening is that we use the ForeignKeyRawIdWidget but aren't adding the field to raw_id_fields. If you look at how Django displays raw_id_fields by default you will only see the lookup link (magnifying glass) but not the add-link (plus) or edit-link (pencil).

This seems to be the relevant code passage in Django: https://github.com/django/django/blob/master/django/contrib/admin/options.py#L154

So the quick fix would be to always also add our CropFKs to the raw_id_fields (and consequently remove the broken extra links)

On the other hand the behavior in related-widget-wrapper.js should probably consider the fact that the tag could be something else than a select. So I guess one could argue that it's a bug in Django: Either the additional links shouldn't be displayed for the widget (even if the widget isn't explicitly added to raw_id_fields) or the links should be functional.

MRigal commented 4 years ago

As the admin has completely changed and the file admin/js/related-widget-wrapper.js isn't available anymore, I would close this issue as wontfix.

If you are still having troubles here @philippze , consider reopening and updating this issue. Thanks for the report!

philippze commented 4 years ago

Yes, please close. It's about a project that I'm no more maintaining for many years.