From 1593159895155bfb6273157013350762a20e3a84 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Mon, 20 Dec 2021 14:32:25 +0100 Subject: [PATCH] Upload logo, PWA, and favicon files to public namespace --- aleksis/core/mixins.py | 14 ++++++++++++++ aleksis/core/preferences.py | 7 ++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/aleksis/core/mixins.py b/aleksis/core/mixins.py index 3232aac4d..c6cee9a8c 100644 --- a/aleksis/core/mixins.py +++ b/aleksis/core/mixins.py @@ -1,5 +1,6 @@ # flake8: noqa: DJ12 +import os from datetime import datetime from typing import Any, Callable, List, Optional, Union @@ -21,6 +22,8 @@ from django.views.generic import CreateView, UpdateView from django.views.generic.edit import DeleteView, ModelFormMixin import reversion +from dynamic_preferences.settings import preferences_settings +from dynamic_preferences.types import FilePreference from guardian.admin import GuardedModelAdmin from guardian.core import ObjectPermissionChecker from jsonstore.fields import IntegerField, JSONFieldMixin @@ -529,3 +532,14 @@ class SchoolTermRelatedExtensibleForm(ExtensibleForm): kwargs["initial"] = {"school_term": SchoolTerm.current} super().__init__(*args, **kwargs) + + +class PublicFilePreferenceMixin(FilePreference): + """Uploads a file to the public namespace.""" + + upload_path = "public" + + def get_upload_path(self): + return os.path.join( + self.upload_path, preferences_settings.FILE_PREFERENCE_UPLOAD_DIR, self.identifier() + ) diff --git a/aleksis/core/preferences.py b/aleksis/core/preferences.py index d0de22fe0..0110d9aa8 100644 --- a/aleksis/core/preferences.py +++ b/aleksis/core/preferences.py @@ -16,6 +16,7 @@ from dynamic_preferences.types import ( ) from oauth2_provider.models import AbstractApplication +from .mixins import PublicFilePreferenceMixin from .models import Group, Person from .registries import person_preferences_registry, site_preferences_registry from .util.notifications import get_notification_choices_lazy @@ -78,7 +79,7 @@ class ColourSecondary(StringPreference): @site_preferences_registry.register -class Logo(FilePreference): +class Logo(PublicFilePreferenceMixin, FilePreference): """Logo of your AlekSIS instance.""" section = theme @@ -88,7 +89,7 @@ class Logo(FilePreference): @site_preferences_registry.register -class Favicon(FilePreference): +class Favicon(PublicFilePreferenceMixin, FilePreference): """Favicon of your AlekSIS instance.""" section = theme @@ -98,7 +99,7 @@ class Favicon(FilePreference): @site_preferences_registry.register -class PWAIcon(FilePreference): +class PWAIcon(PublicFilePreferenceMixin, FilePreference): """PWA-Icon of your AlekSIS instance.""" section = theme -- GitLab