Skip to content

Commit

Permalink
Merge 2d8fa75 into a1ee9a9
Browse files Browse the repository at this point in the history
  • Loading branch information
lundberg committed Apr 3, 2019
2 parents a1ee9a9 + 2d8fa75 commit 33a4197
Show file tree
Hide file tree
Showing 15 changed files with 518 additions and 376 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ all: clean test_all lint

.PHONY: isort
isort:
isort -rc bananas/
isort -rc bananas/ tests/ example/

.PHONY: black
black:
find bananas/ -name '*.py' | xargs black
find bananas/ tests/ example/ -name '*.py' | xargs black

.PHONY: format
format: black isort
27 changes: 22 additions & 5 deletions bananas/admin/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from .. import compat
from ..environment import env
from ..models import ModelDict

__all__ = ["ModelAdminView", "ViewTool", "AdminView", "register", "site"]

Expand Down Expand Up @@ -126,18 +127,33 @@ def has_delete_permission(self, request, obj=None):

def get_context(self, request, **extra):
opts = self.model._meta
changelist = ModelDict(opts=opts)

context = self.admin_site.each_context(request)
context.update(
{
"app_label": opts.app_label,
"model_name": force_text(opts.verbose_name_plural),
"title": force_text(opts.verbose_name_plural),
"cl": {"opts": opts}, # change_list.html requirement
"cl": changelist, # change_list.html requirement
"opts": opts, # change_form.html requirement
"media": self.media,
}
)
context.update(extra or {})

# Fill fake ChangeList object with required data to show search form and count
if extra.get("searchbar"):
changelist.update(
{
"query": request.GET.get("q") or "",
"search_fields": (None,),
"result_count": extra.get("result_count", 1),
"full_result_count": 0,
}
)

context.update(extra)

return context


Expand Down Expand Up @@ -247,6 +263,7 @@ class AdminView(View):
admin = None # type: ModelAdminView
tools = None
action = None
searchbar = False

def dispatch(self, request, *args, **kwargs):
# Try to fetch set action first.
Expand Down Expand Up @@ -315,9 +332,9 @@ def has_access(self):
return self.has_permission(self.admin.access_permission)

def get_context(self, **extra):
return self.admin.get_context(
self.request, view_tools=self.get_view_tools(), **extra
)
context = {"view_tools": self.get_view_tools(), "searchbar": self.searchbar}
context.update(extra)
return self.admin.get_context(self.request, **context)

def render(self, template, context=None):
extra = context or {}
Expand Down
87 changes: 68 additions & 19 deletions bananas/static/admin/bananas/css/bananas.css
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,22 @@ body.popup #changelist #toolbar {
margin-bottom: 0;
}
body:not(.popup) #changelist #toolbar {
display: none;
/*display: none;*/
}
#changelist #toolbar {
padding: 15px;
margin-bottom: 0;
border: 0;
background: #f6f6f6;
}

#changelist #toolbar form {
/*float: left;*/
width: 50%;
}

#changelist thead th {
border-top: 1px solid #f6f6f6;
}

.change-list .filtered {
Expand All @@ -726,16 +741,17 @@ body:not(.popup) #changelist #toolbar {
}

.nav-global #toolbar form {
display: block;
/*display: block;*/
display: none;
}

.change-list #content {
padding: 0;
}

.change-list #content-main {
padding-top: 45px /* fallback */;
padding-top: var(--searchbar-height);
/*padding-top: 45px; [> fallback <]*/
/*padding-top: var(--searchbar-height);*/
}

#changelist #changelist-filter {
Expand All @@ -748,16 +764,23 @@ body:not(.popup) #changelist #toolbar {
}

#changelist .actions {
padding: 15px;
background: transparent;
z-index: 5000;
color: #222;
position: absolute;
top: calc(-1 * 45px) /* fallback */;
top: calc(-1 * var(--searchbar-height));
left: 0;
top: 0;
/*float: right;*/
right: 0;
background: #417690 /* fallback */;
background: var(--theme-color);
background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.33), rgba(255, 255, 255, 0.33)) /* fallback */;
background-image: var(--bg-lighten-33);
color: #fff;
/*top: calc(-1 * 45px); [> fallback <];*/
/*top: calc(-1 * (var(--searchbar-height) + var(--topbar-height)));*/
/*left: 0;*/
/*right: 0;*/
/*background: #417690 [> fallback <];*/
/*background: var(--theme-color);*/
/*background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.33), rgba(255, 255, 255, 0.33)) [> fallback <];*/
/*background-image: var(--bg-lighten-33);*/
/*color: #fff;*/
line-height: 25px;
height: 25px;
}
Expand All @@ -774,27 +797,53 @@ body:not(.popup) #changelist #toolbar {

#changelist .actions label {
vertical-align: top;
float: left;
font-size: 0; /* Hide "Action:" */
}

#changelist .actions select {
#changelist .actions label select {
min-width: 300px;
height: 25px;
/*height: 25px;*/
background: #fff;
border-color: #fff;
/*border-color: #fff;*/

-webkit-appearance: none;
border-radius: 0;
border: 1px solid #ddd;
border-right: 0;
box-sizing: border-box;
height: var(--searchbar-height);
/*line-height: 45px [> fallback <];*/
/*line-height: var(--searchbar-height);*/
margin: 0;
padding: 5px 5px 5px 15px;
}

#changelist .actions .button {
border-radius: 0;
min-width: 48px;
height: 25px;
margin: 0 0 0 10px;
/*height: 25px;*/
height: 45px;
/*margin: 0 0 0 10px;*/
margin: 0;
vertical-align: top;
background: #417690 /* fallback */;
background: var(--theme-color);
/*background: #417690 [> fallback <];*/
/*background: var(--theme-color);*/
background: #ddd;
box-shadow: none;
border: 0;
color: #fff;
}

#changelist .actions span.action-counter {
display: inline;
position: absolute;
right: 80px;
line-height: 45px;
color: #999;
font-style: italic;
}

#changelist .actions span.all,
#changelist .actions span.action-counter,
#changelist .actions span.clear,
Expand Down
57 changes: 32 additions & 25 deletions bananas/static/admin/bananas/css/banansive.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,29 @@ body:not(.popup) #header #object-tools {
#changelist-search {
height: 45px /* fallback */;
height: var(--searchbar-height);
background: #417690 /* fallback */;
background: var(--theme-color);
display: inline;
/*background: #417690 [> fallback <];*/
/*background: var(--theme-color);*/
}

#changelist-search > div {
overflow: hidden;
display: flex;
}

#changelist-search .quiet {
clear: left;
float: right;
text-align: right;
margin: 0;
line-height: 20px;
text-align: right;
color: #fff;
opacity: 0.666;
position: relative;
z-index: 1;
background-color: rgba(0, 0, 0, 0.333);
padding: 2px 10px 2px 20px;
border-radius: 0 0 0 30px;
}

#changelist-search label {
Expand All @@ -22,14 +42,21 @@ body:not(.popup) #header #object-tools {
#changelist-search #searchbar {
float: left;
width: 185px;
height: 35px;
line-height: 35px;
height: 45px /* fallback */;
height: var(--searchbar-height);
line-height: 45px /* fallback */;
line-height: var(--searchbar-height);
margin: 0;
padding: 5px 5px 5px 15px;
border: 0;
border-radius: 0;
outline-width: 0;
flex-grow: 1;
border: 1px solid #ddd;
box-sizing: border-box;
border-right: 0;
}

#searchbar::-webkit-input-placeholder {
font-style: italic;
color: #999;
Expand Down Expand Up @@ -60,26 +87,6 @@ body:not(.popup) #header #object-tools {
background-image: url(/static/admin/bananas/img/search.svg), linear-gradient(to bottom, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.35));
}

#changelist-search > div {
overflow: hidden;
}

#changelist-search .quiet {
clear: left;
float: right;
text-align: right;
margin: 0;
line-height: 20px;
text-align: right;
color: #fff;
opacity: 0.666;
position: relative;
z-index: 1;
background-color: rgba(0, 0, 0, 0.333);
padding: 2px 10px 2px 20px;
border-radius: 0 0 0 30px;
}

#changelist-form .results {
clear: both;
}
Expand Down
2 changes: 1 addition & 1 deletion bananas/static/admin/bananas/js/bananas.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

var $filteredNavItem = $('.filtered nav a.is-selected')[0];
if ($filteredNavItem) {
document.location.hash = $filteredNavItem.name;
//document.location.hash = $filteredNavItem.name;
}
}

Expand Down
24 changes: 14 additions & 10 deletions example/example/admin.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
from bananas.admin import AdminView, register
from django.contrib import admin
from django.utils.translation import gettext_lazy as _

from bananas.admin import AdminView, register

from . import models


@register
class BananasAdmin(AdminView):
verbose_name = _('Bananas')
permissions = (('foobar_permission', 'Can foo bars'),)
verbose_name = _("Bananas")
permissions = (("foobar_permission", "Can foo bars"),)
searchbar = True
tools = (
(_('home'), 'admin:index', 'has_access'),
('superadmin only', 'https://foo.bar/', 'foobar_permission'),
(_("home"), "admin:index", "has_access"),
("superadmin only", "https://foo.bar/", "foobar_permission"),
)

def get(self, request):
return self.render('bananas.html')
context = {"result_count": 123 if request.GET.get("q") else 0}
return self.render("bananas.html", context)


@admin.register(models.Monkey)
class MonkeyAdmin(admin.ModelAdmin):
list_display = ('id',)
list_filter = ('user__username',)
raw_id_fields = ('user',)
date_hierarchy = 'date_created'
list_display = ("id",)
list_filter = ("user__username",)
raw_id_fields = ("user",)
date_hierarchy = "date_created"
actions_on_top = True
actions_on_bottom = True
actions_selection_counter = False
Loading

0 comments on commit 33a4197

Please sign in to comment.