-
-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use static file as logo (if sets) #378
Changes from all commits
ddb480b
ae6b6b5
80a3bf7
89fe3e5
892b7ac
5e78796
b4d8d0e
ee8c179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ def ready(self): | |
from admin_interface import settings | ||
|
||
settings.check_installed_apps() | ||
|
||
# must check if LOCAL_FILE_DIR is set in settings | ||
settings.check_settings("LOCAL_FILE_DIR") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This setting should be optional, it makes no sense to ask users to set a setting that they probably don't need. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-05-10 18:20-0500\n" | ||
"POT-Creation-Date: 2024-03-19 18:27-0500\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
@@ -114,6 +114,10 @@ msgstr "Farbe" | |
msgid "visible" | ||
msgstr "sichtbar" | ||
|
||
#: admin_interface/models.py | ||
msgid "static logo" | ||
msgstr "statisches Logo" | ||
|
||
#: admin_interface/models.py | ||
msgid "Leave blank to use the default Django logo" | ||
msgstr "Dieses Feld leer lassen um das Django Standard Logo zu benutzen" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: django-admin-interface\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-05-10 18:20-0500\n" | ||
"POT-Creation-Date: 2024-03-19 18:27-0500\n" | ||
"PO-Revision-Date: 2023-08-04 11:52-0300\n" | ||
"Last-Translator: Santiago Muñoz <[email protected]>\n" | ||
"Language-Team: Spanish <[email protected]>\n" | ||
|
@@ -116,6 +116,10 @@ msgstr "color" | |
msgid "visible" | ||
msgstr "visible" | ||
|
||
#: admin_interface/models.py | ||
msgid "static logo" | ||
msgstr "logo estático" | ||
|
||
#: admin_interface/models.py | ||
msgid "Leave blank to use the default Django logo" | ||
msgstr "Dejar en blanco para usar el logo por defecto de Django" | ||
|
@@ -236,7 +240,8 @@ msgstr "anclar posición" | |
|
||
#: admin_interface/models.py | ||
msgid "quick remove links for active filters at top of sidebar" | ||
msgstr "remover enlaces para filtros activos en la parte superior de la barra lateral" | ||
msgstr "" | ||
"remover enlaces para filtros activos en la parte superior de la barra lateral" | ||
|
||
#: admin_interface/models.py | ||
msgid "foldable apps" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: django-admin-interface\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-05-10 18:20-0500\n" | ||
"POT-Creation-Date: 2024-03-19 18:27-0500\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: Amir Ajorloo <[email protected]>\n" | ||
"Language-Team: Farsi <[email protected]>\n" | ||
|
@@ -113,6 +113,10 @@ msgstr "رنگ" | |
msgid "visible" | ||
msgstr "نمایان" | ||
|
||
#: admin_interface/models.py | ||
msgid "static logo" | ||
msgstr "لوگوی استاتیک" | ||
|
||
#: admin_interface/models.py | ||
msgid "Leave blank to use the default Django logo" | ||
msgstr "برای نمایش لوگوی پیش فرض، خالی بگذارید." | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-05-10 18:20-0500\n" | ||
"POT-Creation-Date: 2024-03-19 18:27-0500\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
@@ -114,6 +114,10 @@ msgstr "couleur" | |
msgid "visible" | ||
msgstr "visible" | ||
|
||
#: admin_interface/models.py | ||
msgid "static logo" | ||
msgstr "logo statique" | ||
|
||
#: admin_interface/models.py | ||
msgid "Leave blank to use the default Django logo" | ||
msgstr "Laisser vide pour utiliser le logo Django par défaut" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: django-admin-interface\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-05-10 18:20-0500\n" | ||
"POT-Creation-Date: 2024-03-19 18:27-0500\n" | ||
"PO-Revision-Date: 2018-12-30 19:13-0500\n" | ||
"Last-Translator: Fabio Caccamo <[email protected]>\n" | ||
"Language-Team: Italian <[email protected]>\n" | ||
|
@@ -115,6 +115,10 @@ msgstr "colore" | |
msgid "visible" | ||
msgstr "visibile" | ||
|
||
#: admin_interface/models.py | ||
msgid "static logo" | ||
msgstr "logo statico" | ||
|
||
#: admin_interface/models.py | ||
msgid "Leave blank to use the default Django logo" | ||
msgstr "Lasciare vuoto per usare il logo Django di default" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: django-admin-interface\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-05-10 18:20-0500\n" | ||
"POT-Creation-Date: 2024-03-19 18:27-0500\n" | ||
"PO-Revision-Date: 2022-02-04 19:13-0500\n" | ||
"Last-Translator: Kamil Paduszyński <[email protected]>\n" | ||
"Language-Team: Polish <[email protected]>\n" | ||
|
@@ -115,6 +115,10 @@ msgstr "kolor" | |
msgid "visible" | ||
msgstr "widoczny" | ||
|
||
#: admin_interface/models.py | ||
msgid "static logo" | ||
msgstr "statyczne logo" | ||
|
||
#: admin_interface/models.py | ||
msgid "Leave blank to use the default Django logo" | ||
msgstr "Puste ustawia domyślne logo Django" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-05-10 18:20-0500\n" | ||
"POT-Creation-Date: 2024-03-19 18:27-0500\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
@@ -114,6 +114,10 @@ msgstr "cor" | |
msgid "visible" | ||
msgstr "visível" | ||
|
||
#: admin_interface/models.py | ||
msgid "static logo" | ||
msgstr "logo estático" | ||
|
||
#: admin_interface/models.py | ||
msgid "Leave blank to use the default Django logo" | ||
msgstr "Deixe em branco para usar o logotipo padrão do Django" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: PACKAGE VERSION\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-06-23 16:28-0500\n" | ||
"POT-Creation-Date: 2024-03-19 18:27-0500\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
@@ -116,6 +116,10 @@ msgstr "цвет" | |
msgid "visible" | ||
msgstr "видимый" | ||
|
||
#: admin_interface/models.py | ||
msgid "static logo" | ||
msgstr "статический логотип" | ||
|
||
#: admin_interface/models.py | ||
msgid "Leave blank to use the default Django logo" | ||
msgstr "Оставьте пустым, чтобы по умолчанию использовать логотип Django" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ msgid "" | |
msgstr "" | ||
"Project-Id-Version: django-admin-interface\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2023-05-10 18:20-0500\n" | ||
"POT-Creation-Date: 2024-03-19 18:27-0500\n" | ||
"PO-Revision-Date: 2020-01-29 04:53+0300\n" | ||
"Last-Translator: Ishak Okutan <[email protected]>\n" | ||
"Language-Team: \n" | ||
|
@@ -115,6 +115,10 @@ msgstr "renk" | |
msgid "visible" | ||
msgstr "göster" | ||
|
||
#: admin_interface/models.py | ||
msgid "static logo" | ||
msgstr "sabit logo" | ||
|
||
#: admin_interface/models.py | ||
msgid "Leave blank to use the default Django logo" | ||
msgstr "Varsayılan Django logosunu kullanmak için boş bırakın" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 5.0.3 on 2024-03-19 22:29 | ||
|
||
import admin_interface.models | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("admin_interface", "0030_theme_collapsible_stacked_inlines_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="theme", | ||
name="static_logo_path", | ||
field=models.FilePathField( | ||
blank=True, | ||
match="^.*\\.(jpg|jpeg|png|svg)$", | ||
max_length=255, | ||
path=admin_interface.models.static_logo_directory_path, | ||
verbose_name="static logo", | ||
), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,16 @@ | |
from django.dispatch import receiver | ||
from django.utils.encoding import force_str | ||
from django.utils.translation import gettext_lazy as _ | ||
from django.conf import settings | ||
import os | ||
|
||
from .cache import del_cached_active_theme | ||
|
||
|
||
def static_logo_directory_path(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please name this method |
||
return settings.LOCAL_FILE_DIR | ||
|
||
|
||
class ThemeQuerySet(models.QuerySet): | ||
def get_active(self): | ||
objs_active_qs = self.filter(active=True) | ||
|
@@ -62,6 +68,14 @@ class Theme(models.Model): | |
verbose_name=_("visible"), | ||
) | ||
|
||
static_logo_path = models.FilePathField( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please name this field |
||
path=static_logo_directory_path, | ||
blank=True, | ||
verbose_name=_("static logo"), | ||
match=r"^.*\.(jpg|jpeg|png|svg)$", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also |
||
max_length=255, | ||
) | ||
|
||
logo = models.FileField( | ||
upload_to="admin-interface/logo/", | ||
blank=True, | ||
|
@@ -401,10 +415,26 @@ class Theme(models.Model): | |
|
||
objects = ThemeQuerySet.as_manager() | ||
|
||
@property | ||
def static_logo_relative_url(self): | ||
return os.path.relpath(self.static_logo_path, settings.STATIC_ROOT) | ||
|
||
def set_active(self): | ||
self.active = True | ||
self.save() | ||
|
||
def save(self, *args, **kwargs): | ||
if self.static_logo_path: | ||
# clear cache if static logo path has changed | ||
try: | ||
obj = Theme.objects.get(pk=self.pk) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This query (and the related logic) can be avoided by checking if the |
||
if obj.static_logo_path != self.static_logo_path: | ||
del_cached_active_theme() | ||
except Theme.DoesNotExist: | ||
pass | ||
|
||
super().save(*args, **kwargs) | ||
|
||
class Meta: | ||
app_label = "admin_interface" | ||
verbose_name = _("Theme") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The best way to define settings in third-party packages that allow the best flexibility when testing them (overridding them with different values) is this: In package from django.core.exceptions import ImproperlyConfigured
try:
from admin_interface import settings # noqa: F401
except ImproperlyConfigured:
pass In package from django.conf import settings
if not hasattr(settings, "ADMIN_INTERFACE_MY_SETTING"):
settings.ADMIN_INTERFACE_MY_SETTING = "default value" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,5 +25,18 @@ | |
) | ||
|
||
|
||
def check_settings(setting_attribute): | ||
""" | ||
Check if the setting_attribute is set in the settings module. | ||
""" | ||
|
||
if not hasattr(settings, setting_attribute): | ||
raise ImproperlyConfigured( | ||
"You must set the {} setting in your settings module.".format( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests coverage should be improved. |
||
setting_attribute | ||
) | ||
) | ||
|
||
|
||
def check_installed_apps(): | ||
check_installed_app("colorfield") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,3 +120,4 @@ | |
|
||
STATIC_ROOT = os.path.join(BASE_DIR, "admin_interface/public/static/") | ||
STATIC_URL = "/static/" | ||
LOCAL_FILE_DIR = os.path.join(BASE_DIR, "admin_interface/public/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this name is too generic (doesn’t indicate it’s for django-admin-interface) and at the same time too vague! (local file dir? what is a file dir, what is a non-local file dir) So: I think this could be named something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe change the settings name with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering that this is a setting for specifying the static logo directory, I would name it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would show this after the
logo
field.