Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check to handle empty form attributes in general non-crispy template #3140

Closed
wants to merge 2 commits into from

Conversation

podliashanyk
Copy link
Contributor

Originally mentioned in #3105 (review)

@lunkwill42 har suggested IRL to add the check to the general template.

A general failsafe for #2794

If no form.attrs are set then the standard form fields will be rendered. Works as a failsafe.
@podliashanyk podliashanyk requested a review from a team October 14, 2024 13:36
@podliashanyk podliashanyk self-assigned this Oct 14, 2024
Copy link

github-actions bot commented Oct 14, 2024

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON black 992 0 11.08s
✅ PYTHON ruff 987 0 0.1s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

Copy link

github-actions bot commented Oct 14, 2024

Test results

    9 files      9 suites   8m 30s ⏱️
2 135 tests 2 135 ✅ 0 💤 0 ❌
4 009 runs  4 009 ✅ 0 💤 0 ❌

Results for commit 626cc3e.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Oct 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.42%. Comparing base (1e9d859) to head (626cc3e).
Report is 21 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3140      +/-   ##
==========================================
- Coverage   60.44%   60.42%   -0.02%     
==========================================
  Files         605      605              
  Lines       43749    43745       -4     
  Branches       48       48              
==========================================
- Hits        26443    26435       -8     
- Misses      17294    17298       +4     
  Partials       12       12              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests fail since we have not added attrs to the management profile form in #3105.

And generally I thought we were moving away from having the catch-all {{ form }} since we will uncrispify all of nav.

If we don't want to have to add attrs to all forms this tactic is not ideal, since it shows that the tests fail even with the fallback.

It is not necessarily a complete and/or appropriate fallback for forms that are originally non-crispy. This is in ulikely unforeseen cases where for some reason Django widget can not be rendered as a foundation-5/field.html template without loosing some field data. Or a much more likely scenario when styles in foundation-5/field.html are not fitting for the form when reusing this template.
To sum it up: it should be generic enough for forms that are originally non-crispy but it is not a given. So if this template is to be reused by non-crispy forms (in contrast to uncrispified forms), the rendering of forms should be properly tested.
@podliashanyk podliashanyk force-pushed the add-failsafes-to-non-crispy-templates branch from 1ecddf3 to 626cc3e Compare November 4, 2024 13:57
Copy link

sonarcloud bot commented Nov 4, 2024

@podliashanyk podliashanyk requested review from johannaengland and a team November 4, 2024 14:43
Copy link
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make any difference now that {% include 'foundation-5/errors.html' %} will only be rendered if forms.attrs is set? Because before if this template was used even without setting form.attrs it would include that template

@podliashanyk
Copy link
Contributor Author

Does it make any difference now that {% include 'foundation-5/errors.html' %} will only be rendered if forms.attrs is set? Because before if this template was used even without setting form.attrs it would include that template

Good point. Furthermore upon further inspection of the diff I am actually inclined to close this one without merging. After inspecting Django code, it seems to me that having the original implementation of _form_content.html brings us closer to https://github.com/django/django/blob/main/django/forms/templates/django/forms/div.html (the one that is rendered when calling {{ form }}). Which means that the original is a better failsafe already. I will add an issue to fix rendering of CSRF token that works when _form_content.html is to be reused by templates that were non-crispy to begin with. Also we can now drop the failsafe {% if form.attrs %}...{% else %}{{ form }}{% endif %} everywhere when uncrispyfying crispy (if reusing _form_content.html).

@johannaengland
Copy link
Contributor

Furthermore upon further inspection of the diff I am actually inclined to close this one without merging. After inspecting Django code, it seems to me that having the original implementation of _form_content.html brings us closer to https://github.com/django/django/blob/main/django/forms/templates/django/forms/div.html (the one that is rendered when calling {{ form }}). Which means that the original is a better failsafe already.

I agree with you on that. Let's close this one

@podliashanyk podliashanyk deleted the add-failsafes-to-non-crispy-templates branch November 6, 2024 08:22
johannaengland added a commit that referenced this pull request Nov 12, 2024
johannaengland added a commit that referenced this pull request Nov 12, 2024
johannaengland added a commit that referenced this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants