Exemplo n.º 1
0
class AdvisorListFilter(django_filters.FilterSet):
    region = django_filters.ChoiceFilter(choices=Region.region_choices(),
                                         method="filter_region")
    chapter = django_filters.ChoiceFilter(
        label="Chapter",
        choices=Chapter.chapter_choices(),
        method="filter_chapter",
    )

    class Meta:
        model = User
        fields = {
            "name": ["icontains"],
            "chapter": ["exact"],
        }
        order_by = ["name"]

    def filter_region(self, queryset, field_name, value):
        if value == "national":
            return queryset
        elif value == "candidate_chapter":
            queryset = queryset.filter(chapter__candidate_chapter=True)
        else:
            queryset = queryset.filter(chapter__region__slug=value)
        return queryset
Exemplo n.º 2
0
class CompleteListFilter(django_filters.FilterSet):
    complete = django_filters.ChoiceFilter(
        label="Complete",
        method="filter_complete",
        choices=(
            ("1", "Complete"),
            ("0", "Incomplete"),
            ("", "All"),
        ),
    )
    region = django_filters.ChoiceFilter(label="Region",
                                         choices=Region.region_choices(),
                                         method="filter_region")

    class Meta:
        model = PledgeProgram  # This is needed to automatically make year/term
        fields = ["region", "year", "term", "complete"]
        order_by = ["chapter"]

    def filter_complete(self, queryset, field_name, value):
        return queryset

    def filter_region(self, queryset, field_name, value):
        if value == "national":
            return queryset
        elif value == "candidate_chapter":
            queryset = queryset.filter(chapter__candidate_chapter=True)
        else:
            queryset = queryset.filter(chapter__region__slug=value)
        return queryset
Exemplo n.º 3
0
class GearArticleListFilter(django_filters.FilterSet):
    region = django_filters.ChoiceFilter(
        label="Region", choices=Region.region_choices(), method="filter_region"
    )
    chapter = django_filters.ChoiceFilter(
        label="Chapter", choices=Chapter.chapter_choices(), method="filter_chapter"
    )
    date = DateRangeFilter(label="Submit Date")

    class Meta:
        fields = ["region", "chapter", "reviewed", "date"]
        model = GearArticle
        order_by = ["chapter"]

    def filter_region(self, queryset, field_name, value):
        if value == "national":
            return queryset
        elif value == "candidate_chapter":
            queryset = queryset.filter(chapter__candidate_chapter=True)
        else:
            queryset = queryset.filter(chapter__region__slug=value)
        return queryset

    def filter_chapter(self, queryset, field_name, value):
        if value:
            queryset = queryset.filter(submission__chapter__slug=value)
        return queryset
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     natoff = kwargs.get("natoff", False)
     if natoff:
         kwargs.pop("natoff")
         self.base_filters["region"] = django_filters.ChoiceFilter(
             choices=Region.region_choices(), method="filter_region"
         )
         self.base_filters["chapter"] = django_filters.ChoiceFilter(
             label="Chapter",
             choices=Chapter.chapter_choices(),
             method="filter_chapter",
         )
         self.base_filters["pictures"] = django_filters.ChoiceFilter(
             label="Pictures",
             choices=((True, "1+"), (False, "None")),
             method="filter_pictures",
         )
     super().__init__(*args, **kwargs)
Exemplo n.º 5
0
class ChapterBalanceListFilter(django_filters.FilterSet):
    region = django_filters.ChoiceFilter(label="Region",
                                         choices=Region.region_choices(),
                                         method="filter_region")

    class Meta:
        model = Invoice
        fields = [
            "region",
        ]

    def filter_region(self, queryset, field_name, value):
        if value == "national":
            return queryset
        elif value == "candidate_chapter":
            queryset = queryset.filter(candidate_chapter=True)
        else:
            queryset = queryset.filter(region_slug=value)
        return queryset
Exemplo n.º 6
0
class BallotCompleteFilter(django_filters.FilterSet):
    region = django_filters.ChoiceFilter(
        label="Region", choices=Region.region_choices(), method="filter_region"
    )

    class Meta:
        model = BallotComplete
        fields = [
            "region",
            "motion",
        ]
        order_by = ["ballot__due_date"]

    def filter_region(self, queryset, field_name, value):
        if value == "national":
            return queryset
        elif value == "candidate_chapter":
            queryset = queryset.filter(user__chapter__candidate_chapter=True)
        else:
            queryset = queryset.filter(user__chapter__region__slug=value)
        return queryset
Exemplo n.º 7
0
class UserRoleListFilter(django_filters.FilterSet):
    current_status = django_filters.ChoiceFilter(
        choices=[
            ("active", "active"),
            ("pnm", "prospective"),
        ],
        method="filter_current_status",
    )
    role = django_filters.MultipleChoiceFilter(choices=UserRoleChange.ROLES,
                                               method="filter_role")
    region = django_filters.ChoiceFilter(choices=Region.region_choices(),
                                         method="filter_region")
    major = django_filters.ModelChoiceFilter(
        queryset=ChapterCurricula.objects.none(),
        method="filter_major",
    )
    chapter = django_filters.ChoiceFilter(
        label="Chapter",
        choices=Chapter.chapter_choices(),
        method="filter_chapter",
    )

    class Meta:
        model = User
        fields = {
            "name": ["icontains"],
            "major": ["exact"],
            "graduation_year": ["icontains"],
            "chapter": ["exact"],
        }
        order_by = ["name"]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.filters["major"].queryset = ChapterCurricula.objects.values_list(
            "major",
            flat=True,
        ).distinct()

    def filter_current_status(self, queryset, field_name, value):
        if value:
            queryset = queryset.filter(current_status=value)
        return queryset

    def filter_role(self, queryset, field_name, value):
        if value:
            queryset = queryset.filter(roles__role__in=value,
                                       roles__end__gte=TODAY_END)
        return queryset

    def filter_region(self, queryset, field_name, value):
        if value == "national":
            return queryset
        elif value == "candidate_chapter":
            queryset = queryset.filter(chapter__candidate_chapter=True)
        else:
            queryset = queryset.filter(chapter__region__slug=value)
        return queryset

    def filter_major(self, queryset, field_name, value):
        if value:
            queryset = queryset.filter(major__major=value.major)
        return queryset

    def filter_chapter(self, queryset, field_name, value):
        if value:
            queryset = queryset.filter(chapter__slug=value)
        return queryset