diff --git a/allianceauth/custom_css/admin.py b/allianceauth/custom_css/admin.py index debc4f16..093e18e8 100644 --- a/allianceauth/custom_css/admin.py +++ b/allianceauth/custom_css/admin.py @@ -2,16 +2,16 @@ Admin classes for custom_css app """ +# Django +from django.contrib import admin + +# Django Solos +from solo.admin import SingletonModelAdmin + # Alliance Auth Custom CSS from allianceauth.custom_css.models import CustomCSS from allianceauth.custom_css.forms import CustomCSSAdminForm -# Alliance Auth Framework -from allianceauth.framework.admin import SingletonModelAdmin - -# Django -from django.contrib import admin - @admin.register(CustomCSS) class CustomCSSAdmin(SingletonModelAdmin): diff --git a/allianceauth/custom_css/models.py b/allianceauth/custom_css/models.py index d3c3cebd..c831cf6b 100644 --- a/allianceauth/custom_css/models.py +++ b/allianceauth/custom_css/models.py @@ -2,13 +2,11 @@ Models for the custom_css app """ -import hashlib import os import re -import sys -# Alliance Auth Framework -from allianceauth.framework.models import SingletonModel +# Django Solo +from solo.models import SingletonModel # Django from django.conf import settings @@ -62,7 +60,7 @@ class CustomCSS(SingletonModel): self.pk = 1 - if len(self.css.replace(" ", "")) > 0: + if self.css and len(self.css.replace(" ", "")) > 0: # Write the custom CSS to a file custom_css_file = open( f"{settings.STATIC_ROOT}allianceauth/custom-styles.css", "w+" diff --git a/allianceauth/framework/admin.py b/allianceauth/framework/admin.py deleted file mode 100644 index 8fb8e678..00000000 --- a/allianceauth/framework/admin.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -Admin classes for the framework app -""" - -from django.contrib import admin - - -class SingletonModelAdmin(admin.ModelAdmin): - """ - Singleton Model Admin - Prevents Django admin users deleting the singleton or adding extra rows. - """ - - actions = None # Removes the default delete action. - - def has_add_permission(self, request): # pylint: disable=unused-argument - """ - Has "add" permissions - - :param request: - :type request: - :return: - :rtype: - """ - - return self.model.objects.all().count() == 0 - - def has_change_permission( - self, request, obj=None # pylint: disable=unused-argument - ): - """ - Has "change" permissions - - :param request: - :type request: - :param obj: - :type obj: - :return: - :rtype: - """ - - return True - - def has_delete_permission( - self, request, obj=None # pylint: disable=unused-argument - ): - """ - Has "delete" permissions - - :param request: - :type request: - :param obj: - :type obj: - :return: - :rtype: - """ - - return False diff --git a/allianceauth/framework/models.py b/allianceauth/framework/models.py deleted file mode 100644 index 071de410..00000000 --- a/allianceauth/framework/models.py +++ /dev/null @@ -1,47 +0,0 @@ -""" -AA framework models -""" - -from django.db import models - - -class SingletonModel(models.Model): - """ - SingletonModel - """ - - class Meta: # pylint: disable=too-few-public-methods - """ - Model meta definitions - """ - - abstract = True - - def save(self, *args, **kwargs): - """ - "Save" action - - :param args: - :type args: - :param kwargs: - :type kwargs: - :return: - :rtype: - """ - - self.pk = 1 - super().save(*args, **kwargs) - - def delete(self, *args, **kwargs): - """ - "Delete" action - - :param args: - :type args: - :param kwargs: - :type kwargs: - :return: - :rtype: - """ - - pass # pylint: disable=unnecessary-pass diff --git a/allianceauth/project_template/project_name/settings/base.py b/allianceauth/project_template/project_name/settings/base.py index 14469132..cf26fe4a 100644 --- a/allianceauth/project_template/project_name/settings/base.py +++ b/allianceauth/project_template/project_name/settings/base.py @@ -22,6 +22,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'django.contrib.humanize', 'django_celery_beat', + 'solo', 'bootstrapform', 'django_bootstrap5', # https://github.com/zostera/django-bootstrap5 'sortedm2m', diff --git a/pyproject.toml b/pyproject.toml index a2568a40..35edbe64 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ dependencies = [ "django-esi>=5", "django-redis>=5.2", "django-registration<3.4,>=3.3", + "django-solo", "django-sortedm2m", "dnspython", "mysqlclient>=2.1",