Skip to content

Commit

Permalink
Events, Events Published API: add filtering by country
Browse files Browse the repository at this point in the history
Events Published API: change filtering to use EventFilter instead of
"raw" changing queryset.

This fixes #1350.
  • Loading branch information
pbanaszkiewicz committed Oct 6, 2018
1 parent a1cbbbd commit 432f70f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 37 deletions.
5 changes: 2 additions & 3 deletions api/filters.py
Expand Up @@ -37,8 +37,10 @@ class Meta:
model = Event
fields = (
'completed', 'tag',
'administrator', 'host',
'start', 'start_before', 'start_after',
'end', 'end_before', 'end_after',
'country',
)


Expand All @@ -62,9 +64,6 @@ def filter_instructors(queryset, name, value):
return queryset





class PersonFilter(filters.FilterSet):
is_instructor = filters.BooleanFilter(method=filter_instructors,
label='Is instructor?')
Expand Down
36 changes: 2 additions & 34 deletions api/views.py
Expand Up @@ -294,44 +294,12 @@ def get_object(self):

class PublishedEvents(ListAPIView):
"""List published events."""

# only events that have both a starting date and a URL
permission_classes = (IsAuthenticatedOrReadOnly, )
paginator = None # disable pagination

serializer_class = ExportEventSerializer

metadata_class = QueryMetadata

def get_queryset(self):
"""Optionally restrict the returned event set to events hosted by
specific host or administered by specific admin."""
queryset = Event.objects.published_events()

administrator = self.request.query_params.get('administrator', None)
if administrator is not None:
queryset = queryset.filter(administrator__pk=administrator)

host = self.request.query_params.get('host', None)
if host is not None:
queryset = queryset.filter(host__pk=host)

tags = self.request.query_params.getlist('tag', None)
if tags:
tags = Tag.objects.filter(name__in=tags)
for tag in tags:
queryset = queryset.filter(tags=tag)

return queryset

def get_query_params_description(self):
return {
'administrator': 'ID of the organization responsible for admin '
'work on events.',
'host': 'ID of the organization hosting the event.',
'tag': "Events' tag(s). You can use this parameter multiple "
"times.",
}
filterset_class = EventFilter
queryset = Event.objects.published_events()


class UserTodoItems(ListAPIView):
Expand Down

0 comments on commit 432f70f

Please sign in to comment.