Skip to content
Snippets Groups Projects
Commit 75c7b6af authored by Klaas Kliffen's avatar Klaas Kliffen :satellite:
Browse files

Storing filters works

parent 99af007b
No related branches found
No related tags found
1 merge request!104Propagate extra fields form group into WorkSpecifications
......@@ -180,10 +180,16 @@
data-filter="{{ filter.lookup_type }}"
style="width: 12rem">
{#for some reason, styling is not applied otherwise#}
<option selected value="">All</option>
{% if filter.default == "" %}
<option selected value="">All</option>
{% else %}
<option value="">All</option>
{% endif%}
{% for option in filter.choices %}
{% if filter.default == option.0 %}
<option value="{{ option.0 }}">{{ option.0 }}</option>
<option selected value="{{ option.0 }}">{{ option.0 }}</option>
{% else %}
<option value="{{ option.0 }}">{{ option.0 }}</option>
{% endif %}
......
from typing import Union
from typing import List, Optional, Union
from lofardata.models import DataFilterType, DataProductFilter, Group, WorkSpecification
from lofardata.view_helpers.dataproductinfo import get_distinct_dataproduct_field
def preprocess(filterable: Union[WorkSpecification, Group]):
dataproduct_filters = DataProductFilter.objects.all()
def preprocess(
filterable: Union[WorkSpecification, Group], show: Optional[List[str]] = None
):
"""Preprocess available dataproduct filters and pre-fill them if the filterable
objects already contains a value for the filter field
filterable: A WorkSpecification or Group to pre-fill the filter fields
show: which fields to show (or all if None)
"""
if show is None:
dataproduct_filters = DataProductFilter.objects.all()
else:
dataproduct_filters = DataProductFilter.objects.filter(field__in=show)
for dataproduct_filter in dataproduct_filters:
if (
filterable is not None
......@@ -22,4 +35,5 @@ def preprocess(filterable: Union[WorkSpecification, Group]):
)
dataproduct_filter.choices = [(field,) for field in distinct_filter_fields]
return dataproduct_filters
......@@ -32,10 +32,12 @@ class GroupCreateUpdateView(LoginRequiredMixin, UpdateView):
except ObjectDoesNotExist:
group = None
# FIXME: remove SAS ID from filters
context["filters"] = filters_preprocessor.preprocess(group)
context["processing_sites"] = processing_sites
context["single_processing_site"] = processing_sites[0]['name'] if len(processing_sites) == 1 else None
# Excludes obs_id, since groups handle these differently
context["filters"] = filters_preprocessor.preprocess(
group, show=["dataproduct_type", "activity", "project", "location"]
)
return context
def form_valid(self, form):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment