Opened 4 years ago
Closed 4 years ago
#32324 closed Cleanup/optimization (fixed)
Wrapping the header in base.html of contrib.abmin in {% blocks %}.
Reported by: | Muskan Vaswan | Owned by: | Muskan Vaswan |
---|---|---|---|
Component: | contrib.admin | Version: | 3.1 |
Severity: | Normal | Keywords: | admin customize |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | yes |
Description (last modified by )
Use case
Allowing the user to overwrite the Top Navigation Bar od the admin page.
Existing method
to Overwrite the top nav-bar without having to overwrite the entire template of base.html, the user currently has to add the
{% extends "admin/base_site.html" %} {% load static %} {% block branding %} {% endblock %}
to admin/base_site.html and`
{% extends "admin/base.html" %} {% load static %} {% block usertools %} {% endblock %}
to admin/base.html.
No other method, other than overwriting the entire template exists.
Issue with Existing method
- Even after doing the above, the top-bar doesn't entirely disappear due to the CSS applied on the <div> with the id of header
(Image attached)
- The user must extend two separate files to even make this happen.
Solution
The simple solution is to wrap the entire header class using {% block ... %}. So the final django/admin/base.html would have:
<!-- Header --> {% block header %} <div id="header"> ... </div> {% endblock %} <!-- END Header -->
Final Result
The user will be able to overwrite the default blue-green nav-bar *entirely* by adding
{% extends "admin/base.html" %} {% load static %} {% block header %} {% endblock %}
to admin/base.html.
Attachments (1)
Change History (12)
comment:1 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
follow-up: 3 comment:2 by , 4 years ago
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
Summary: | Adding more blocks to the contrib.admin site → Adding more blocks to the contrib.admin site. |
comment:3 by , 4 years ago
That was an example... Also adding the entire header inside a block improves flexibility as it allows the user to change the entire topbar in one go rather changing singular elements. Not to mention currently if the user wants to make an entirely new topbar... ideally making the old one disappear entirely they would have to override and extend two files, that is, base_site.html for (branding block) and base.html (for the user_tools block) both and it still doesn't entirely dissapear. Which could simply be accomplished by adding a block for the entire header and the user could simply extend the base.html and {% block header %}{% endblock %}
.
Another example is if the user wants to change the add_url for a particular model having more blocks would be very helpful.
Replying to Mariusz Felisiak:
For example, the user can overwrite the entire navbar if the header was put inside {% block header %} simply by extending the template.
The navigation sidebar is already in a separate block
nav-sidebar
and use a separate template, so it's easy to customize, see comment. Also,header
already contains blocks for each element so I don't see how adding anotherblock
around existing blocks can increase flexibility.
comment:4 by , 4 years ago
Resolution: | invalid → needsinfo |
---|
Ticket described as "adding more blocks" cannot be accepted, it's too generic. You need to describe a concrete issue and use case. Maybe you should Set up your projects admin template directories for your use case.
Another example is if the user wants to change the add_url for a particular model having more blocks would be very helpful.
I don't think that templates are appropriate place for such logic.
comment:5 by , 4 years ago
Description: | modified (diff) |
---|---|
Summary: | Adding more blocks to the contrib.admin site. → Wrapping the header in base.html of contrib.abmin in {% blocks %}. |
In consideration of that, I wrote a more specific and comprehensive Issue. I hope this makes it more clear.
by , 4 years ago
Attachment: | Screen Shot 2021-01-06 at 5.02.36 PM.png added |
---|
comment:6 by , 4 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → new |
Thanks for the more detailed info. I will reopen to triage again.
follow-up: 8 comment:7 by , 4 years ago
Triage Stage: | Unreviewed → Accepted |
---|
Hmmm. I'm a bit sceptical that very many people want to remove the header entirely, but I agree that a single block would make that feasible.
Even after doing the above the top-bar doesn't entirely disappear dude to the CSS applied on the <div> with the id of header
Query: an amount of CSS resolves that no?
comment:8 by , 4 years ago
Description: | modified (diff) |
---|
Replying to Carlton Gibson:
Hmmm. I'm a bit sceptical that very many people want to remove the header entirely, but I agree that a single block would make that feasible.
Even after doing the above the top-bar doesn't entirely disappear dude to the CSS applied on the <div> with the id of header
Query: an amount of CSS resolves that no?
Yes, adding CSS to make would surely make it disappear, but I'm not sure if that would be the best way to do it, but again, that's just what I think.
About the first point, I have come across many occasions when I needed to replace the admin top-nav and personally, I don't think its that uncommon to have a themed top-bar that you want to use throughout the website.
At the same time, I agree, it's not a pressing issue by any means.
I guess it's just a matter of deciding whether making something like this more convenient for the user justifies adding another block...
comment:10 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
The navigation sidebar is already in a separate block
nav-sidebar
and use a separate template, so it's easy to customize, see comment. Also,header
already contains blocks for each element so I don't see how adding anotherblock
around existing blocks can increase flexibility.