Skip to content

Commit

Permalink
refactor naming, update auth objects, add migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Aug 14, 2024
1 parent c0ae8c7 commit 9ffa23d
Show file tree
Hide file tree
Showing 20 changed files with 575 additions and 81 deletions.
15 changes: 6 additions & 9 deletions effect_auth/auth_objects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.apps import apps as django_apps
from edc_auth.get_app_codenames import get_app_codenames
from edc_qareports.utils import get_qareports_codenames

EFFECT_AUDITOR = "EFFECT_AUDITOR"
EFFECT_CLINIC = "EFFECT_CLINIC"
Expand All @@ -11,17 +11,14 @@
clinic_codenames = []
screening_codenames = []

reports_codenames = [c for c in get_app_codenames("effect_reports")]
reports_codenames = get_qareports_codenames(
"effect_reports", "effect_reports.serumcragdatenote"
)

for app_config in django_apps.get_app_configs():
if app_config.name in [
"effect_lists",
]:
if app_config.name in ["effect_lists"]:
for model_cls in app_config.get_models():
for prefix in ["view"]:
clinic_codenames.append(
f"{app_config.name}.{prefix}_{model_cls._meta.model_name}"
)
clinic_codenames.append(f"{app_config.name}.view_{model_cls._meta.model_name}")

for app_config in django_apps.get_app_configs():
if app_config.name in [
Expand Down
3 changes: 1 addition & 2 deletions effect_reports/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .confirmed_serum_crag_date_admin import ConfirmedSerumCragDateAdmin
from .consented_serum_crag_date_admin import ConsentedSerumCragDateAdmin
from .serum_crag_date_admin import SerumCragDateAdmin, SerumCragDateNoteAdmin
from .unmanaged import (
Rm792KwInCurrentSxGteG3OtherAdmin,
Rm792KwInCurrentSxOtherAdmin,
Expand Down
2 changes: 2 additions & 0 deletions effect_reports/admin/serum_crag_date_admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .serum_crag_date_admin import SerumCragDateAdmin
from .serum_crag_date_note_admin import SerumCragDateNoteAdmin
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from django.apps import apps as django_apps
from django.contrib import admin
from django.utils.html import format_html
from django.utils.translation import gettext as _
from edc_model_admin.dashboard import ModelAdminDashboardMixin
from edc_model_admin.mixins import TemplatesModelAdminMixin
from edc_qareports.modeladmin_mixins import QaReportModelAdminMixin
from edc_qareports.utils import truncate_string
from edc_sites.admin import SiteModelAdminMixin
from edc_utils import escape_braces

from ..admin_site import effect_reports_admin
from ..consented_serum_crag_date_df import ConsentedSerumCragDateDf
from ..models import ConsentedSerumCragDate
from ...admin_site import effect_reports_admin
from ...dataframes import SerumCragDateDf
from ...models import SerumCragDate


@admin.register(ConsentedSerumCragDate, site=effect_reports_admin)
class ConsentedSerumCragDateAdmin(
@admin.register(SerumCragDate, site=effect_reports_admin)
class SerumCragDateAdmin(
QaReportModelAdminMixin,
SiteModelAdminMixin,
ModelAdminDashboardMixin,
Expand All @@ -23,7 +23,7 @@ class ConsentedSerumCragDateAdmin(
):
qa_report_list_display_insert_pos = 5

note_model_cls = django_apps.get_model("effect_reports.confirmedserumcragdate")
note_model = "effect_reports.serumcragdatenote"

ordering = ("subject_identifier",)
list_display = [
Expand Down Expand Up @@ -56,16 +56,16 @@ def screening(self, obj=None):
def subject(self, obj=None):
return obj.subject_identifier

@admin.display(description="Conf. ser CrAg Date")
@admin.display(description="Confirm")
def notes(self, obj=None):
"""Returns url to add or edit qa_report model note"""
"""Overridden to change description"""
return super().notes(obj=obj)

def get_notes_label(self, obj=None, field_name=None):
if not obj:
label = "Add"
label = _("Add")
else:
date = obj.confirmed_serum_crag_date
date = obj.serum_crag_date
note = obj.note
if date and not note:
label = date
Expand All @@ -77,10 +77,10 @@ def get_notes_label(self, obj=None, field_name=None):
elif note:
label = truncate_string(note, max_length=35)
else:
label = "Edit"
label = _("Edit")
return label

def get_queryset(self, request):
cls = ConsentedSerumCragDateDf()
cls.to_model()
df_cls = SerumCragDateDf()
df_cls.to_model()
return super().get_queryset(request)
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
)
from edc_sites.admin import SiteModelAdminMixin

from ..admin_site import effect_reports_admin
from ..forms import ConfirmedSerumCragDateForm
from ..models import ConfirmedSerumCragDate
from ...admin_site import effect_reports_admin
from ...forms import SerumCragDateNoteForm
from ...models import SerumCragDateNote


@admin.register(ConfirmedSerumCragDate, site=effect_reports_admin)
class ConfirmedSerumCragDateAdmin(
@admin.register(SerumCragDateNote, site=effect_reports_admin)
class SerumCragDateNoteAdmin(
SiteModelAdminMixin,
ModelAdminDashboardMixin,
ModelAdminAuditFieldsMixin,
Expand All @@ -33,25 +33,32 @@ class ConfirmedSerumCragDateAdmin(
admin.ModelAdmin,
):

form = ConfirmedSerumCragDateForm
form = SerumCragDateNoteForm
ordering = ["site", "subject_identifier"]

note_template_name = "edc_qareports/qa_report_note.html"

fieldsets = (
(
None,
{
"fields": (
"subject_identifier",
"report_datetime",
"report_model",
)
},
),
(
"Screening Serum CrAg Date",
{"fields": ("confirmed_serum_crag_date",)},
{"fields": ("serum_crag_date",)},
),
(
"Notes",
{
"fields": (
"note",
"status",
"subject_identifier",
"report_model",
"report_datetime",
"note",
)
},
),
Expand All @@ -63,15 +70,15 @@ class ConfirmedSerumCragDateAdmin(
"subject_identifier",
"report",
"status",
"confirmed_serum_crag_date",
"serum_crag_date",
"report_note",
"report_datetime",
]

radio_fields = {"status": admin.VERTICAL}

list_filter = [
"confirmed_serum_crag_date",
"serum_crag_date",
"status",
"report_datetime",
"report_model",
Expand Down
1 change: 1 addition & 0 deletions effect_reports/dataframes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .serum_crag_date_df import SerumCragDateDf
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
from edc_utils import get_utcnow

if TYPE_CHECKING:
from effect_reports.models import ConsentedSerumCragDate
from effect_reports.models import SerumCragDate


class ConsentedSerumCragDateDf:
class SerumCragDateDf:
"""A dataframe that lists serum_crag_date for every consented
subject.
model = "effect_reports.consentedserumcragdate"
See `SerumCragDateAdmin` admin class get_queryset.
"""

model = "effect_reports.serumcragdate"

def __init__(self):
self.subject_screening_model_cls = django_apps.get_model(
Expand Down Expand Up @@ -45,7 +50,7 @@ def to_dataframe(self) -> pd.DataFrame:
df["report_model"] = self.model
return df

def to_model(self) -> ConsentedSerumCragDate:
def to_model(self) -> SerumCragDate:
self.model_cls.objects.all().delete()

df = self.to_dataframe()
Expand Down
2 changes: 1 addition & 1 deletion effect_reports/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .confirmed_serum_crag_date_form import ConfirmedSerumCragDateForm
from .serum_crag_date_note_form import SerumCragDateNoteForm
4 changes: 2 additions & 2 deletions effect_reports/forms/serum_crag_date_note_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from edc_sites.modelform_mixins import SiteModelFormMixin
from effect_form_validators.effect_reports import SerumCragDateNoteFormValidator

from ..models import ConfirmedSerumCragDate
from ..models import SerumCragDateNote


class SerumCragDateNoteForm(
Expand All @@ -18,7 +18,7 @@ class SerumCragDateNoteForm(
form_validator_cls = SerumCragDateNoteFormValidator

class Meta:
model = ConfirmedSerumCragDate
model = SerumCragDateNote
fields = "__all__"
help_text = {"subject_identifier": "(read-only)", "name": "(read-only)"}
widgets = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Migration(migrations.Migration):
),
),
(
"confirmed_serum_crag_date",
"serum_crag_date",
models.DateField(
blank=True,
help_text="Please enter first collection date in episode. Test must have been performed within 21 days of screening.",
Expand Down Expand Up @@ -346,7 +346,7 @@ class Migration(migrations.Migration):
),
),
(
"confirmed_serum_crag_date",
"serum_crag_date",
models.DateField(
blank=True,
help_text="Please enter first collection date in episode. Test must have been performed within 21 days of screening.",
Expand Down
Loading

0 comments on commit 9ffa23d

Please sign in to comment.