Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further uplift to DRF 3.10.3 #618

Merged
merged 9 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ django-ajax-selects = "==1.7.1"
django-environ = "*"
django-filter = "==1.1"
django-storages = "*"
djangorestframework = "==3.6.4"
djangorestframework = "==3.10.3"
factory_boy = "*"
Faker = "*"
google-api-python-client = "*"
Expand Down
8 changes: 4 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions pulseapi/creators/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from itertools import chain
from django.db.models import Q
from django.conf import settings
from rest_framework import filters
from django_filters.rest_framework import DjangoFilterBackend

from rest_framework import exceptions
from rest_framework.filters import BaseFilterBackend
from rest_framework.generics import ListAPIView
from rest_framework.pagination import PageNumberPagination
from rest_framework import exceptions

from pulseapi.profiles.models import UserProfile
from pulseapi.creators.serializers import CreatorSerializer
Expand All @@ -20,7 +22,7 @@ class CreatorsPagination(PageNumberPagination):
max_page_size = 20


class FilterCreatorNameBackend(filters.BaseFilterBackend):
class FilterCreatorNameBackend(BaseFilterBackend):
def filter_queryset(self, request, queryset, view):
search_term = request.query_params.get('name', None)

Expand Down Expand Up @@ -71,7 +73,7 @@ class CreatorListView(ListAPIView):
serializer_class = CreatorSerializer

filter_backends = (
filters.DjangoFilterBackend,
DjangoFilterBackend,
FilterCreatorNameBackend,
)

Expand Down
1 change: 1 addition & 0 deletions pulseapi/entries/serializers/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


class NewsEntrySerializer(EntrySerializerWithCreators):
help_types = None

class Meta(EntrySerializerWithCreators.Meta):
exclude = EntrySerializerWithCreators.Meta.exclude + (
Expand Down
34 changes: 23 additions & 11 deletions pulseapi/entries/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@
import base64
import operator
import django_filters
from functools import reduce

from django.core.exceptions import ObjectDoesNotExist

from django.core.files.base import ContentFile
from django.conf import settings
from django.db import models
from django.db.models import Q

from functools import reduce
from django_filters.rest_framework import (
DjangoFilterBackend,
FilterSet
)

from rest_framework import filters, status
from rest_framework import status
from rest_framework.compat import distinct
from rest_framework.decorators import detail_route, api_view
from rest_framework.generics import ListCreateAPIView, RetrieveAPIView, ListAPIView, get_object_or_404
from rest_framework.decorators import action, api_view
from rest_framework.filters import (
OrderingFilter,
SearchFilter
)
from rest_framework.generics import (
ListCreateAPIView,
RetrieveAPIView,
ListAPIView,
get_object_or_404
)
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
from rest_framework.parsers import JSONParser
Expand Down Expand Up @@ -160,7 +172,7 @@ class EntriesPagination(PageNumberPagination):
max_page_size = 1000


class EntryCustomFilter(filters.FilterSet):
class EntryCustomFilter(FilterSet):
"""
We add custom filtering to allow you to filter by:
* Tag - pass the `?tag=` query parameter
Expand Down Expand Up @@ -255,7 +267,7 @@ def get_serializer_context(self):
# When people POST to this route, we want to do some
# custom validation involving CSRF and nonce validation,
# so we intercept the POST handling a little.
@detail_route(methods=['post'])
@action(detail=True, methods=['post'])
def post(self, request, *args, **kwargs):
validation_result = post_validate(request)

Expand Down Expand Up @@ -306,7 +318,7 @@ class ModerationStateView(ListAPIView):


# see https://stackoverflow.com/questions/60326973
class SearchWithNormalTagFiltering(filters.SearchFilter):
class SearchWithNormalTagFiltering(SearchFilter):
"""
This is a custom search filter that allows the same kind of
matching that DRF v3.6.3 allowed wrt many to many relations,
Expand Down Expand Up @@ -401,9 +413,9 @@ class EntriesListView(ListCreateAPIView):
pagination_class = EntriesPagination

filter_backends = (
filters.DjangoFilterBackend,
DjangoFilterBackend,
SearchWithNormalTagFiltering,
filters.OrderingFilter,
OrderingFilter,
)

filter_class = EntryCustomFilter
Expand Down Expand Up @@ -509,7 +521,7 @@ def get_serializer_context(self):
# When people POST to this route, we want to do some
# custom validation involving CSRF and nonce validation,
# so we intercept the POST handling a little.
@detail_route(methods=['post'])
@action(detail=True, methods=['post'])
def post(self, request, *args, **kwargs):
request_data = request.data
user = request.user if hasattr(request, 'user') else None
Expand Down
26 changes: 16 additions & 10 deletions pulseapi/profiles/views/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
from django.core.files.base import ContentFile
from django.conf import settings
from django.db.models import Q
from rest_framework import permissions, filters
from rest_framework.pagination import PageNumberPagination

from django_filters.rest_framework import (
DjangoFilterBackend,
FilterSet,
)

from rest_framework import permissions
from rest_framework.filters import (
SearchFilter,
OrderingFilter
)
from rest_framework.generics import (
RetrieveUpdateAPIView,
RetrieveAPIView,
ListAPIView,
get_object_or_404,
)
from rest_framework.pagination import PageNumberPagination

from pulseapi.profiles.models import UserProfile
from pulseapi.profiles.serializers import (
Expand Down Expand Up @@ -104,11 +114,7 @@ class NumberInFilter(django_filters.BaseInFilter, django_filters.NumberFilter):
pass


# NOTE: DRF has deprecated the FilterSet class in favor of
# django_filters.rest_framework.FilterSet in v3.7.x, which
# we aren't far from upgrading to.
# SEE: https://github.com/mozilla/network-pulse-api/issues/288
class ProfileCustomFilter(filters.FilterSet):
class ProfileCustomFilter(FilterSet):
"""
We add custom filtering to allow you to filter by:

Expand Down Expand Up @@ -216,9 +222,9 @@ class UserProfileListAPIView(ListAPIView):
page=(number)
"""
filter_backends = (
filters.OrderingFilter,
filters.DjangoFilterBackend,
filters.SearchFilter,
OrderingFilter,
DjangoFilterBackend,
SearchFilter,
)
ordering_fields = ('id', 'custom_name', 'program_year',)
ordering = ('-id',)
Expand Down