konova/compensation/filters.py
mipel 07a428d0e5 HTML improvements
* refactors initializing and rendering of a map view into map/geom_form.html, which leads to simple includes on the detail views instead of redundant html
* refactors django-autocomplete-light form media links and scripts into dal/scripts.html, which can be included on the header blocks of detail views to support form modals using dal easier without the need for form.media
* changes filter behaviour on eco account index: instead of hiding recorded accounts (like in interventions), the filter option there has been replaced with "Show only unrecorded" which can be used to hide all recorded ones
   * background: eco accounts shall be visible when recorded, since they can only be used for withdrawing if they are recorded. Hiding the recorded ones does not make any sense, just like in interventions
* updates some code documentation
* adds/updates translations
2021-08-10 13:12:15 +02:00

110 lines
2.6 KiB
Python

"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 29.07.21
"""
import django_filters
from django.utils.translation import gettext_lazy as _
from django import forms
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.
"""
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
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(
intervention__recorded=None,
)
else:
return queryset
class EcoAccountTableFilter(InterventionTableFilter):
""" TableFilter for eco accounts
Based widely on InterventionTableFilter.
Just some minor changes for EcoAccount model.
"""
sr = django_filters.BooleanFilter(
method='_filter_only_show_unrecorded',
label=_("Show only unrecorded"),
label_suffix=_(""),
widget=forms.CheckboxInput()
)
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
def _filter_only_show_unrecorded(self, queryset, name, value) -> QuerySet:
""" Filters queryset depending on value of 'show_recorded' setting
Args:
queryset ():
name ():
value ():
Returns:
"""
if value:
return queryset.filter(
recorded=None,
)
else:
return queryset