Skip to content

Commit

Permalink
Allow filter by code
Browse files Browse the repository at this point in the history
  • Loading branch information
luisza committed May 4, 2024
1 parent 4f64f61 commit 453886a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/laboratory/static/laboratory/js/laboratory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
15 changes: 11 additions & 4 deletions src/laboratory/views/labroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand All @@ -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'],
Expand Down

0 comments on commit 453886a

Please sign in to comment.