Skip to content

Commit

Permalink
update drf to 3.9, drf-gis to 0.14 and swagger-ui to the most updated…
Browse files Browse the repository at this point in the history
… version
  • Loading branch information
willemarcel committed Jul 24, 2019
1 parent 5cf2a6f commit fa32b6b
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 62 deletions.
3 changes: 1 addition & 2 deletions config/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class SwaggerSchemaView(APIView):
permission_classes = [AllowAny]
renderer_classes = [
renderers.OpenAPIRenderer,
renderers.SwaggerUIRenderer
]

@classmethod
Expand All @@ -21,7 +20,7 @@ def as_view(self, url_pattern=None, **kwargs):
def get(self, request):
generator = SchemaGenerator(
patterns=self.url_pattern,
title='OSMCHA API'
title='OSMCha API'
)
schema = generator.get_schema()

Expand Down
3 changes: 0 additions & 3 deletions config/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@
'rest_framework_gis',
'rest_framework.authtoken',
'social_django',
'rest_framework_swagger',
'corsheaders',
'coreapi',
'coreschema',
'django_filters',
)

Expand Down
9 changes: 7 additions & 2 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.contrib import admin
from django.views import defaults
from django.views import static as static_views
from django.views.generic import TemplateView

from .docs import SwaggerSchemaView

Expand Down Expand Up @@ -44,10 +45,14 @@

# api docs
path(
'api-docs/',
'swagger/',
SwaggerSchemaView.as_view(url_pattern=api_urls),
name='api-docs'
name='swagger'
),
path('api-docs/', TemplateView.as_view(
template_name='redoc.html',
extra_context={'schema_url':'swagger'}
), name='redoc'),

# include api_urls
path(
Expand Down
68 changes: 36 additions & 32 deletions osmchadjango/changeset/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,98 +20,102 @@ class ChangesetFilter(GeoFilterSet):
by contains match (filter changesets that have any of the reasons).
"""
geometry = GeometryFilter(
name='bbox',
field_name='bbox',
lookup_expr='intersects',
help_text="""Geospatial filter of changeset whose bbox intersects with
another geometry. You can use any geometry type in this filter."""
)
checked_by = filters.CharFilter(
name='check_user',
field_name='check_user',
method='filter_checked_by',
help_text="""Filter changesets that were checked by a user. Use commas
to search for more than one user."""
)
users = filters.CharFilter(
name='user',
field_name='user',
method='filter_users',
help_text="""Filter changesets created by a user. Use commas to search
for more than one user."""
)
ids = filters.CharFilter(
name='id',
field_name='id',
method='filter_ids',
help_text="""Filter changesets by its ID. Use commas to search for more
than one id."""
)
uids = filters.CharFilter(
name='uid',
field_name='uid',
method='filter_uids',
help_text="""Filter changesets by its uid. The uid is a unique identifier
of each user in OSM. Use commas to search for more than one uid."""
)
checked = filters.BooleanFilter(
field_name='checked',
widget=BooleanWidget(),
help_text="""Filter changesets that were checked or not. Use true/false,
1/0 values."""
)
harmful = filters.BooleanFilter(
field_name='harmful',
widget=BooleanWidget(),
help_text="""Filter changesets that were marked as harmful or not.
Use true/false, 1/0 values."""
)
is_suspect = filters.BooleanFilter(
field_name='is_suspect',
widget=BooleanWidget(),
help_text='Filter changesets that were considered suspect by OSMCHA.'
)
powerfull_editor = filters.BooleanFilter(
field_name='powerfull_editor',
widget=BooleanWidget(),
help_text="""Filter changesets that were created using a software editor
considered powerfull (those that allow to create, modify or delete
data in a batch)."""
)
order_by = filters.CharFilter(
name=None,
field_name='order',
method='order_queryset',
help_text="""Order the Changesets by one of the following fields: id,
date, check_date, create, modify, delete or number_reasons. Use a
minus sign (-) before the field name to reverse the ordering.
Default ordering is '-id'."""
)
hide_whitelist = filters.BooleanFilter(
name=None,
field_name='user',
method='filter_whitelist',
widget=BooleanWidget(),
help_text="""If True, it will exclude the changesets created by the
users that you whitelisted."""
)
blacklist = filters.BooleanFilter(
name=None,
field_name='user',
method='filter_blacklist',
widget=BooleanWidget(),
help_text="""If True, it will get only the changesets created by the
users that you blacklisted."""
)
mapping_teams = filters.CharFilter(
name='user',
field_name='user',
method='filter_mapping_team',
help_text="""Filter changesets created by users that are on a Mapping
Team. It accepts a list of teams separated by commas."""
)
exclude_teams = filters.CharFilter(
name='user',
field_name='user',
method='exclude_mapping_team',
help_text="""Exclude changesets created by users that are on a Mapping
Team. It accepts a list of teams separated by commas."""
)
exclude_trusted_teams = filters.BooleanFilter(
name=None,
field_name='user',
method='filter_hide_trusted_teams',
widget=BooleanWidget(),
help_text="""If True, it will exclude the changesets created by the
users that are part of trusted teams."""
)
area_lt = filters.CharFilter(
name=None,
field_name='user',
method='filter_area_lt',
help_text="""Filter changesets that have a bbox area lower than X times
the area of your geospatial filter. For example, if the bbox or
Expand All @@ -120,116 +124,116 @@ class ChangesetFilter(GeoFilterSet):
lower than 2 degrees."""
)
create__gte = filters.NumberFilter(
name='create',
field_name='create',
lookup_expr='gte',
help_text="""Filter changesets whose number of elements created are
greater than or equal to a number."""
)
create__lte = filters.NumberFilter(
name='create',
field_name='create',
lookup_expr='lte',
help_text="""Filter changesets whose number of elements created are
lower than or equal to a number."""
)
modify__gte = filters.NumberFilter(
name='modify',
field_name='modify',
lookup_expr='gte',
help_text="""Filter changesets whose number of elements modified are
greater than or equal to a number."""
)
modify__lte = filters.NumberFilter(
name='modify',
field_name='modify',
lookup_expr='lte',
help_text="""Filter changesets whose number of elements modified are
lower than or equal to a number."""
)
delete__gte = filters.NumberFilter(
name='delete',
field_name='delete',
lookup_expr='gte',
help_text="""Filter changesets whose number of elements deleted are
greater than or equal to a number."""
)
delete__lte = filters.NumberFilter(
name='delete',
field_name='delete',
lookup_expr='lte',
help_text="""Filter changesets whose number of elements deleted are
lower than or equal to a number."""
)
date__gte = filters.DateTimeFilter(
name='date',
field_name='date',
lookup_expr='gte',
help_text="""Filter changesets whose date is greater than or equal to a
date or a datetime value."""
)
date__lte = filters.DateTimeFilter(
name='date',
field_name='date',
lookup_expr='lte',
help_text="""Filter changesets whose date is lower than or equal to a
date or a datetime value."""
)
check_date__gte = filters.DateTimeFilter(
name='check_date',
field_name='check_date',
lookup_expr='gte',
help_text="""Filter changesets whose check_date is greater than or equal
to a date or a datetime value."""
)
check_date__lte = filters.DateTimeFilter(
name='check_date',
field_name='check_date',
lookup_expr='lte',
help_text="""Filter changesets whose check_date is lower than or equal
to a date or a datetime value."""
)
editor = filters.CharFilter(
name='editor',
field_name='editor',
lookup_expr='icontains',
help_text="""Filter changesets created with a software editor. It uses
the icontains lookup expression, so a query for 'josm' will return
changesets created or last modified with all JOSM versions."""
)
comment = filters.CharFilter(
name='comment',
field_name='comment',
lookup_expr='icontains',
help_text="""Filter changesets by its comment field using the icontains
lookup expression."""
)
source = filters.CharFilter(
name='source',
field_name='source',
lookup_expr='icontains',
help_text="""Filter changesets by its source field using the icontains
lookup expression."""
)
imagery_used = filters.CharFilter(
name='imagery_used',
field_name='imagery_used',
lookup_expr='icontains',
help_text="""Filter changesets by its imagery_used field using the
icontains lookup expression."""
)
reasons = filters.CharFilter(
name='reasons',
field_name='reasons',
method='filter_any_reasons',
help_text="""Filter changesets that have one or more of the Suspicion
Reasons. Inform the Suspicion Reasons ids separated by commas."""
)
all_reasons = filters.CharFilter(
name='reasons',
field_name='reasons',
method='filter_all_reasons',
help_text="""Filter changesets that have ALL the Suspicion Reasons of a
list. Inform the Suspicion Reasons ids separated by commas."""
)
number_reasons__gte = filters.NumberFilter(
name='number_reasons',
field_name='number_reasons',
method='filter_number_reasons',
help_text="""Filter changesets whose number of Suspicion Reasons is
equal or greater than a value."""
)
tags = filters.CharFilter(
name='tags',
field_name='tags',
method='filter_any_reasons',
help_text="""Filter changesets that have one or more of the Tags. Inform
the Tags ids separated by commas."""
)
all_tags = filters.CharFilter(
name='tags',
field_name='tags',
method='filter_all_reasons',
help_text="""Filter changesets that have ALL the Tags of a list. Inform
the Tags ids separated by commas."""
Expand Down Expand Up @@ -380,4 +384,4 @@ def filter_area_lt(self, queryset, name, value):

class Meta:
model = Changeset
fields = []
fields = ['geometry', 'users', 'area_lt']
18 changes: 9 additions & 9 deletions osmchadjango/changeset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import django_filters.rest_framework
from rest_framework import status
from rest_framework.decorators import (
api_view, parser_classes, permission_classes, detail_route, throttle_classes
api_view, parser_classes, permission_classes, action, throttle_classes
)
from rest_framework.generics import (
ListAPIView, ListCreateAPIView, RetrieveAPIView, get_object_or_404,
Expand Down Expand Up @@ -164,7 +164,7 @@ class AddRemoveChangesetReasonsAPIView(ModelViewSet):
serializer_class = SuspicionReasonsChangesetSerializer
permission_classes = (IsAdminUser,)

@detail_route(methods=['post'])
@action(detail=True, methods=['post'])
def add_reason_to_changesets(self, request, pk):
"""This endpoint allows us to add Suspicion Reasons to changesets in a
batch. The use of this endpoint is restricted to staff users. The ids of
Expand All @@ -184,7 +184,7 @@ def add_reason_to_changesets(self, request, pk):
status=status.HTTP_400_BAD_REQUEST
)

@detail_route(methods=['delete'])
@action(detail=True, methods=['delete'])
def remove_reason_from_changesets(self, request, pk):
"""This endpoint allows us to remove Suspicion Reasons from changesets
in a batch. The use of this endpoint is restricted to staff users. The
Expand Down Expand Up @@ -237,7 +237,7 @@ def update_changeset(self, changeset, request, harmful):
status=status.HTTP_200_OK
)

@detail_route(methods=['put'])
@action(detail=True, methods=['put'])
def set_harmful(self, request, pk):
"""Mark a changeset as harmful. You can set the tags of the changeset by
sending a list of tag ids inside a field named 'tags' in the request
Expand Down Expand Up @@ -266,7 +266,7 @@ def set_harmful(self, request, pk):
)
return self.update_changeset(changeset, request, harmful=True)

@detail_route(methods=['put'])
@action(detail=True, methods=['put'])
def set_good(self, request, pk):
"""Mark a changeset as good. You can set the tags of the changeset by
sending a list of tag ids inside a field named 'tags' in the request
Expand Down Expand Up @@ -337,7 +337,7 @@ class AddRemoveChangesetTagsAPIView(ModelViewSet):
# in docs schema generation.
serializer_class = ChangesetStatsSerializer

@detail_route(methods=['post'])
@action(detail=True, methods=['post'])
def add_tag(self, request, pk, tag_pk):
"""Add a tag to a changeset. If the changeset is unchecked, any user can
add tags. After the changeset got checked, only staff users and the user
Expand Down Expand Up @@ -365,7 +365,7 @@ def add_tag(self, request, pk, tag_pk):
status=status.HTTP_200_OK
)

@detail_route(methods=['delete'])
@action(detail=True, methods=['delete'])
def remove_tag(self, request, pk, tag_pk):
"""Remove a tag from a changeset. If the changeset is unchecked, any user
can remove tags. After the changeset got checked, only staff users and
Expand Down Expand Up @@ -470,7 +470,7 @@ class ChangesetCommentAPIView(ModelViewSet):
permission_classes = (IsAuthenticated,)
serializer_class = ChangesetCommentSerializer

@detail_route(methods=['get'])
@action(detail=True, methods=['get'])
def get_comments(self, request, pk):
"List comments received by a changeset on the OpenStreetMap website."
self.changeset = self.get_object()
Expand All @@ -493,7 +493,7 @@ def get_comments(self, request, pk):
status=status.HTTP_200_OK
)

@detail_route(methods=['post'])
@action(detail=True, methods=['post'])
def post_comment(self, request, pk):
"Post a comment to a changeset in the OpenStreetMap website."
self.changeset = self.get_object()
Expand Down
Loading

0 comments on commit fa32b6b

Please sign in to comment.