Skip to content

Commit

Permalink
list objects manager first, use SiteModelAdminMixin, move DataManager…
Browse files Browse the repository at this point in the history
…SiteModelAdminMixin to modeladmin_mixins module
  • Loading branch information
erikvw committed Jul 10, 2023
1 parent 121f718 commit c250565
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 9 deletions.
4 changes: 2 additions & 2 deletions edc_data_manager/admin/autocomplete_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from edc_auth.admin import UserAdmin as BaseUserAdmin
from edc_lab.admin import PanelAdmin as BasePanelAdmin
from edc_model_admin.mixins import TemplatesModelAdminMixin
from edc_registration.admin import RegisteredSubjectAdmin as BaseRegisteredSubjectAdmin
from edc_sites.admin import SiteModelAdminMixin
from edc_visit_schedule.admin import VisitScheduleAdmin as BaseVisitScheduleAdmin

from ..admin_site import edc_data_manager_admin
Expand Down Expand Up @@ -40,7 +40,7 @@ class RequisitionDataDictionaryAdmin(TemplatesModelAdminMixin, admin.ModelAdmin)


@register(QuerySubject, site=edc_data_manager_admin)
class QuerySubjectAdmin(BaseRegisteredSubjectAdmin):
class QuerySubjectAdmin(SiteModelAdminMixin, admin.ModelAdmin):
ordering = ("subject_identifier",)
search_fields = ("subject_identifier",)

Expand Down
6 changes: 2 additions & 4 deletions edc_data_manager/admin/data_query_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@
from edc_dashboard.utils import get_bootstrap_version
from edc_model_admin.dashboard import ModelAdminSubjectDashboardMixin
from edc_model_admin.history import SimpleHistoryAdmin
from edc_sites.admin import SiteModelAdminMixin
from edc_utils import formatted_datetime

from ..admin_site import edc_data_manager_admin
from ..auth_objects import DATA_MANAGER
from ..constants import CLOSED_WITH_ACTION
from ..forms import DataQueryForm
from ..modeladmin_mixins import DataManagerSiteModelAdminMixin
from ..models import DataDictionary, DataQuery
from .actions import toggle_dm_status


@register(DataQuery, site=edc_data_manager_admin)
class DataQueryAdmin(
DataManagerSiteModelAdminMixin, ModelAdminSubjectDashboardMixin, SimpleHistoryAdmin
):
class DataQueryAdmin(SiteModelAdminMixin, ModelAdminSubjectDashboardMixin, SimpleHistoryAdmin):
status_column_template_name = (
f"edc_data_manager/bootstrap{get_bootstrap_version()}/columns/status.html"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Generated by Django 4.2.1 on 2023-07-05 02:16

from django.db import migrations
import django.db.models.manager
import edc_sites.model_mixins


class Migration(migrations.Migration):
dependencies = [
("edc_data_manager", "0027_alter_dataquery_dm_user"),
]

operations = [
migrations.AlterModelOptions(
name="dataquery",
options={
"default_manager_name": "objects",
"default_permissions": (
"add",
"change",
"delete",
"view",
"export",
"import",
),
"get_latest_by": "modified",
"ordering": ("-modified", "-created"),
"verbose_name": "Data Query",
"verbose_name_plural": "Data Queries",
},
),
migrations.AlterModelOptions(
name="queryrule",
options={
"default_manager_name": "objects",
"default_permissions": (
"add",
"change",
"delete",
"view",
"export",
"import",
),
"get_latest_by": "modified",
"ordering": ("title",),
"verbose_name": "Query Rule",
"verbose_name_plural": "Query Rules",
},
),
migrations.AlterModelManagers(
name="dataquery",
managers=[
("on_site", edc_sites.model_mixins.CurrentSiteManager()),
("objects", django.db.models.manager.Manager()),
],
),
]
24 changes: 24 additions & 0 deletions edc_data_manager/migrations/0029_alter_dataquery_managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.1 on 2023-07-07 19:32

from django.db import migrations
import django.db.models.manager
import edc_sites.model_mixins


class Migration(migrations.Migration):
dependencies = [
(
"edc_data_manager",
"0028_alter_dataquery_options_alter_queryrule_options_and_more",
),
]

operations = [
migrations.AlterModelManagers(
name="dataquery",
managers=[
("objects", django.db.models.manager.Manager()),
("on_site", edc_sites.model_mixins.CurrentSiteManager()),
],
),
]
8 changes: 7 additions & 1 deletion edc_data_manager/modeladmin_mixins.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from django.conf import settings
from django.contrib import messages
from django.contrib.admin import ModelAdmin
from django.contrib.messages import get_messages
from django.utils.html import format_html
from django.utils.safestring import mark_safe

from .auth_objects import DATA_MANAGER_ROLE

if TYPE_CHECKING:
from django.contrib.admin import ModelAdmin


class DataManagerSiteModelAdminMixin:
"""Do not declare together with `SiteModelAdminMixin`"""
Expand Down
4 changes: 2 additions & 2 deletions edc_data_manager/models/data_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ class DataQuery(DataQueryModelMixin, ActionModelMixin, SiteModelMixin, BaseUuidM
verbose_name="Query rule reference", max_length=150, null=True, default=uuid4
)

on_site = CurrentSiteManager()

objects = models.Manager()

on_site = CurrentSiteManager()

def __str__(self):
return f"{self.action_identifier[-9:]}, {self.status}"

Expand Down

0 comments on commit c250565

Please sign in to comment.