diff --git a/apps/permission/signals.py b/apps/permission/signals.py index 5ea04113..af5ab4ce 100644 --- a/apps/permission/signals.py +++ b/apps/permission/signals.py @@ -13,6 +13,7 @@ EXCLUDED = [ 'cas_server.serviceticket', 'cas_server.user', 'cas_server.userattributes', + 'constance.constance', 'contenttypes.contenttype', 'logs.changelog', 'migrations.migration', diff --git a/note_kfet/admin.py b/note_kfet/admin.py index 6bda409f..7f4effe3 100644 --- a/note_kfet/admin.py +++ b/note_kfet/admin.py @@ -56,3 +56,8 @@ if "cas_server" in settings.INSTALLED_APPS: from cas_server.models import * admin_site.register(ServicePattern, ServicePatternAdmin) admin_site.register(FederatedIendityProvider, FederatedIendityProviderAdmin) + +if "constance" in settings.INSTALLED_APPS: + from constance.admin import * + from constance.models import * + admin_site.register([Config], ConstanceAdmin) diff --git a/note_kfet/settings/base.py b/note_kfet/settings/base.py index 8a0fc738..dc954453 100644 --- a/note_kfet/settings/base.py +++ b/note_kfet/settings/base.py @@ -41,6 +41,7 @@ INSTALLED_APPS = [ 'bootstrap_datepicker_plus', 'cas_server', 'colorfield', + 'constance', 'crispy_bootstrap4', 'crispy_forms', # 'django_htcpcp_tea', @@ -112,6 +113,7 @@ TEMPLATES = [ 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ + 'constance.context_processors.config', 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', @@ -315,3 +317,20 @@ CAS_LOGGED_TEMPLATE = 'cas/logged.html' # Default field for primary key DEFAULT_AUTO_FIELD = "django.db.models.AutoField" + +# Constance settings +CONSTANCE_ADDITIONAL_FIELDS = { + 'banner_type': ['django.forms.fields.ChoiceField', { + 'widget': 'django.forms.Select', + 'choices': (('info', 'Info'), ('success', 'Success'), ('warning', 'Warning'), ('danger', 'Danger')) + }], +} +CONSTANCE_CONFIG = { + 'BANNER_MESSAGE': ('', 'Some message', str), + 'BANNER_TYPE': ('Info', 'Banner type', 'banner_type'), +} +CONSTANCE_CONFIG_FIELDSETS = { + 'Banner': ('BANNER_MESSAGE', 'BANNER_TYPE'), +} +CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend' +CONSTANCE_SUPERUSER_ONLY = True diff --git a/note_kfet/templates/base.html b/note_kfet/templates/base.html index 45dcdfe7..f7794222 100644 --- a/note_kfet/templates/base.html +++ b/note_kfet/templates/base.html @@ -191,7 +191,11 @@ SPDX-License-Identifier: GPL-3.0-or-later {% endblocktrans %} {% endif %} - {# TODO Add banners #} + {% if config.BANNER_MESSAGE %} +
Default content...
diff --git a/requirements.txt b/requirements.txt index 1d6f5063..c40bf0bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ Django~=5.2.4 django-bootstrap-datepicker-plus~=5.0.5 django-cas-server~=3.1.0 django-colorfield~=0.14.0 +django-constance~=4.3.2 django-crispy-forms~=2.4.0 django-extensions>=4.1.0 django-filter~=25.1