Code

Opened 2 years ago

Closed 2 years ago

#18420 closed Uncategorized (fixed)

JavaScript crashes in django admin for translation inlines in some circumstances

Reported by: maciej.maciaszek@… Owned by: nobody
Component: contrib.admin Version: 1.4
Severity: Normal Keywords: javascript
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This issue is close to #10651.

I use here FeinCMS but I'm sure it's Django bug not Feincms bug.

Models of my app integrated as Aplication Content look like:

class Plant(models.Model, TranslatedObjectMixin):

    class Meta:
        verbose_name = _('Performance')


class PlantTranslation(Translation(Plant)):
    title = models.CharField(max_length=255, verbose_name=_('Performance Title'))
    slug = models.SlugField()
    description = models.TextField(max_length=2000)

    class Meta:
        verbose_name = _('Peformance Translation')

    def __unicode__(self):
        return '%s' % (self.title,)

admin.py


class PlantAdmin(admin.ModelAdmin):
    inlines = [admin_translationinline(PlantTranslation)]

As you can see in django admin I only have inline forms for each translation because translated object itself doesn't have any fields.

JavaScript crashes at django/contrib/admin/templates/admin/change_form.html on line 70.

It renders this line as:

<script type="text/javascript">document.getElementById("").focus();</script>

so I get an JS error. It would be nice that JS check first if there's existing field which it can focus on.

Attachments (2)

django_admin_first_field_focus.diff (743 bytes) - added by maciej.maciaszek@… 2 years ago.
django_admin_first_field_focus.2.diff (747 bytes) - added by maciej.maciaszek@… 2 years ago.
fixed diff

Download all attachments as: .zip

Change History (4)

Changed 2 years ago by maciej.maciaszek@…

comment:1 Changed 2 years ago by Keryn Knight <django@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

That patch looks like it'll throw a TemplateSyntaxError on the if statement, as the test terminates on 'and' rather than 'and add'

Changed 2 years ago by maciej.maciaszek@…

fixed diff

comment:2 Changed 2 years ago by Julien Phalip <jphalip@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [d708298184f8e19f250d2cee5bb900e496ed1175]:

Fixed #18420 -- Prevented the admin JS from crashing when the main form contains no field. Thanks to maciej.maciaszek for the report and patch.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.