<s> import django_filters <EOL> from rest_framework . filters import BaseFilterBackend <EOL> from nodeconductor . core import filters as core_filters <EOL> from nodeconductor . structure import models as structure_models <EOL> from . models import ResourceSlaStateTransition <EOL> from . utils import get_period <EOL> class ResourceScopeFilterBackend ( core_filters . GenericKeyFilterBackend ) : <EOL> def get_related_models ( self ) : <EOL> return structure_models . Resource . get_all_models ( ) <EOL> def get_field_name ( self ) : <EOL> return '<STR_LIT>' <EOL> class ResourceStateFilter ( django_filters . FilterSet ) : <EOL> class Meta : <EOL> model = ResourceSlaStateTransition <EOL> period = django_filters . CharFilter ( name = '<STR_LIT>' ) <EOL> class SlaFilter ( BaseFilterBackend ) : <EOL> """<STR_LIT>""" <EOL> def filter_queryset ( self , request , queryset , view ) : <EOL> period = get_period ( request ) <EOL> if '<STR_LIT>' in request . query_params : <EOL> value = request . query_params . get ( '<STR_LIT>' ) <EOL> return queryset . filter ( sla_items__value = value , sla_items__period = period ) <EOL> elif request . query_params . get ( '<STR_LIT:o>' ) == '<STR_LIT>' : <EOL> return queryset . filter ( sla_items__period = period ) . order_by ( '<STR_LIT>' ) <EOL> else : <EOL> return queryset <EOL> class MonitoringItemFilter ( BaseFilterBackend ) : <EOL> """<STR_LIT>""" <EOL> def filter_queryset ( self , request , queryset , view ) : <EOL> for key in request . query_params . keys ( ) : <EOL> item_name = self . _get_item_name ( key ) <EOL> if item_name : <EOL> value = request . query_params . get ( key ) <EOL> queryset = queryset . filter ( monitoring_items__name = item_name , <EOL> monitoring_items__value = value ) <EOL> order_by = request . query_params . get ( '<STR_LIT:o>' ) <EOL> item_name = self . _get_item_name ( order_by ) <EOL> if item_name : <EOL> queryset = queryset . filter ( monitoring_items__name = item_name ) . order_by ( '<STR_LIT>' ) <EOL> return queryset <EOL> def _get_item_name ( self , key ) : <EOL> if key and key . startswith ( '<STR_LIT>' ) : <EOL> _ , item_name = key . split ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> return item_name </s>
