This commit is contained in:
shamoon
2024-01-11 22:55:04 -08:00
parent 37ae9aec2e
commit 97e25f26aa
11 changed files with 96 additions and 21 deletions

View File

@@ -1171,6 +1171,9 @@ class UiSettingsView(GenericAPIView):
ui_settings["app_title"] = settings.APP_TITLE
if general_config.app_title is not None and len(general_config.app_title) > 0:
ui_settings["app_title"] = general_config.app_title
ui_settings["app_logo"] = settings.APP_LOGO
if general_config.app_logo is not None and len(general_config.app_logo) > 0:
ui_settings["app_logo"] = general_config.app_logo
user_resp = {
"id": user.id,

View File

@@ -102,8 +102,10 @@ class GeneralConfig(BaseConfig):
"""
app_title: str = dataclasses.field(init=False)
app_logo: str = dataclasses.field(init=False)
def __post_init__(self) -> None:
app_config = self._get_config_instance()
self.app_title = app_config.app_title or None
self.app_logo = app_config.app_logo.url if app_config.app_logo else None

View File

@@ -1,4 +1,4 @@
# Generated by Django 4.2.8 on 2024-01-07 07:31
# Generated by Django 4.2.9 on 2024-01-12 05:33
from django.db import migrations
from django.db import models
@@ -10,6 +10,16 @@ class Migration(migrations.Migration):
]
operations = [
migrations.AddField(
model_name="applicationconfiguration",
name="app_logo",
field=models.FileField(
blank=True,
null=True,
upload_to="",
verbose_name="Application logo",
),
),
migrations.AddField(
model_name="applicationconfiguration",
name="app_title",
@@ -17,7 +27,7 @@ class Migration(migrations.Migration):
blank=True,
max_length=48,
null=True,
verbose_name="Application Title",
verbose_name="Application title",
),
),
]

View File

@@ -1,3 +1,4 @@
from django.core.validators import FileExtensionValidator
from django.core.validators import MinValueValidator
from django.db import models
from django.utils.translation import gettext_lazy as _
@@ -167,12 +168,22 @@ class ApplicationConfiguration(AbstractSingletonModel):
)
app_title = models.CharField(
verbose_name=_("Application Title"),
verbose_name=_("Application title"),
null=True,
blank=True,
max_length=48,
)
app_logo = models.FileField(
verbose_name=_("Application logo"),
null=True,
blank=True,
validators=[
FileExtensionValidator(allowed_extensions=["jpg", "png", "gif", "svg"]),
],
upload_to="logo/",
)
class Meta:
verbose_name = _("paperless application settings")

View File

@@ -129,6 +129,11 @@ class ApplicationConfigurationSerializer(serializers.ModelSerializer):
data["user_args"] = None
return super().run_validation(data)
def update(self, instance, validated_data):
if instance.app_logo and "app_logo" in validated_data:
instance.app_logo.delete()
return super().update(instance, validated_data)
class Meta:
model = ApplicationConfiguration
fields = "__all__"

View File

@@ -367,6 +367,7 @@ STORAGES = {
"staticfiles": {
"BACKEND": _static_backend,
},
"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"},
}
_CELERY_REDIS_URL, _CHANNELS_REDIS_URL = _parse_redis_url(
@@ -1000,6 +1001,7 @@ if ENABLE_UPDATE_CHECK != "default":
ENABLE_UPDATE_CHECK = __get_boolean("PAPERLESS_ENABLE_UPDATE_CHECK")
APP_TITLE = os.getenv("PAPERLESS_APP_TITLE", None)
APP_LOGO = os.getenv("PAPERLESS_APP_LOGO", None)
###############################################################################
# Machine Learning #

View File

@@ -1,3 +1,5 @@
import re
from django.conf import settings
from django.conf.urls import include
from django.contrib import admin
@@ -8,6 +10,7 @@ from django.utils.translation import gettext_lazy as _
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import RedirectView
from django.views.static import serve
from rest_framework.authtoken import views
from rest_framework.routers import DefaultRouter
@@ -181,6 +184,12 @@ urlpatterns = [
url=settings.STATIC_URL + "frontend/en-US/assets/%(path)s",
),
),
# App logo
re_path(
r"^%s(?P<path>.*)$" % re.escape(settings.MEDIA_URL.lstrip("/")),
serve,
kwargs={"document_root": settings.MEDIA_ROOT},
),
# TODO: with localization, this is even worse! :/
# login, logout
path("accounts/", include("django.contrib.auth.urls")),