LDSSA / portal

LDSA Portal
3 stars 2 forks source link

Instructor’s student list view filter only filters by the first selected filter #196

Open buedaswag opened 3 years ago

buedaswag commented 3 years ago

when i filter for both can_graduate and user_id, i expect the results shown in the page to be filtered, however, only the first filter is applied

https://portal.lisbondatascience.org/academy/instructor/students/?can_graduate=False&user_id=111

image

buedaswag commented 3 years ago

in the prep course portal i fixed it like this


def get_queryset(self):
        # no need to call super().get_queryset() because
        # "By default, it returns the value of the queryset attribute"
        # https://docs.djangoproject.com/en/3.2/topics/class-based-views/generic-display/#dynamic-filtering
        slackid = self.request.GET.get("slackid")
        learning_unit = self.request.GET.get("learning_unit")
        exercise_notebook = self.request.GET.get("exercise_notebook")
        # TODO this is inneficient, is there a better way?
        queryset = self.queryset.all()
        if slackid:
            queryset = queryset.filter(slackid=slackid)
        if learning_unit:
            queryset = queryset.filter(learning_unit=learning_unit)
        if exercise_notebook:
            queryset = queryset.filter(exercise_notebook=exercise_notebook)

        return queryset.order_by("-learning_unit", "-exercise_notebook", "-created")
´´´

god its ugly, but it sure works