@@ -120,6 +120,21 @@ class _BAGObjectData(TypedDict):
120120 containers : list [_AfvalContainerData ]
121121
122122
123+ class _FilterChoice (TypedDict ):
124+ """A single choice in a filter group."""
125+
126+ value : str
127+ label : str
128+
129+
130+ class _FilterGroup (TypedDict ):
131+ """A group of filter choices."""
132+
133+ name : str
134+ label : str
135+ choices : list [_FilterChoice ]
136+
137+
123138def _format_container_for_table (
124139 ledigingen : list [_LedigingData ],
125140 totaal_gewicht : str ,
@@ -260,6 +275,89 @@ def _format_afval_profiel(profiel: AfvalProfiel) -> list[_BAGObjectData]:
260275 return result
261276
262277
278+ def _extract_filter_options (afval_data : list [_BAGObjectData ]) -> list [_FilterGroup ]:
279+ """
280+ Extract unique filter options from the formatted afval data.
281+
282+ Args:
283+ afval_data: List of formatted BAG object data
284+
285+ Returns:
286+ List of filter groups with their available choices
287+ """
288+ addresses : dict [str , str ] = {} # value: label
289+ container_types : dict [str , str ] = {} # value: label
290+ periods : dict [str , str ] = {} # year: year (as label)
291+
292+ # Extract unique values from the data
293+ for bag_obj in afval_data :
294+ # Extract address
295+ if bag_obj ["object_address" ]:
296+ addresses [bag_obj ["object_address" ]] = bag_obj ["object_address" ]
297+
298+ # Extract container types and periods
299+ for container in bag_obj ["containers" ]:
300+ # Container type
301+ container_type = container ["type" ]
302+ if container_type not in container_types :
303+ container_types [container_type ] = _get_container_type_label (
304+ container_type
305+ )
306+
307+ # Extract years from ledigingen dates
308+ for lediging in container ["ledigingen" ]:
309+ # Date format is "dd-mm-yyyy", extract year
310+ date_parts = lediging ["tijdstip_datum" ].split ("-" )
311+ if len (date_parts ) == 3 :
312+ year = date_parts [2 ]
313+ if year not in periods :
314+ periods [year ] = _ ("Jaar {year}" ).format (year = year )
315+
316+ # Build filter groups
317+ filter_groups : list [_FilterGroup ] = []
318+
319+ # Adres filter
320+ if addresses :
321+ filter_groups .append (
322+ {
323+ "name" : "adres" ,
324+ "label" : _ ("Adres" ),
325+ "choices" : [
326+ {"value" : value , "label" : label }
327+ for value , label in sorted (addresses .items ())
328+ ],
329+ }
330+ )
331+
332+ # Type container filter
333+ if container_types :
334+ filter_groups .append (
335+ {
336+ "name" : "type-container" ,
337+ "label" : _ ("Type container" ),
338+ "choices" : [
339+ {"value" : value , "label" : label }
340+ for value , label in sorted (container_types .items ())
341+ ],
342+ }
343+ )
344+
345+ # Periode filter (sorted by year descending)
346+ if periods :
347+ filter_groups .append (
348+ {
349+ "name" : "periode" ,
350+ "label" : _ ("Periode" ),
351+ "choices" : [
352+ {"value" : value , "label" : label }
353+ for value , label in sorted (periods .items (), reverse = True )
354+ ],
355+ }
356+ )
357+
358+ return filter_groups
359+
360+
263361class AfvalProfielView (
264362 LoginRequiredMixin , BaseBreadcrumbMixin , AppConfigMixin , TemplateView
265363):
@@ -305,7 +403,7 @@ def get_context_data(self, **kwargs):
305403 afval_config = MijnAfvalConfig .get_solo ()
306404
307405 if not (openafval_service := afval_config .openafval_service ):
308- messages .error (_ ("This module is not yet configured" ))
406+ messages .error (self . request , _ ("This module is not yet configured" ))
309407 return context
310408
311409 api_client = build_zgw_client (
@@ -320,11 +418,19 @@ def get_context_data(self, **kwargs):
320418 messages .error (
321419 self .request ,
322420 _ (
323- "We kunnen uw afvalgegevens momenteel niet ophalen. "
324- "Probeer het later opnieuw."
421+ "We kunnen uw afvalgegevens momenteel niet ophalen. Probeer het later opnieuw."
325422 ),
326423 )
327424 afval_data = []
328425
329- context ["afval_data" ] = afval_data
426+ # Extract filter options from the formatted data for the frontend filters
427+ filter_groups = _extract_filter_options (afval_data )
428+
429+ context .update (
430+ {
431+ "afval_data" : afval_data ,
432+ "filter_groups" : filter_groups ,
433+ }
434+ )
435+
330436 return context
0 commit comments