<s> from django . db . models import Q <EOL> import django_filters <EOL> import taggit <EOL> from nodeconductor . core import filters as core_filters <EOL> from nodeconductor . structure import models as structure_models <EOL> from nodeconductor . template import models <EOL> class AbstractProjectFilter ( django_filters . Filter ) : <EOL> """<STR_LIT>""" <EOL> def get_project ( self , value ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def filter ( self , qs , value ) : <EOL> if not value : <EOL> return qs <EOL> project = self . get_project ( value ) <EOL> if project is None : <EOL> return qs . none ( ) <EOL> project_head_templates = ( <EOL> models . Template . objects <EOL> . filter ( order_number = <NUM_LIT:1> ) <EOL> . filter ( <EOL> Q ( service_settings__isnull = True ) | <EOL> Q ( service_settings__shared = True ) | <EOL> Q ( service_settings__customer__projects = project ) <EOL> ) <EOL> ) <EOL> return qs . filter ( templates = project_head_templates ) <EOL> class URLProjectFilter ( AbstractProjectFilter , core_filters . URLFilter ) : <EOL> def get_project ( self , value ) : <EOL> uuid = self . get_uuid ( value ) <EOL> try : <EOL> return structure_models . Project . objects . get ( uuid = uuid ) <EOL> except structure_models . Project . DoesNotExist : <EOL> return <EOL> class UUIDProjectFilter ( AbstractProjectFilter ) : <EOL> def get_project ( self , value ) : <EOL> try : <EOL> return structure_models . Project . objects . get ( uuid = value ) <EOL> except structure_models . Project . DoesNotExist : <EOL> return <EOL> class TemplateGroupFilter ( django_filters . FilterSet ) : <EOL> tag = django_filters . ModelMultipleChoiceFilter ( <EOL> name = '<STR_LIT>' , <EOL> to_field_name = '<STR_LIT:name>' , <EOL> lookup_type = '<STR_LIT>' , <EOL> queryset = taggit . models . Tag . objects . all ( ) , <EOL> ) <EOL> rtag = django_filters . ModelMultipleChoiceFilter ( <EOL> name = '<STR_LIT>' , <EOL> to_field_name = '<STR_LIT:name>' , <EOL> queryset = taggit . models . Tag . objects . all ( ) , <EOL> conjoined = True , <EOL> ) <EOL> templates_tag = django_filters . ModelMultipleChoiceFilter ( <EOL> name = '<STR_LIT>' , <EOL> to_field_name = '<STR_LIT:name>' , <EOL> lookup_type = '<STR_LIT>' , <EOL> queryset = taggit . models . Tag . objects . all ( ) , <EOL> ) <EOL> templates_rtag = django_filters . ModelMultipleChoiceFilter ( <EOL> name = '<STR_LIT>' , <EOL> to_field_name = '<STR_LIT:name>' , <EOL> queryset = taggit . models . Tag . objects . all ( ) , <EOL> conjoined = True , <EOL> ) <EOL> project = URLProjectFilter ( view_name = '<STR_LIT>' ) <EOL> project_uuid = UUIDProjectFilter ( ) <EOL> name = django_filters . CharFilter ( lookup_type = '<STR_LIT>' ) <EOL> class Meta ( object ) : <EOL> model = models . TemplateGroup <EOL> fields = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> order_by = [ '<STR_LIT:name>' , '<STR_LIT>' ] </s>
