2021-07-29 10:51:14 +02:00
|
|
|
"""
|
|
|
|
Author: Michel Peltriaux
|
|
|
|
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
|
|
|
|
Contact: michel.peltriaux@sgdnord.rlp.de
|
|
|
|
Created on: 29.07.21
|
|
|
|
|
|
|
|
"""
|
2021-08-10 13:12:15 +02:00
|
|
|
import django_filters
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from django import forms
|
2021-07-29 10:51:14 +02:00
|
|
|
from django.db.models import QuerySet
|
|
|
|
|
|
|
|
from intervention.filters import InterventionTableFilter
|
|
|
|
|
|
|
|
|
|
|
|
class CompensationTableFilter(InterventionTableFilter):
|
|
|
|
""" TableFilter for compensations
|
|
|
|
|
|
|
|
Based widely on InterventionTableFilter.
|
|
|
|
Just some minor changes for Compensation model.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2021-07-29 16:10:56 +02:00
|
|
|
def _filter_show_all(self, queryset, name, value) -> QuerySet:
|
|
|
|
""" Filters queryset depending on value of 'show_all' setting
|
|
|
|
|
|
|
|
Args:
|
|
|
|
queryset ():
|
|
|
|
name ():
|
|
|
|
value ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
if not value:
|
|
|
|
return queryset.filter(
|
|
|
|
intervention__users__in=[self.user], # requesting user has access
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return queryset
|
|
|
|
|
2021-07-29 10:51:14 +02:00
|
|
|
def _filter_show_recorded(self, queryset, name, value) -> QuerySet:
|
|
|
|
""" Filters queryset depending on value of 'show_recorded' setting
|
|
|
|
|
|
|
|
Args:
|
|
|
|
queryset ():
|
|
|
|
name ():
|
|
|
|
value ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
if not value:
|
|
|
|
return queryset.filter(
|
2021-07-29 15:49:19 +02:00
|
|
|
intervention__recorded=None,
|
2021-07-29 10:51:14 +02:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
return queryset
|
2021-08-09 14:16:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
class EcoAccountTableFilter(InterventionTableFilter):
|
|
|
|
""" TableFilter for eco accounts
|
|
|
|
|
|
|
|
Based widely on InterventionTableFilter.
|
|
|
|
Just some minor changes for EcoAccount model.
|
|
|
|
|
|
|
|
"""
|
2021-08-10 13:12:15 +02:00
|
|
|
sr = django_filters.BooleanFilter(
|
|
|
|
method='_filter_only_show_unrecorded',
|
|
|
|
label=_("Show only unrecorded"),
|
|
|
|
label_suffix=_(""),
|
|
|
|
widget=forms.CheckboxInput()
|
|
|
|
)
|
2021-08-09 14:16:54 +02:00
|
|
|
|
|
|
|
def _filter_show_all(self, queryset, name, value) -> QuerySet:
|
|
|
|
""" Filters queryset depending on value of 'show_all' setting
|
|
|
|
|
|
|
|
Args:
|
|
|
|
queryset ():
|
|
|
|
name ():
|
|
|
|
value ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
if not value:
|
|
|
|
return queryset.filter(
|
|
|
|
users__in=[self.user], # requesting user has access
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return queryset
|
|
|
|
|
2021-08-10 13:12:15 +02:00
|
|
|
def _filter_only_show_unrecorded(self, queryset, name, value) -> QuerySet:
|
2021-08-09 14:16:54 +02:00
|
|
|
""" Filters queryset depending on value of 'show_recorded' setting
|
|
|
|
|
|
|
|
Args:
|
|
|
|
queryset ():
|
|
|
|
name ():
|
|
|
|
value ():
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2021-08-10 13:12:15 +02:00
|
|
|
if value:
|
2021-08-09 14:16:54 +02:00
|
|
|
return queryset.filter(
|
|
|
|
recorded=None,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return queryset
|