Skip to content

Commit

Permalink
[CHANGE] Switch to django-solo
Browse files Browse the repository at this point in the history
No need to provide our own singleton instance, since django-solo is now a dependency of AA
  • Loading branch information
ppfeufer committed Sep 19, 2024
1 parent fab0f16 commit 570f31b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 96 deletions.
7 changes: 7 additions & 0 deletions .make/conf.d/django.mk
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ compile_translations:
-l uk \
-l zh_Hans

# Migrations
.PHONY: migrations
migrations:
@echo "Creating or updating migrations"
@python ../myauth/manage.py makemigrations $(package)

# Help message
.PHONY: help
help::
@echo " $(TEXT_UNDERLINE)Translation:$(TEXT_UNDERLINE_END)"
@echo " migrations Create or update migrations"
@echo " translations Create or update translation files"
@echo " compile_translations Compile translation files"
@echo ""
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Section Order:
### Security
-->

### Changed

- Switch to django-solo to provide the singleton for the settings model, instead of the custom implementation

## \[3.3.0\] - 2024-09-16

### Changed
Expand Down
55 changes: 3 additions & 52 deletions fleetpings/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
AA Fleet Pings :: Admin
"""

# Third Party
from solo.admin import SingletonModelAdmin

# Django
from django.contrib import admin
from django.contrib.auth.models import Group
Expand Down Expand Up @@ -45,58 +48,6 @@ def __new__(cls, *args, **kwargs):
return Wrapper


class SingletonModelAdmin(admin.ModelAdmin):
"""
Prevents Django admin users deleting the singleton or adding extra rows
"""

actions = None # Removes the default delete action.

def has_add_permission(self, request) -> bool: # 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
) -> bool:
"""
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
) -> bool:
"""
Has "delete" permissions
:param request:
:type request:
:param obj:
:type obj:
:return:
:rtype:
"""

return False


@admin.register(FleetComm)
class FleetCommAdmin(admin.ModelAdmin):
"""
Expand Down
45 changes: 1 addition & 44 deletions fleetpings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Third Party
from requests.exceptions import HTTPError
from solo.models import SingletonModel

# Django
from django.contrib.auth.models import Group
Expand Down Expand Up @@ -60,50 +61,6 @@ def _get_discord_group_info(ping_target: Group) -> dict:
return discord_group_info


class SingletonModel(models.Model):
"""
Singleton model
"""

class Meta: # pylint: disable=too-few-public-methods
"""
SingletonModel :: Meta
"""

abstract = True

def save(self, *args, **kwargs):
"""
Save action
:param args:
:type args:
:param kwargs:
:type kwargs:
:return:
:rtype:
"""

if self.__class__.objects.count():
self.pk = self.__class__.objects.first().pk # pylint: disable=invalid-name

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


class AaFleetpings(models.Model):
"""
Alliance Auth Fleet Pings
Expand Down

0 comments on commit 570f31b

Please sign in to comment.