Opened 4 years ago

Last modified 4 years ago

#32324 closed Cleanup/optimization

Wrapping the header in base.html of contrib.abmin in {% blocks %}. — at Version 8

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 Muskan Vaswan)

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

  1. 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)

  1. 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.

Change History (9)

comment:1 by Muskan Vaswan, 4 years ago

Owner: changed from nobody to Muskan Vaswan
Status: newassigned

comment:2 by Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: assignedclosed
Summary: Adding more blocks to the contrib.admin siteAdding more blocks to the contrib.admin site.

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 another block around existing blocks can increase flexibility.

in reply to:  2 comment:3 by Muskan Vaswan, 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 another block around existing blocks can increase flexibility.

comment:4 by Mariusz Felisiak, 4 years ago

Resolution: invalidneedsinfo

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 Muskan Vaswan, 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 Muskan Vaswan, 4 years ago

comment:6 by Carlton Gibson, 4 years ago

Resolution: needsinfo
Status: closednew

Thanks for the more detailed info. I will reopen to triage again.

comment:7 by Carlton Gibson, 4 years ago

Triage Stage: UnreviewedAccepted

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?

in reply to:  7 comment:8 by Muskan Vaswan, 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...

Note: See TracTickets for help on using tickets.
Back to Top