stephenmcd / mezzanine

CMS framework for Django
http://mezzanine.jupo.org
BSD 2-Clause "Simplified" License
4.75k stars 1.64k forks source link

[BUG] Collapsibles aren't working when DEBUG = False in Mezzanine 5.0.0 #2005

Closed RandomJo closed 2 years ago

RandomJo commented 2 years ago

Is there an existing issue for this?

Current Behavior

Collapsible sections of the admin aren't working in Mezzanine 5.0.0 when DEBUG = False. They do work as expected when DEBUG = True.

Expected Behavior

I expect to be able to toggle a collapsible fieldset in the admin.

Steps To Reproduce

  1. Install Django at 2.2.25 and Mezzanine at 5.0.0 with Python 3.8.
  2. Make sure the DEBUG setting = False.
  3. Identify or create a page type that has a collapsible fieldset. I believe the Meta Data fieldset is collapsible by default, which is where I noticed it.
  4. Load the page in the admin and observe that the fieldset cannot be toggled. It is grey by default and is not clickable. It should be blue and clickable to toggle open and closed.

Environment

- Operating System: Ubuntu
- Python version: 3.8
- Django version: 2.2.25
- Database engine and version: PostgreSQL@10
- Mezzanine version: 5.0.0

Anything else?

For others with this issue, I resolved this temporarily for myself by reverting back to the 5.0.0a1 alpha release.

Before trying this, I also found that I could fix this by overriding the templates/admin/change_form.html with the following:

{% extends "admin/change_form.html" %}

{% block extrahead %}
  {{ block.super }}
  {% comment %}
    After upgrading to Mezzanine 5.0.0, the collapse.min.js version of this file
    stopped working. I'm not entirely sure why, but pulling in the non-minified
    version seems to fix it.
  {% endcomment %}
  {% if not debug %}
    <script type="text/javascript" src="/static/admin/js/collapse.js"></script>
  {% endif %}
{% endblock %}
jerivas commented 2 years ago

Hi @RandomJo,

Can you try again with the latest master version (commit 70404bbb0007bd3779476b9ece85ac3856722f6f)? I was unable to reproduce the problem with DEBUG=False, the templates always refer to collapse.js, not the minified version.

jerivas commented 2 years ago

Closing because I can't reproduce the problem

caffodian commented 2 years ago

We have run into this. I think i know why, but haven't fixed it yet.

this is how django decides which version of the collapse.js to load: https://github.com/django/django/blob/119f227aa62885f12cd7dd2558a62148d02adbb4/django/contrib/admin/options.py#L2327

Collapse.min.js is actually pre-minified and included in the Django package: https://github.com/django/django/blob/cab36618326524b336517c2c5fd62633916818e0/django/contrib/admin/static/admin/js/collapse.min.js

Since there's no minified version of that file included here, the minified Django collapse.min.js will be picked up instead of the unminified collapse.js here.

and i guess prior to this PR: https://github.com/stephenmcd/mezzanine/commit/95b138a961d5a102cfe79ed792cba1e9b93d134a it would have still worked because it'd load the minified django collapse + the unminified mezzanine collapse still.