<commit_before>from django.utils.translation import gettext as _
from django_filters.filters import MultipleChoiceFilter, ModelMultipleChoiceFilter
from geotrek.authent.filters import StructureRelatedFilterSet
from geotrek.outdoor.models import Site, Practice, Sector, Course
from geotrek.zoning.filters import ZoningFilterSet


class SiteFilterSet(ZoningFilterSet, StructureRelatedFilterSet):
    orientation = MultipleChoiceFilter(choices=Site.ORIENTATION_CHOICES, method='filter_orientation')
    wind = MultipleChoiceFilter(choices=Site.ORIENTATION_CHOICES, method='filter_orientation')
    practice = ModelMultipleChoiceFilter(queryset=Practice.objects.all(), method='filter_super')
    sector = ModelMultipleChoiceFilter(queryset=Sector.objects.all(), method='filter_sector', label=_("Sector"))

    class Meta(StructureRelatedFilterSet.Meta):
        model = Site
        fields = StructureRelatedFilterSet.Meta.fields + [
            'sector', 'practice', 'labels', 'themes', 'portal', 'source', 'information_desks',
            'web_links', 'type', 'orientation', 'wind',
        ]

    def filter_orientation(self, qs, name, values):
        return qs.filter(**{'{}__contains'.format(name): values}).get_ancestors(include_self=True)

    def filter_super(self, qs, name, values):
        if not values:
            return qs
        return qs.filter(**{'{}__in'.format(name): values}).get_ancestors(include_self=True)

    def filter_sector(self, qs, name, values):
        if not values:
            return qs
        return qs.filter(practice__sector__in=values).get_ancestors(include_self=True)


class CourseFilterSet(ZoningFilterSet, StructureRelatedFilterSet):
    orientation = MultipleChoiceFilter(choices=Site.ORIENTATION_CHOICES, method='filter_orientation')
    wind = MultipleChoiceFilter(choices=Site.ORIENTATION_CHOICES, method='filter_orientation')

    class Meta(StructureRelatedFilterSet.Meta):
        model = Course
        fields = StructureRelatedFilterSet.Meta.fields + [
            'site', 'site__practice__sector', 'site__practice', 'site__labels', 'site__themes',
            'site__portal', 'site__source', 'site__type', 'orientation', 'wind',
            'height',
        ]

    def filter_orientation(self, qs, name, values):
        return qs.filter(**{'site__{}__contains'.format(name): values})<commit_msg>Fix orientation/wind labels in course filter<commit_after>from django.utils.translation import gettext as _
from django_filters.filters import MultipleChoiceFilter, ModelMultipleChoiceFilter
from geotrek.authent.filters import StructureRelatedFilterSet
from geotrek.outdoor.models import Site, Practice, Sector, Course
from geotrek.zoning.filters import ZoningFilterSet


class SiteFilterSet(ZoningFilterSet, StructureRelatedFilterSet):
    orientation = MultipleChoiceFilter(choices=Site.ORIENTATION_CHOICES, method='filter_orientation')
    wind = MultipleChoiceFilter(choices=Site.ORIENTATION_CHOICES, method='filter_orientation')
    practice = ModelMultipleChoiceFilter(queryset=Practice.objects.all(), method='filter_super')
    sector = ModelMultipleChoiceFilter(queryset=Sector.objects.all(), method='filter_sector', label=_("Sector"))

    class Meta(StructureRelatedFilterSet.Meta):
        model = Site
        fields = StructureRelatedFilterSet.Meta.fields + [
            'sector', 'practice', 'labels', 'themes', 'portal', 'source', 'information_desks',
            'web_links', 'type', 'orientation', 'wind',
        ]

    def filter_orientation(self, qs, name, values):
        return qs.filter(**{'{}__contains'.format(name): values}).get_ancestors(include_self=True)

    def filter_super(self, qs, name, values):
        if not values:
            return qs
        return qs.filter(**{'{}__in'.format(name): values}).get_ancestors(include_self=True)

    def filter_sector(self, qs, name, values):
        if not values:
            return qs
        return qs.filter(practice__sector__in=values).get_ancestors(include_self=True)


class CourseFilterSet(ZoningFilterSet, StructureRelatedFilterSet):
    orientation = MultipleChoiceFilter(choices=Site.ORIENTATION_CHOICES, method='filter_orientation',
                                       label=_("Orientation"))
    wind = MultipleChoiceFilter(choices=Site.ORIENTATION_CHOICES, method='filter_orientation',
                                label=_("Wind"))

    class Meta(StructureRelatedFilterSet.Meta):
        model = Course
        fields = StructureRelatedFilterSet.Meta.fields + [
            'site', 'site__practice__sector', 'site__practice', 'site__labels', 'site__themes',
            'site__portal', 'site__source', 'site__type', 'orientation', 'wind',
            'height',
        ]

    def filter_orientation(self, qs, name, values):
        return qs.filter(**{'site__{}__contains'.format(name): values})
{'fraction_non_alphanumeric': 0.11212058641338013, 'fraction_numerical': 0.0, 'mean_word_length': 4.3584070796460175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4708329', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1313, 'n_words': 256}