0

Trying to add custom page into the admin. I want this page to have the same header and upper menu like any other page in admin from django-admin-tools.

Everything seems to be ok except the welcome section.

This is how it should look like enter image description here

This is how it looks enter image description here

As you can see there is missing the upper right section.

This is my base template:

{% extends "admin:admin/app_index.html" %}
{% load django_tables2 %}
{% block extrastyle %}
    {{ block.super }}
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.5/datepicker.min.css">
{% endblock %}

{% block extrahead %}
    {{ block.super }}
    <script
            src="https://code.jquery.com/jquery-3.3.1.min.js"
            integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
            crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/datepicker/0.6.5/datepicker.min.js"></script>
    <script>
        $(document).ready(function () {
            $(".datepicker").datepicker(
                {
                    format: 'dd.mm.yyyy'
                }
            );
        })
    </script>
{% endblock %}

{% block content %}
    {{ block.super }}
    {% block render_home_table %}
        <section class="home_table_section">
            <button class="copy_table_to_cb">Clipboard</button>
            {% render_table home_table %}
        </section>
    {% endblock %}
    {% block render_away_table %}
        <button class="copy_table_to_cb">Clipboard</button>
        <section class="away_table_section">
            {% render_table away_table %}
        </section>
    {% endblock %}

{% endblock %}

How to fix this? Do I have to extend another template?

Milano
  • 18,048
  • 37
  • 153
  • 353

1 Answers1

1

Use this code:

{% if not is_popup %}
<!-- Header -->
<div id="header">
    <div id="branding">
    {% block branding %}{% endblock %}
    </div>
    {% block usertools %}
    {% if has_permission %}
    <div id="user-tools">
        {% block welcome-msg %}
            {% trans 'Welcome,' %}
            <strong>{% firstof user.get_short_name user.get_username %}</strong>.
        {% endblock %}
        / <a href="/analytics">View Analytics</a> /
        {% block userlinks %}
            {% if site_url %}
                <a href="{{ site_url }}">{% trans 'View site' %}</a> /
            {% endif %}
            {% if user.is_active and user.is_staff %}
                {% url 'django-admindocs-docroot' as docsroot %}
                {% if docsroot %}
                    <a href="{{ docsroot }}">{% trans 'Documentation' %}</a> /
                {% endif %}
            {% endif %}
            {% if user.has_usable_password %}
            <a href="{% url 'admin:password_change' %}">{% trans 'Change 
password' %}</a> /
            {% endif %}
            <a href="{% url 'admin:logout' %}">{% trans 'Log out' %}</a>
        {% endblock %}
    </div>
    {% endif %}
    {% endblock %}
    {% block nav-global %}{% endblock %}
</div>

After which you need to pass these parameters to your return statement in your views which renders this page.

from django.contrib.admin import AdminSite
class MyAdminSite(admin.AdminSite):
            pass
mysite = MyAdminSite()
return render(request, 'analytics.html',  {'user': request.user,'site_header': mysite.site_header,'has_permission': mysite.has_permission(request), 'site_url': mysite.site_url})
ans2human
  • 2,300
  • 1
  • 14
  • 29
  • Unfortunately, this doesn't work for bredcrumbs. It adds this breadcrumb under the blue line. But the problem is upper right section line Odhlásiť / Logout etc – Milano Jul 26 '18 at 12:38
  • @MilanoSlesarik, my bad brother, i mistook your question for top left breadcrumbs. Give me sometime i'll edit my ans ASAP. – ans2human Jul 26 '18 at 12:42
  • @MilanoSlesarik i have updated the ans, please review. – ans2human Jul 26 '18 at 13:11
  • Thank but I can't figure out where to put it. There is such a wild inheritance between admin_tools and admin... – Milano Jul 26 '18 at 16:53