Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix metaclass conflict #522

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ jobs:
run: cp elixir_daisy/settings_compose_ci.py elixir_daisy/settings_compose.py

- name: Build and start containers
run: docker-compose up -d --build
run: docker compose up -d --build

- name: Check code formatting with Black
run: docker-compose exec -T web black --check --verbose .
run: docker compose exec -T web black --check --verbose .

- name: Install test dependencies
run: docker-compose exec -T web pip install ".[test]"
run: docker compose exec -T web pip install ".[test]"

- name: Execute the tests
run: docker-compose exec -T web pytest
run: docker compose exec -T web pytest

- name: Stop containers
if: always()
run: docker-compose down
run: docker compose down
4 changes: 2 additions & 2 deletions core/models/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from enumchoicefield import EnumChoiceField, ChoiceEnum

from .utils import CoreModel, CoreNotifyMeta
from .utils import CoreModel
from notification import NotifyMixin
from notification.models import NotificationVerb, Notification
from core.utils import DaisyLogger
Expand All @@ -35,7 +35,7 @@ class StatusChoices(ChoiceEnum):
terminated = "Terminated"


class Access(CoreModel, NotifyMixin, metaclass=CoreNotifyMeta):
class Access(CoreModel, NotifyMixin):
"""
Represents the access given to an internal (LCSB) entity over data storage locations.
"""
Expand Down
4 changes: 2 additions & 2 deletions core/models/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from core.permissions.mapping import PERMISSION_MAPPING
from notification import NotifyMixin
from notification.models import Notification, NotificationVerb
from .utils import CoreTrackedModel, TextFieldWithInputWidget, CoreNotifyMeta
from .utils import CoreTrackedModel, TextFieldWithInputWidget
from .partner import HomeOrganisation

if typing.TYPE_CHECKING:
Expand All @@ -28,7 +28,7 @@
logger = DaisyLogger(__name__)


class Dataset(CoreTrackedModel, NotifyMixin, metaclass=CoreNotifyMeta):
class Dataset(CoreTrackedModel, NotifyMixin):
class Meta:
app_label = "core"
get_latest_by = "added"
Expand Down
4 changes: 2 additions & 2 deletions core/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.core.files.storage import default_storage
from django.urls import reverse

from .utils import CoreModel, CoreNotifyMeta
from .utils import CoreModel
from core.utils import DaisyLogger
from notification.models import Notification, NotificationVerb
from notification import NotifyMixin
Expand All @@ -39,7 +39,7 @@ def get_file_name(instance, filename):
)


class Document(CoreModel, NotifyMixin, metaclass=CoreNotifyMeta):
class Document(CoreModel, NotifyMixin):
"""
Represents a document
"""
Expand Down
4 changes: 2 additions & 2 deletions core/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from notification.models import NotificationVerb, Notification
from core.utils import DaisyLogger

from .utils import CoreTrackedModel, COMPANY, CoreNotifyMeta
from .utils import CoreTrackedModel, COMPANY
from .partner import HomeOrganisation


Expand All @@ -30,7 +30,7 @@
logger = DaisyLogger(__name__)


class Project(CoreTrackedModel, NotifyMixin, metaclass=CoreNotifyMeta):
class Project(CoreTrackedModel, NotifyMixin):
class Meta:
app_label = "core"
get_latest_by = "added"
Expand Down
6 changes: 0 additions & 6 deletions core/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from django.utils.module_loading import import_string
from django.contrib.auth.hashers import make_password

from notification import NotifyMixin

COMPANY = getattr(settings, "COMPANY", "Company")


Expand Down Expand Up @@ -48,10 +46,6 @@ class Meta:
abstract = True


class CoreNotifyMeta(type(CoreModel), type(NotifyMixin)):
pass


class CoreTrackedModel(CoreModel):
elu_accession = models.CharField(
unique=True,
Expand Down
12 changes: 4 additions & 8 deletions notification/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from abc import ABC, abstractmethod
import typing
from typing import List, Optional
from datetime import timedelta
Expand All @@ -11,15 +10,14 @@
User = settings.AUTH_USER_MODEL


class NotifyMixin(ABC):
class NotifyMixin:
@staticmethod
@abstractmethod
def get_notification_recipients() -> List["User"]:
"""
Should query the users based on their notification settings
and the entity.
"""
pass
raise NotImplementedError("Subclasses must implement this method")

@classmethod
def make_notifications(cls, exec_date: "date"):
Expand All @@ -41,7 +39,6 @@ def make_notifications(cls, exec_date: "date"):
cls.make_notifications_for_user(day_offset, exec_date, user)

@classmethod
@abstractmethod
def make_notifications_for_user(
cls, day_offset: "timedelta", exec_date: "date", user: "User"
):
Expand All @@ -53,15 +50,14 @@ def make_notifications_for_user(
exec_date: The date of execution of the task.
user: The user to create the notification for.
"""
pass
raise NotImplementedError("Subclasses must implement this method")

@staticmethod
@abstractmethod
def notify(user: "User", obj: object, verb: "NotificationVerb"):
"""
Notify the user about the entity.
"""
pass
raise NotImplementedError("Subclasses must implement this method")

@staticmethod
def get_notification_setting(user: "User"):
Expand Down
Loading