[Django] #29936: Improved font customization in the admin

33 views
Skip to first unread message

Django

unread,
Nov 9, 2018, 6:33:14 AM11/9/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
------------------------------------------------+------------------------
Reporter: Antonio Cavedoni | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: contrib.admin | Version: 2.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
------------------------------------------------+------------------------
The admin is pretty flexible when it comes to formatting. One can extend
the `extrastyle` block in the `admin/base_site.html` (which is actually
defined in `admin/base.html`) and override / inject whatever one may need
in the stylesheet. However, when it comes to customizing the fonts in the
admin, there currently is a big limitation due to the way the admin fonts
(Roboto) are being loaded. `admin/css/base.css` is referenced in a non-
extendable section of `admin/base.html`, and the first thing it does is to
`@import fonts.css`, which in turn loads a bunch of woff files for Roboto.
If one were to customize the fonts in their admin, they would still find
themselves loading these woffs, even if unused.

So I propose we remove the `@import` in `admin/css/base.css` and replace
it with a `<link rel="stylesheet">` inside an overridable block in
`base.html`. Right now I called it `adminfonts` for lack of a better name.

With that in place, a project can extend `base_site.html`, empty out
`adminfonts` and add whatever color / font customizations in the existing
`extrastyle` block.

This change would also offer some greater flexibility for users to at
least improve the situation for themselves when it comes to Django’s
default international font challenges—see issue #29122, for instance.

--
Ticket URL: <https://code.djangoproject.com/ticket/29936>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 9, 2018, 6:34:53 AM11/9/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Antonio Cavedoni):

* Attachment "admin-fonts.patch" added.

Patch for #29936 created on git master as of
75dfa92a05c7161edd0ba7bc9ceab9b54d3383db

Django

unread,
Nov 9, 2018, 12:05:07 PM11/9/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1
Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Ramiro Morales):

* keywords: => css roboto fonts woff font
* cc: elky (added)
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:1>

Django

unread,
Nov 9, 2018, 12:11:33 PM11/9/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Couldn't you override the `fonts.css` static file?

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:2>

Django

unread,
Nov 9, 2018, 4:03:12 PM11/9/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Antonio Cavedoni):

Replying to [comment:2 Tim Graham]:


> Couldn't you override the `fonts.css` static file?

Not really, because it’s hardcoded through an `@import` rule into the
admin `base.css`. You could have your own copy of either `fonts.css` or
the `base.css` file, but one would lose the convenience of being able to
update Django with no modifications.

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:3>

Django

unread,
Nov 9, 2018, 4:26:38 PM11/9/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Antonio Cavedoni):

I created a pull request with the proposed change:
https://github.com/django/django/pull/10631

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:4>

Django

unread,
Nov 14, 2018, 1:53:41 PM11/14/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

In the ticket description you said, a use case is to "empty out
adminfonts" -- is that different from overriding fonts.css with an empty
file? I'm still trying to understand a use case that requires the
additional template block.

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:5>

Django

unread,
Nov 15, 2018, 11:20:34 AM11/15/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Antonio Cavedoni):

It achieves the same thing but—I argue—in a more elegant way. Unless I’m
overlooking something obvious, overriding `fonts.css` with an empty file
essentially means maintaining one’s fork of Django. Even if it’s just
running a `ln -s` operation, it means having to do that after every Django
update / install. My solution avoids that by making the very import of
`fonts.css` an extendable (overridable) block so it can all be done at the
project / application level. Does that make the patch clearer?

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:6>

Django

unread,
Nov 15, 2018, 11:21:43 AM11/15/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Antonio Cavedoni):

(Whatever the outcome, thanks for your continued attention to this
admittedly minor issue, Tim.)

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:7>

Django

unread,
Nov 15, 2018, 2:22:55 PM11/15/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

You can override a static file by creating one with the same path in an
app that comes before the admin in `INSTALLED_APPS`.

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:8>

Django

unread,
Nov 16, 2018, 4:42:32 AM11/16/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

Or indeed using `STATICFILES_DIRS`. (With the default
`STATICFILES_FINDERS`, any files there will be found before any app
folders, so before `contrib.admin`’s)

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:9>

Django

unread,
Nov 16, 2018, 11:44:11 AM11/16/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Antonio Cavedoni):

Doesn’t that hold true only if you’re serving the static files via Django?
In other words, if you serve the admin static files via some other server,
Django isn’t even involved and no overriding can take place, correct?

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:10>

Django

unread,
Nov 16, 2018, 2:31:36 PM11/16/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution:
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Do you gather your static files without `collectstatic`?

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:11>

Django

unread,
Nov 19, 2018, 6:32:06 PM11/19/18
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 2.1
Severity: Normal | Resolution: invalid

Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Antonio Cavedoni):

* status: new => closed
* resolution: => invalid


Comment:

I see, I wasn’t aware of the interaction between app loading / overriding
and collectstatic. Awesome! Thanks, Tim & Carlton, and sorry for the
noise.

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:12>

Django

unread,
Aug 17, 2022, 4:26:38 AM8/17/22
to django-...@googlegroups.com
#29936: Improved font customization in the admin
-------------------------------------+-------------------------------------

Reporter: Antonio Cavedoni | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: contrib.admin | Version: 2.1

Severity: Normal | Resolution: invalid
Keywords: css roboto fonts | Triage Stage: Accepted
woff font |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson):

#33878 (for Django 4.2) added `--font-family-primary` and `--font-family-
monospace` variables that can be overridden as per
[https://docs.djangoproject.com/en/dev/ref/contrib/admin/#theming-support
Theming support docs].

--
Ticket URL: <https://code.djangoproject.com/ticket/29936#comment:13>

Reply all
Reply to author
Forward
0 new messages