Opened 12 years ago

Closed 2 years ago

Last modified 2 years ago

#19215 closed Bug (fixed)

ImageField's “Currently” and “Clear” Sometimes Don't Appear

Reported by: nrogers64@… Owned by: Marcelo Galigniana
Component: Forms Version: 1.4
Severity: Normal Keywords: ImageField
Cc: Marcelo Galigniana Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

I have found scenarios where an ImageField's “Currently” and “Clear” widgets don't appear. Here are the instructions to reproduce the scenarios:

Create an app called "imagefield_bug" and paste this in its "models.py" file:

from django.db import models


class ImageFieldBug(models.Model):
    required_text_field = models.CharField(max_length=100)
    optional_image = models.ImageField(upload_to='images/', blank=True, null=True)

    def __unicode__(self):
        return self.required_text_field

Add the "imagefield_bug" app to your project's INSTALLED_APPS. Make sure "django.contrib.admin" is also in INSTALLED_APPS while you're at it.

Make sure the admin lines in "urls.py" are uncommented.

Run these commands:

printf "from django.contrib import admin\nfrom models import ImageFieldBug\n\nadmin.site.register(ImageFieldBug)\n" > imagefield_bug/admin.py

python manage.py syncdb

python manage.py runserver

Go to the following URL, log in, fill out both fields correctly, and click "Save and continue editing":

http://127.0.0.1:8000/admin/imagefield_bug/imagefieldbug/add/

Now you should see the "Currently" and "Clear" widgets. Choose a non-image to upload and then click "Save". Now the "Currently" and "Clear" widgets are gone, potentially misleading the user into thinking the original image is gone forever.

Now click your browser's "Back" button, refresh the page, blank out the "Required text field" field, and either check the "Clear" checkbox or choose a valid image to upload. After that, click "Save". Again, the "Currently" and "Clear" widgets will be gone.

See this django-developers discussion for more information.

Change History (7)

comment:1 by Carl Meyer, 12 years ago

Triage Stage: UnreviewedAccepted

Thanks for filing the report!

I've verified this behavior, and I think it is less-than-optimal. The path to fixing it isn't entirely clear, though.

comment:2 by Mariusz Felisiak, 2 years ago

Cc: Marcelo Galigniana added

comment:3 by Marcelo Galigniana, 2 years ago

Owner: changed from nobody to Marcelo Galigniana
Status: newassigned

comment:4 by Marcelo Galigniana, 2 years ago

Has patch: set

comment:5 by Mariusz Felisiak, 2 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In c0fc1b53:

Fixed #19215 -- Fixed rendering ClearableFileInput when editing with invalid files.

Thanks Michael Cardillo for the initial patch.

comment:7 by GitHub <noreply@…>, 2 years ago

In d559cb0:

Refs #19215 -- Fixed admin_widgets tests if Pillow isn't installed.

Follow up to c0fc1b5302f5d9d82e2255fb5758321fbac34949.

Note: See TracTickets for help on using tickets.
Back to Top