-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ConfirmedSerumCragDate (note) model, refactor effect_reports to use
NoteModel(Admin)Mixin, fix SQL defined report_models, fix imports for refactored QaReportModelMixin
- Loading branch information
1 parent
59247e0
commit 600afcf
Showing
14 changed files
with
605 additions
and
18 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
effect_reports/admin/confirmed_serum_crag_date_admin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from django.contrib import admin | ||
from django.template.loader import render_to_string | ||
from django.urls import NoReverseMatch, reverse | ||
from django.utils.html import format_html | ||
from django_audit_fields import ModelAdminAuditFieldsMixin, audit_fieldset_tuple | ||
from django_revision.modeladmin_mixin import ModelAdminRevisionMixin | ||
from edc_model_admin.dashboard import ModelAdminDashboardMixin | ||
from edc_model_admin.mixins import ( | ||
ModelAdminFormAutoNumberMixin, | ||
ModelAdminFormInstructionsMixin, | ||
ModelAdminInstitutionMixin, | ||
ModelAdminNextUrlRedirectMixin, | ||
TemplatesModelAdminMixin, | ||
) | ||
from edc_sites.admin import SiteModelAdminMixin | ||
|
||
from ..admin_site import effect_reports_admin | ||
from ..forms import ConfirmedSerumCragDateForm | ||
from ..models import ConfirmedSerumCragDate | ||
|
||
|
||
@admin.register(ConfirmedSerumCragDate, site=effect_reports_admin) | ||
class ConfirmedSerumCragDateAdmin( | ||
SiteModelAdminMixin, | ||
ModelAdminDashboardMixin, | ||
ModelAdminAuditFieldsMixin, | ||
ModelAdminFormAutoNumberMixin, | ||
ModelAdminFormInstructionsMixin, | ||
ModelAdminRevisionMixin, # add | ||
ModelAdminInstitutionMixin, # add | ||
ModelAdminNextUrlRedirectMixin, | ||
TemplatesModelAdminMixin, | ||
admin.ModelAdmin, | ||
): | ||
|
||
form = ConfirmedSerumCragDateForm | ||
ordering = ["site", "subject_identifier"] | ||
|
||
note_template_name = "edc_qareports/qa_report_note.html" | ||
|
||
fieldsets = ( | ||
( | ||
"Screening Serum CrAg Date", | ||
{"fields": ("confirmed_serum_crag_date",)}, | ||
), | ||
( | ||
"Notes", | ||
{ | ||
"fields": ( | ||
"note", | ||
"status", | ||
"subject_identifier", | ||
"report_model", | ||
"report_datetime", | ||
) | ||
}, | ||
), | ||
audit_fieldset_tuple, | ||
) | ||
|
||
list_display = [ | ||
"dashboard", | ||
"subject_identifier", | ||
"report", | ||
"status", | ||
"confirmed_serum_crag_date", | ||
"report_note", | ||
"report_datetime", | ||
] | ||
|
||
radio_fields = {"status": admin.VERTICAL} | ||
|
||
list_filter = [ | ||
"confirmed_serum_crag_date", | ||
"status", | ||
"report_datetime", | ||
"report_model", | ||
"user_created", | ||
"user_modified", | ||
] | ||
|
||
search_fields = ["subject_identifier", "name"] | ||
|
||
@admin.display(description="Report", ordering="report_name") | ||
def report(self, obj=None): | ||
app_label, model = obj.report_model_cls._meta.label_lower.split(".") | ||
changelist_url = "_".join([app_label, model, "changelist"]) | ||
try: | ||
# assume admin site naming convention | ||
url = reverse(f"{app_label}_admin:{changelist_url}") | ||
except NoReverseMatch: | ||
# TODO: find the admin site where this model is registered | ||
url = "#" | ||
return format_html( | ||
'<a data-toggle="tooltip" title="go to report" href="{}?q={}">{}</a>', | ||
*(url, obj.subject_identifier, obj.report_model_cls._meta.verbose_name), | ||
) | ||
|
||
@admin.display(description="QA Note", ordering="note") | ||
def report_note(self, obj=None): | ||
context = dict(note=obj.note) | ||
return render_to_string(self.note_template_name, context) | ||
|
||
def redirect_url(self, request, obj, post_url_continue=None) -> str | None: | ||
redirect_url = super().redirect_url(request, obj, post_url_continue=post_url_continue) | ||
return f"{redirect_url}?q={obj.subject_identifier}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .confirmed_serum_crag_date_form import ConfirmedSerumCragDateForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django import forms | ||
from edc_form_validators import FormValidatorMixin | ||
from edc_model_form.mixins import BaseModelFormMixin | ||
from edc_sites.modelform_mixins import SiteModelFormMixin | ||
from effect_form_validators.effect_reports import ConfirmedSerumCragDateFormValidator | ||
|
||
from ..models import ConfirmedSerumCragDate | ||
|
||
|
||
class ConfirmedSerumCragDateForm( | ||
SiteModelFormMixin, | ||
BaseModelFormMixin, | ||
FormValidatorMixin, | ||
forms.ModelForm, | ||
): | ||
|
||
report_datetime_field_attr = "report_datetime" | ||
form_validator_cls = ConfirmedSerumCragDateFormValidator | ||
|
||
class Meta: | ||
model = ConfirmedSerumCragDate | ||
fields = "__all__" | ||
help_text = {"subject_identifier": "(read-only)", "name": "(read-only)"} | ||
widgets = { | ||
"report_model": forms.TextInput(attrs={"readonly": "readonly"}), | ||
"subject_identifier": forms.TextInput(attrs={"readonly": "readonly"}), | ||
"name": forms.TextInput(attrs={"readonly": "readonly"}), | ||
} |
Oops, something went wrong.