Skip to content

Commit

Permalink
Merge branch 'release/0.3.78' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jun 10, 2024
2 parents 1af8108 + 5e79676 commit 24f0234
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
66 changes: 61 additions & 5 deletions edc_data_manager/admin/data_dictionary_admin.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
from django.conf import settings
from django.contrib import admin
from django.contrib.admin import sites
from django.contrib.admin.decorators import register
from django.contrib.auth import get_permission_codename
from django.urls import NoReverseMatch, reverse
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django_audit_fields.admin import audit_fieldset_tuple
from django_audit_fields.admin import ModelAdminAuditFieldsMixin, audit_fieldset_tuple
from django_revision.modeladmin_mixin import ModelAdminRevisionMixin
from edc_list_data.model_mixins import ListModelMixin
from edc_model_admin.dashboard import ModelAdminSubjectDashboardMixin
from edc_model_admin.history import SimpleHistoryAdmin
from edc_model_admin.mixins import (
ModelAdminFormInstructionsMixin,
ModelAdminInstitutionMixin,
ModelAdminNextUrlRedirectMixin,
ModelAdminRedirectOnDeleteMixin,
ModelAdminReplaceLabelTextMixin,
TemplatesModelAdminMixin,
)
from edc_notification.modeladmin_mixins import NotificationModelAdminMixin

from ..admin_site import edc_data_manager_admin
from ..forms import DataDictionaryForm
from ..models import DataDictionary
from ..populate_data_dictionary import populate_data_dictionary


@register(DataDictionary, site=edc_data_manager_admin)
class DataDictionaryAdmin(ModelAdminSubjectDashboardMixin, SimpleHistoryAdmin):
@admin.register(DataDictionary, site=edc_data_manager_admin)
class DataDictionaryAdmin(
TemplatesModelAdminMixin,
ModelAdminNextUrlRedirectMixin, # add
NotificationModelAdminMixin,
ModelAdminFormInstructionsMixin, # add
ModelAdminRevisionMixin, # add
ModelAdminInstitutionMixin, # add
ModelAdminRedirectOnDeleteMixin,
ModelAdminReplaceLabelTextMixin,
ModelAdminAuditFieldsMixin,
SimpleHistoryAdmin,
):

form = DataDictionaryForm

fieldsets = (
[
None,
Expand Down Expand Up @@ -47,6 +72,7 @@ class DataDictionaryAdmin(ModelAdminSubjectDashboardMixin, SimpleHistoryAdmin):
list_display = (
"form_title",
"field_name",
"changelist_link",
"active",
"number",
"question_text",
Expand All @@ -70,6 +96,36 @@ class DataDictionaryAdmin(ModelAdminSubjectDashboardMixin, SimpleHistoryAdmin):
"model_verbose_name",
)

readonly_fields = [
"model",
"model_verbose_name",
"number",
"prompt",
"field_name",
"field_type",
"help_text",
"default_value",
"nullable",
"max_length",
"max_digits",
"decimal_places",
"active",
]

@admin.display(description="Changelist")
def changelist_link(self, obj):
for site in sites.all_sites.data:
for modeladmin in site()._registry.values():
if modeladmin.model._meta.label_lower == obj.model:
model_string = obj.model.replace(".", "_")
try:
url = reverse(f"{site().name}:{model_string}_changelist")
except NoReverseMatch:
pass
else:
return format_html(f'<a href="{url}">Changelist</a>')
return None

@staticmethod
def form_title(obj):
return obj.model_verbose_name
Expand Down
1 change: 1 addition & 0 deletions edc_data_manager/forms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .data_dictionary import DataDictionaryForm
from .data_query import DataQueryForm
from .query_rule import QueryRuleForm
11 changes: 11 additions & 0 deletions edc_data_manager/forms/data_dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django import forms
from edc_action_item.forms.action_item_form_mixin import ActionItemFormMixin

from ..models import DataDictionary


class DataDictionaryForm(ActionItemFormMixin, forms.ModelForm):

class Meta:
model = DataDictionary
fields = "__all__"

0 comments on commit 24f0234

Please sign in to comment.