mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-07 03:43:48 -05:00
Merge pull request #4147 from alphagov/refactor-mixins
Refactor mixins for reuse and clearer naming
This commit is contained in:
@@ -8,21 +8,17 @@ from rtreelib import Rect
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.formatters import square_metres_to_square_miles
|
||||
from app.models import SortByNameMixin
|
||||
|
||||
from .populations import CITY_OF_LONDON
|
||||
from .repo import BroadcastAreasRepository, rtree_index
|
||||
|
||||
|
||||
class SortableMixin:
|
||||
class IdEqualityMixin:
|
||||
|
||||
def __repr__(self):
|
||||
return f'{self.__class__.__name__}(<{self.id}>)'
|
||||
|
||||
def __lt__(self, other):
|
||||
# Implementing __lt__ means any classes inheriting from this
|
||||
# method are sortable
|
||||
return self.name < other.name
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.id == other.id
|
||||
|
||||
@@ -79,7 +75,7 @@ class BaseBroadcastArea(ABC):
|
||||
return max(500, min(estimated_bleed, 5000))
|
||||
|
||||
|
||||
class BroadcastArea(BaseBroadcastArea, SortableMixin):
|
||||
class BroadcastArea(BaseBroadcastArea, IdEqualityMixin, SortByNameMixin):
|
||||
|
||||
def __init__(self, row):
|
||||
self.id, self.name, self._count_of_phones, self.library_id = row
|
||||
@@ -224,7 +220,7 @@ class CustomBroadcastAreas(SerialisedModelCollection):
|
||||
)
|
||||
|
||||
|
||||
class BroadcastAreaLibrary(SerialisedModelCollection, SortableMixin, GetItemByIdMixin):
|
||||
class BroadcastAreaLibrary(SerialisedModelCollection, SortByNameMixin, IdEqualityMixin, GetItemByIdMixin):
|
||||
|
||||
model = BroadcastArea
|
||||
|
||||
|
||||
@@ -64,9 +64,6 @@ class Organisation(JSONModel, SortByNameMixin):
|
||||
return cls({})
|
||||
return cls(organisations_client.get_organisation(org_id))
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.name.lower() < other.name.lower()
|
||||
|
||||
@classmethod
|
||||
def from_domain(cls, domain):
|
||||
return cls(organisations_client.get_organisation_by_domain(domain))
|
||||
|
||||
Reference in New Issue
Block a user