Skip to content

Commit

Permalink
Merge branch 'release/0.3.14' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Nov 26, 2024
2 parents 04f457c + 7527d19 commit aac971f
Show file tree
Hide file tree
Showing 32 changed files with 298 additions and 386 deletions.
6 changes: 5 additions & 1 deletion edc_pharmacy/admin/remove_fields_for_blinded_users.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from django.core.handlers.wsgi import WSGIRequest
from edc_randomization.blinding import user_is_blinded_from_request

from .list_filters import AssignmentListFilter


def remove_fields_for_blinded_users(request: WSGIRequest, fields: tuple) -> tuple:
"""You need to secure custom SimpleListFilters yourself"""
if user_is_blinded_from_request(request):
fields = list(fields)
for f in fields:
if isinstance(f, str):
if "assignment" in f or "lot_no" in f:
if "assignment" in f or "lot_no" in f or "lot" in f:
fields.remove(f)
elif issubclass(f, AssignmentListFilter):
fields.remove(f)
fields = tuple(fields)
return fields
20 changes: 19 additions & 1 deletion edc_pharmacy/admin/stock/allocation_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
from django.urls import NoReverseMatch, reverse
from django.utils.translation import gettext
from django_audit_fields import audit_fieldset_tuple
from edc_model_admin.history import SimpleHistoryAdmin
from edc_utils.date import to_local

from ...admin_site import edc_pharmacy_admin
from ...models import Allocation
from ..list_filters import AssignmentListFilter, TransferredFilter
from ..model_admin_mixin import ModelAdminMixin
from ..remove_fields_for_blinded_users import remove_fields_for_blinded_users


@admin.register(Allocation, site=edc_pharmacy_admin)
class AllocationAdmin(ModelAdminMixin, admin.ModelAdmin):
class AllocationAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Allocations"
change_form_title = "Pharmacy: Allocation"
history_list_display = ()
show_object_tools = True
show_cancel = True
list_per_page = 20
Expand Down Expand Up @@ -70,6 +73,21 @@ class AllocationAdmin(ModelAdminMixin, admin.ModelAdmin):
"allocated_by",
)

def get_list_display(self, request):
fields = super().get_list_display(request)
fields = remove_fields_for_blinded_users(request, fields)
return fields

def get_list_filter(self, request):
fields = super().get_list_filter(request)
fields = remove_fields_for_blinded_users(request, fields)
return fields

def get_search_fields(self, request):
fields = super().get_search_fields(request)
fields = remove_fields_for_blinded_users(request, fields)
return fields

@admin.display(description="ALLOCATION #", ordering="allocation_identifier")
def identifier(self, obj):
return obj.allocation_identifier.split("-")[0]
Expand Down
4 changes: 3 additions & 1 deletion edc_pharmacy/admin/stock/container_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin
from django_audit_fields.admin import audit_fieldset_tuple
from edc_model_admin.history import SimpleHistoryAdmin

from ...admin_site import edc_pharmacy_admin
from ...forms import ContainerForm
Expand All @@ -9,9 +10,10 @@


@admin.register(Container, site=edc_pharmacy_admin)
class ContainerAdmin(ModelAdminMixin, admin.ModelAdmin):
class ContainerAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Containers"
show_object_tools = True
history_list_display = ()
list_per_page = 20

form = ContainerForm
Expand Down
4 changes: 3 additions & 1 deletion edc_pharmacy/admin/stock/dispense_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.template.loader import render_to_string
from django.urls import reverse
from django_audit_fields.admin import audit_fieldset_tuple
from edc_model_admin.history import SimpleHistoryAdmin
from edc_utils.date import to_local

from ...admin_site import edc_pharmacy_admin
Expand All @@ -11,9 +12,10 @@


@admin.register(Dispense, site=edc_pharmacy_admin)
class DispenseAdmin(ModelAdminMixin, admin.ModelAdmin):
class DispenseAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Dispense"
change_form_title = "Pharmacy: Dispense"
history_list_display = ()
show_object_tools = True
show_cancel = True
list_per_page = 20
Expand Down
4 changes: 3 additions & 1 deletion edc_pharmacy/admin/stock/dispense_item_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.template.loader import render_to_string
from django.urls import reverse
from django_audit_fields.admin import audit_fieldset_tuple
from edc_model_admin.history import SimpleHistoryAdmin
from edc_utils.date import to_local

from ...admin_site import edc_pharmacy_admin
Expand All @@ -10,9 +11,10 @@


@admin.register(DispenseItem, site=edc_pharmacy_admin)
class DispenseItemAdmin(ModelAdminMixin, admin.ModelAdmin):
class DispenseItemAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Dispense items"
change_form_title = "Pharmacy: Dispense item"
history_list_display = ()
show_object_tools = True
show_cancel = True
list_per_page = 20
Expand Down
4 changes: 3 additions & 1 deletion edc_pharmacy/admin/stock/location_admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib import admin
from edc_model_admin.history import SimpleHistoryAdmin

from ...admin_site import edc_pharmacy_admin
from ...forms import LocationForm
Expand All @@ -7,7 +8,8 @@


@admin.register(Location, site=edc_pharmacy_admin)
class LocationAdmin(ModelAdminMixin, admin.ModelAdmin):
class LocationAdmin(ModelAdminMixin, SimpleHistoryAdmin):
history_list_display = ()
show_cancel = True
ordering = ("name",)
list_per_page = 20
Expand Down
8 changes: 5 additions & 3 deletions edc_pharmacy/admin/stock/lot_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib import admin
from django_audit_fields.admin import audit_fieldset_tuple
from edc_model_admin.history import SimpleHistoryAdmin
from edc_randomization.blinding import user_is_blinded_from_request

from ...admin_site import edc_pharmacy_admin
Expand All @@ -12,9 +13,10 @@


@admin.register(Lot, site=edc_pharmacy_admin)
class LotAdmin(ModelAdminMixin, admin.ModelAdmin):
change_list_title = "Pharmacy: Lots"
change_form_title = "Pharmacy: Lot"
class LotAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Batches"
change_form_title = "Pharmacy: Batch"
history_list_display = ()
show_object_tools = True
show_cancel = True
list_per_page = 20
Expand Down
28 changes: 4 additions & 24 deletions edc_pharmacy/admin/stock/order_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,20 @@
from django.urls import reverse
from django.utils.html import format_html
from django_audit_fields.admin import audit_fieldset_tuple
from edc_model_admin.mixins import TabularInlineMixin
from edc_model_admin.history import SimpleHistoryAdmin
from edc_utils.date import to_local

from ...admin_site import edc_pharmacy_admin
from ...forms import OrderForm, OrderItemForm
from ...forms import OrderForm
from ...models import Order, OrderItem, Receive
from ..model_admin_mixin import ModelAdminMixin


class OrderItemInlineAdmin(TabularInlineMixin, admin.TabularInline):
model = OrderItem
form = OrderItemForm
extra = 1

fieldsets = (
(
None,
{
"fields": (
[
"product",
"container",
"qty",
]
)
},
),
)


@admin.register(Order, site=edc_pharmacy_admin)
class OrderAdmin(ModelAdminMixin, admin.ModelAdmin):
class OrderAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Orders"
change_form_title = "Pharmacy: Order"
history_list_display = ()
show_object_tools = True
show_cancel = True
list_per_page = 20
Expand Down
4 changes: 3 additions & 1 deletion edc_pharmacy/admin/stock/order_item_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils.translation import gettext as _
from django_audit_fields.admin import audit_fieldset_tuple
from edc_constants.constants import NEW, PARTIAL, RECEIVED
from edc_model_admin.history import SimpleHistoryAdmin
from edc_utils import message_in_queue

from ...admin_site import edc_pharmacy_admin
Expand All @@ -20,8 +21,9 @@


@admin.register(OrderItem, site=edc_pharmacy_admin)
class OrderItemAdmin(ModelAdminMixin, admin.ModelAdmin):
class OrderItemAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Ordered items"
history_list_display = ()
show_object_tools = False
show_cancel = True
list_per_page = 20
Expand Down
20 changes: 19 additions & 1 deletion edc_pharmacy/admin/stock/product_admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
from django.contrib import admin
from django_audit_fields.admin import audit_fieldset_tuple
from edc_model_admin.history import SimpleHistoryAdmin

from ...admin_site import edc_pharmacy_admin
from ...forms import ProductForm
from ...models import Product
from ..model_admin_mixin import ModelAdminMixin
from ..remove_fields_for_blinded_users import remove_fields_for_blinded_users


@admin.register(Product, site=edc_pharmacy_admin)
class ProductAdmin(ModelAdminMixin, admin.ModelAdmin):
class ProductAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Products"
history_list_display = ()
show_object_tools = True
show_cancel = True
list_per_page = 20
Expand Down Expand Up @@ -61,3 +64,18 @@ def get_readonly_fields(self, request, obj=None):
if obj:
return self.readonly_fields + ("formulation", "assignment")
return self.readonly_fields

def get_list_display(self, request):
fields = super().get_list_display(request)
fields = remove_fields_for_blinded_users(request, fields)
return fields

def get_list_filter(self, request):
fields = super().get_list_filter(request)
fields = remove_fields_for_blinded_users(request, fields)
return fields

def get_search_fields(self, request):
fields = super().get_search_fields(request)
fields = remove_fields_for_blinded_users(request, fields)
return fields
31 changes: 5 additions & 26 deletions edc_pharmacy/admin/stock/receive_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,21 @@
from django.template.loader import render_to_string
from django.urls import reverse
from django_audit_fields.admin import audit_fieldset_tuple
from edc_model_admin.mixins import TabularInlineMixin
from edc_model_admin.history import SimpleHistoryAdmin
from edc_utils.date import to_local

from ...admin_site import edc_pharmacy_admin
from ...forms import ReceiveForm, ReceiveItemForm
from ...models import Receive, ReceiveItem
from ...forms import ReceiveForm
from ...models import Receive
from ..actions import confirm_received_stock_action, print_labels_from_receive
from ..model_admin_mixin import ModelAdminMixin


class ReceiveItemInlineAdmin(TabularInlineMixin, admin.TabularInline):
model = ReceiveItem
form = ReceiveItemForm
extra = 1

fieldsets = (
(
None,
{
"fields": (
[
"receive_item_datetime",
"order_item",
"container",
"unit_qty",
]
)
},
),
)


@admin.register(Receive, site=edc_pharmacy_admin)
class ReceiveAdmin(ModelAdminMixin, admin.ModelAdmin):
class ReceiveAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Receiving"
change_form_title = "Pharmacy: Receive"
history_list_display = ()

show_object_tools = False
show_cancel = True
Expand Down
4 changes: 3 additions & 1 deletion edc_pharmacy/admin/stock/receive_item_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.template.loader import render_to_string
from django.urls import reverse
from django_audit_fields.admin import audit_fieldset_tuple
from edc_model_admin.history import SimpleHistoryAdmin
from edc_utils.date import to_local

from ...admin_site import edc_pharmacy_admin
Expand All @@ -13,9 +14,10 @@


@admin.register(ReceiveItem, site=edc_pharmacy_admin)
class ReceiveItemAdmin(ModelAdminMixin, admin.ModelAdmin):
class ReceiveItemAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Received items"
change_form_title = "Pharmacy: Receive item"
history_list_display = ()
show_object_tools = False
show_cancel = True
list_per_page = 20
Expand Down
20 changes: 19 additions & 1 deletion edc_pharmacy/admin/stock/repack_request_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.template.loader import render_to_string
from django.urls import reverse
from django_audit_fields import audit_fieldset_tuple
from edc_model_admin.history import SimpleHistoryAdmin
from edc_utils.celery import get_task_result
from edc_utils.date import to_local

Expand All @@ -19,12 +20,14 @@
process_repack_request_action,
)
from ..model_admin_mixin import ModelAdminMixin
from ..remove_fields_for_blinded_users import remove_fields_for_blinded_users


@admin.register(RepackRequest, site=edc_pharmacy_admin)
class RequestRepackAdmin(ModelAdminMixin, admin.ModelAdmin):
class RequestRepackAdmin(ModelAdminMixin, SimpleHistoryAdmin):
change_list_title = "Pharmacy: Repack/Decant request"
change_form_title = "Pharmacy: Repack/Decant"
history_list_display = ()

show_object_tools = True
show_cancel = True
Expand Down Expand Up @@ -85,6 +88,21 @@ class RequestRepackAdmin(ModelAdminMixin, admin.ModelAdmin):

readonly_fields = ("processed_qty", "task_id")

def get_list_display(self, request):
fields = super().get_list_display(request)
fields = remove_fields_for_blinded_users(request, fields)
return fields

def get_list_filter(self, request):
fields = super().get_list_filter(request)
fields = remove_fields_for_blinded_users(request, fields)
return fields

def get_search_fields(self, request):
fields = super().get_search_fields(request)
fields = remove_fields_for_blinded_users(request, fields)
return fields

@admin.display(description="Repack date", ordering="repack_datetime")
def repack_date(self, obj):
return to_local(obj.repack_datetime).date()
Expand Down
Loading

0 comments on commit aac971f

Please sign in to comment.