From 453886a94d81746aeb80095ba77292e408e26b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Z=C3=A1rate=20Montero?= Date: Fri, 3 May 2024 23:26:16 -0600 Subject: [PATCH] Allow filter by code --- src/laboratory/static/laboratory/js/laboratory.js | 7 +++++-- src/laboratory/views/labroom.py | 15 +++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/laboratory/static/laboratory/js/laboratory.js b/src/laboratory/static/laboratory/js/laboratory.js index 4a1f7e5c9..d2fbc10cb 100644 --- a/src/laboratory/static/laboratory/js/laboratory.js +++ b/src/laboratory/static/laboratory/js/laboratory.js @@ -322,8 +322,11 @@ $(document).ready(function(){ addfilter=false); //shelfselected - $('input[name="shelfselected"]').change(function(){ - datatableelement.ajax.reload(); + $('input[name="shelfselected"]').change(function(event){ + if(event.currentTarget.checked ){ + datatableelement.ajax.reload(); + } + }); $('#shelfobjecttable').on( 'init.dt', function () { diff --git a/src/laboratory/views/labroom.py b/src/laboratory/views/labroom.py index 6c2c5ded2..8ed97a7bd 100644 --- a/src/laboratory/views/labroom.py +++ b/src/laboratory/views/labroom.py @@ -33,6 +33,8 @@ from ..shelfobject.serializers import SearchShelfObjectSerializer from ..utils import organilab_logentry, check_user_access_kwargs_org_lab +def display_shelfobject(data, name): + return "%s %s"%(data['object__code'],data[name]) @method_decorator(permission_required('laboratory.view_laboratoryroom'), name='dispatch') @@ -108,17 +110,20 @@ def get_obj_colors(self): } - def get_whitelist_by_object(self, model, filters, color, value='name'): + def get_whitelist_by_object(self, model, filters, color, value='name', + filter_values=None, display_fnc=lambda x,y: x[y]): suggestions_tag = [] contenttype = ContentType.objects.filter( app_label='laboratory', model=model ).first() + if filter_values is None: + filter_values=['pk', value] MODEL = contenttype.model_class() - queryset = MODEL.objects.filter(**filters).values('pk', value).distinct() + queryset = MODEL.objects.filter(**filters).values(*filter_values).distinct() whitelist = [ - {'pk': x['pk'], 'value': "%d: %s" % (x['pk'], x[value]), 'objtype': model, 'color': color} + {'pk': x['pk'], 'value': "%d: %s" % (x['pk'], display_fnc(x,value)), 'objtype': model, 'color': color} for x in queryset] if whitelist: @@ -132,7 +137,9 @@ def get_suggestions_tag(self): suggestions_tag += self.get_whitelist_by_object('shelf', {'furniture__labroom__laboratory': self.lab}, color_by_obj['shelf']) suggestions_tag += self.get_whitelist_by_object('shelfobject', {'in_where_laboratory': self.lab, 'containershelfobject': None}, - color_by_obj['shelfobject'], value='object__name') + color_by_obj['shelfobject'], + filter_values=['pk', 'object__name', 'object__code'], + value='object__name', display_fnc=display_shelfobject) suggestions_tag += self.get_whitelist_by_object('object', {'shelfobject__in_where_laboratory': self.lab, 'shelfobject__containershelfobject': None}, color_by_obj['object'],