Skip to content

Commit bb9e2aa

Browse files
committed
Navbar and top buttons
* navbar-expand-md to stop navbar growing when dropdown opens. * Split dropdown doesn't work with tooltip - looks like a bs5 bug (same layout works with bs4) * Need to check button colours * Need to look at colour of dropdown links
1 parent 5983d27 commit bb9e2aa

File tree

3 files changed

+31
-27
lines changed

3 files changed

+31
-27
lines changed

rest_framework/static/rest_framework/css/bootstrap-tweaks.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ a single block in the template.
1818
font-size: 80%;
1919
}
2020

21-
.navbar-inverse .brand a {
21+
.navbar-dark .navbar-brand {
2222
color: #999999;
2323
}
24-
.navbar-inverse .brand:hover a {
24+
.navbar-inverse .navbar-brand:hover {
2525
color: white;
2626
text-decoration: none;
2727
}

rest_framework/templates/rest_framework/base.html

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@
3333

3434
<div class="wrapper">
3535
{% block navbar %}
36-
<div class="navbar navbar-static-top {% block bootstrap_navbar_variant %}navbar-inverse{% endblock %}"
36+
<div class="navbar navbar-expand-md fixed-top {% block bootstrap_navbar_variant %}navbar-dark{% endblock %}"
3737
role="navigation" aria-label="{% trans "navbar" %}">
3838
<div class="container">
39-
<span>
4039
{% block branding %}
4140
<a class='navbar-brand' rel="nofollow" href='https://www.django-rest-framework.org/'>
4241
Django REST framework
4342
</a>
4443
{% endblock %}
45-
</span>
46-
<ul class="nav navbar-nav pull-right">
44+
<ul class="navbar-nav">
4745
{% block userlinks %}
4846
{% if user.is_authenticated %}
4947
{% optional_logout request user %}
@@ -61,9 +59,9 @@
6159
<ul class="breadcrumb">
6260
{% for breadcrumb_name, breadcrumb_url in breadcrumblist %}
6361
{% if forloop.last %}
64-
<li class="active"><a href="{{ breadcrumb_url }}">{{ breadcrumb_name }}</a></li>
62+
<li class="breadcrumb-item active"><a href="{{ breadcrumb_url }}">{{ breadcrumb_name }}</a></li>
6563
{% else %}
66-
<li><a href="{{ breadcrumb_url }}">{{ breadcrumb_name }}</a></li>
64+
<li class="breadcrumb-item"><a href="{{ breadcrumb_url }}">{{ breadcrumb_name }}</a></li>
6765
{% endif %}
6866
{% empty %}
6967
{% block breadcrumbs_empty %}&nbsp;{% endblock breadcrumbs_empty %}
@@ -79,38 +77,37 @@
7977
{% block request_forms %}
8078

8179
{% if 'GET' in allowed_methods %}
82-
<form id="get-form" class="pull-right">
80+
<form id="get-form" class="float-right">
8381
<fieldset>
8482
{% if api_settings.URL_FORMAT_OVERRIDE %}
85-
<div class="btn-group format-selection">
86-
<a class="btn btn-primary js-tooltip" href="{{ request.get_full_path }}" rel="nofollow" title="Make a GET request on the {{ name }} resource">GET</a>
87-
88-
<button class="btn btn-primary dropdown-toggle js-tooltip" data-toggle="dropdown" title="Specify a format for the GET request">
89-
<span class="caret"></span>
83+
<div class="btn-group">
84+
<button class="btn btn-primary" data-toggle="tooltip" href="{{ request.get_full_path }}" rel="nofollow" title="Make a GET request on the {{ name }} resource">GET</button>
85+
<button class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" data-toggle-second="tooltip" title="Specify a format for the GET request">
86+
<span class="sr-only">Toggle Dropdown</span>
9087
</button>
9188
<ul class="dropdown-menu">
9289
{% for format in available_formats %}
9390
<li>
94-
<a class="js-tooltip format-option" href="{% add_query_param request api_settings.URL_FORMAT_OVERRIDE format %}" rel="nofollow" title="Make a GET request on the {{ name }} resource with the format set to `{{ format }}`">{{ format }}</a>
91+
<a class="dropdown-item" data-toggle="tooltip" href="{% add_query_param request api_settings.URL_FORMAT_OVERRIDE format %}" rel="nofollow" title="Make a GET request on the {{ name }} resource with the format set to `{{ format }}`">{{ format }}</a>
9592
</li>
9693
{% endfor %}
9794
</ul>
9895
</div>
9996
{% else %}
100-
<a class="btn btn-primary js-tooltip" href="{{ request.get_full_path }}" rel="nofollow" title="Make a GET request on the {{ name }} resource">GET</a>
97+
<a class="btn btn-primary" data-toggle="tooltip" href="{{ request.get_full_path }}" rel="nofollow" title="Make a GET request on the {{ name }} resource">GET</a>
10198
{% endif %}
10299
</fieldset>
103100
</form>
104101
{% endif %}
105102

106103
{% if options_form %}
107104
<form class="button-form" action="{{ request.get_full_path }}" data-method="OPTIONS">
108-
<button class="btn btn-primary js-tooltip" title="Make an OPTIONS request on the {{ name }} resource">OPTIONS</button>
105+
<button class="btn btn-primary" data-toggle="tooltip" title="Make an OPTIONS request on the {{ name }} resource">OPTIONS</button>
109106
</form>
110107
{% endif %}
111108

112109
{% if delete_form %}
113-
<button class="btn btn-danger button-form js-tooltip" title="Make a DELETE request on the {{ name }} resource" data-toggle="modal" data-target="#deleteModal">DELETE</button>
110+
<button class="btn btn-danger button-form" data-toggle="tooltip" title="Make a DELETE request on the {{ name }} resource" data-toggle="modal" data-target="#deleteModal">DELETE</button>
114111

115112
<!-- Delete Modal -->
116113
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
@@ -132,13 +129,12 @@ <h4 class="text-center">Are you sure you want to delete this {{ name }}?</h4>
132129

133130
{% if extra_actions %}
134131
<div class="dropdown" style="float: right; margin-right: 10px">
135-
<button class="btn btn-default" id="extra-actions-menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
132+
<button class="btn btn-info dropdown-toggle" id="extra-actions-menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
136133
{% trans "Extra Actions" %}
137-
<span class="caret"></span>
138134
</button>
139135
<ul class="dropdown-menu" aria-labelledby="extra-actions-menu">
140136
{% for action_name, url in extra_actions|items %}
141-
<li><a href="{{ url }}">{{ action_name }}</a></li>
137+
<li><a class="dropdown-item" href="{{ url }}">{{ action_name }}</a></li>
142138
{% endfor %}
143139
</ul>
144140
</div>
@@ -305,6 +301,15 @@ <h1>{{ name }}</h1>
305301
$('form').ajaxForm();
306302
});
307303
</script>
304+
<! -- enable tooltips -->
305+
<script type="text/javascript">
306+
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-toggle="tooltip"], [data-toggle-second="tooltip"]'))
307+
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
308+
return new bootstrap.Tooltip(tooltipTriggerEl)
309+
})
310+
311+
</script>
312+
308313
{% endblock %}
309314

310315
</body>

rest_framework/templatetags/rest_framework.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def optional_login(request):
9797
except NoReverseMatch:
9898
return ''
9999

100-
snippet = "<li><a href='{href}?next={next}'>Log in</a></li>"
100+
snippet = "<li class='nav-item'><a href='{href}?next={next}' class='nav-link'>Log in</a></li>"
101101
snippet = format_html(snippet, href=login_url, next=escape(request.path))
102102

103103
return mark_safe(snippet)
@@ -127,16 +127,15 @@ def optional_logout(request, user):
127127
try:
128128
logout_url = reverse('rest_framework:logout')
129129
except NoReverseMatch:
130-
snippet = format_html('<li class="navbar-text">{user}</li>', user=escape(user))
130+
snippet = format_html('<li class="nav-item">{user}</li>', user=escape(user))
131131
return mark_safe(snippet)
132132

133-
snippet = """<li class="dropdown">
134-
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
133+
snippet = """<li class="nav-item dropdown">
134+
<a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" id="navbarDropdown" role="button" data-toggle="dropdown">
135135
{user}
136-
<b class="caret"></b>
137136
</a>
138137
<ul class="dropdown-menu">
139-
<li><a href='{href}?next={next}'>Log out</a></li>
138+
<li><a class="dropdown-item" href='{href}?next={next}'>Log out</a></li>
140139
</ul>
141140
</li>"""
142141
snippet = format_html(snippet, user=escape(user), href=logout_url, next=escape(request.path))

0 commit comments

Comments
 (0)