[mezzanine-users] Re: Admin action drop-down 'required' preventing saving updates

2021-02-18 Thread Danny

Hi again everyone,

I think I finally got to the bottom of my problem.

The Select widget  used for this admin dropdown *does* have the 
'required' attribute by default, but there's Mezzanine javascript that 
removes this from this specific location in admin pages:


https://github.com/stephenmcd/mezzanine/blob/master/mezzanine/core/static/mezzanine/js/admin/navigation.js#L6

In my case, the problem was that my website was hitting a Javascript 
error earlier on and thus this line wasn't executing properly or being 
skipped entirely. Part of this was that I had an old set of javascript 
files etc in 'static' on my webserver leftover from using Mezzanine 4.3.


Among other things,  I was missing the new jQuery version used by 
Mezzanine 5.0.0a1 and when I checked the developer console in my browser 
I could see a bunch of JS errors.


I manually ran python manage.py collectstatic, restarted the server, and 
now things appear to be working as expected.


So a word of advice for anyone else hitting similar upgrade issues: 
check the developer console in your browser for javascript errors, and 
make sure you have run collectstatic when you deploy!


Seeya. Danny.

On 18/02/2021 4:30 pm, Danny wrote:


Hi all,

This is possibly a Django-2.2.18 related problem, but I thought I'd 
see if anyone else has experienced this and had a workaround.


I recently updated my website to Mezzanine 5.0.0a1 and Django 2.2.18, 
and after some reasonably thorough local testing, deployed it to the 
live website.


One of my fellow admins discovered something odd, which I've now 
confirmed on both local and deployed sites.


At the top of an Admin change list page, there's the standard action 
drop down (usually containing 'Delete selected '). This is 
useful when you want to select some objects and delete them, but 
otherwise I've not customised it for any of the standard 
Mezzanine/Cartridge models I use.


What's now odd is that if you hit the 'Save' button at the bottom of 
the object list, a generic prompt pops up saying 'Please select an 
item in the list' pointing to this action drop down.


After some research, I discovered the following:

a) this pop up message is generic from HTML5, for a  form 
element that has the 'required' attribute: 
https://www.w3schools.com/TAGS/att_select_required.asp


b) this 'required' attribute is being added to the  element 
when the page is rendered, but only when DEBUG=False. That is, on my 
local development with DEBUG=True, the select element is not required 
(and Save works fine), but if I modify my local settings and set 
DEBUG=False, then required is forced on this element, and I get the 
same pop up as seen on the deployed server.


I've tried digging into the Django code to try and find out what's 
happening to render this field, but it seems to be fairly benign:


grapelli-safe template that renders the action drop down: 
https://github.com/stephenmcd/grappelli-safe/blob/master/grappelli_safe/templates/admin/actions.html#L3


django code that is the action form: 
https://github.com/django/django/blob/2.2.18/django/contrib/admin/helpers.py#L20


I'm not sure where the ChoiceField is being forced to required=True 
when DEBUG=False, nor how I can override this.


Any one got any ideas? Have you noticed this on your own deployments 
using Mezzanine 5.0.0a1?


Thanks for any help,

Seeya. Danny.



--
You received this message because you are subscribed to the Google Groups "Mezzanine 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mezzanine-users/38160e1e-093b-92e1-89c3-070fb1d77c51%40gmail.com.


Re: [mezzanine-users] Admin action drop-down 'required' preventing saving updates

2021-02-18 Thread Daniel Montecillo

Have you tried checking one of the forms used in the templates?
You can check there if required is explicitly declared.

Example:

```language-python

selection = forms.CharField(
required=True,
widget=forms.ChoiceField(attrs={"class": "form-control", 
"type": "text", }),

)

```

On 17 Feb 2021, at 23:00, Danny wrote:


Hi all,

This is possibly a Django-2.2.18 related problem, but I thought I'd 
see if anyone else has experienced this and had a workaround.


I recently updated my website to Mezzanine 5.0.0a1 and Django 2.2.18, 
and after some reasonably thorough local testing, deployed it to the 
live website.


One of my fellow admins discovered something odd, which I've now 
confirmed on both local and deployed sites.


At the top of an Admin change list page, there's the standard action 
drop down (usually containing 'Delete selected '). This is 
useful when you want to select some objects and delete them, but 
otherwise I've not customised it for any of the standard 
Mezzanine/Cartridge models I use.


What's now odd is that if you hit the 'Save' button at the bottom of 
the object list, a generic prompt pops up saying 'Please select an 
item in the list' pointing to this action drop down.


After some research, I discovered the following:

a) this pop up message is generic from HTML5, for a  form 
element that has the 'required' attribute: 



b) this 'required' attribute is being added to the  element 
when the page is rendered, but only when DEBUG=False. That is, on my 
local development with DEBUG=True, the select element is not required 
(and Save works fine), but if I modify my local settings and set 
DEBUG=False, then required is forced on this element, and I get the 
same pop up as seen on the deployed server.


I've tried digging into the Django code to try and find out what's 
happening to render this field, but it seems to be fairly benign:


grapelli-safe template that renders the action drop down: 



django code that is the action form: 



I'm not sure where the ChoiceField is being forced to required=True 
when DEBUG=False, nor how I can override this.


Any one got any ideas? Have you noticed this on your own deployments 
using Mezzanine 5.0.0a1?


Thanks for any help,

Seeya. Danny.

\--
You received this message because you are subscribed to the Google 
Groups "Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send 
an email to 
[mezzanine-users+unsubscr...@googlegroups.com]().
To view this discussion on the web visit 
[https://groups.google.com/d/msgid/mezzanine-users/a46283a7-99de-02ad-628f-26b80459403b%40gmail.com]().



--
You received this message because you are subscribed to the Google Groups "Mezzanine 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mezzanine-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mezzanine-users/6E450F43-B01A-4552-81E6-CA074CD1822C%40montecillo.ca.


publickey - daniel.montecillo@montecillo.ca - 5be7637f.asc
Description: application/pgp-keys


signature.asc
Description: OpenPGP digital signature