mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-25 04:40:21 +00:00
Linting for the entire project
This commit is contained in:
parent
3867a3bb8d
commit
341b635332
8 changed files with 482 additions and 448 deletions
6
Makefile
6
Makefile
|
@ -1,6 +1,12 @@
|
||||||
install:
|
install:
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
|
dev-install:
|
||||||
|
pip install -r test-requirements.txt
|
||||||
|
|
||||||
|
lint:
|
||||||
|
flake8 .
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
python manage.py migrate --settings=config.local
|
python manage.py migrate --settings=config.local
|
||||||
python manage.py loaddata dev-data.json --settings=config.local
|
python manage.py loaddata dev-data.json --settings=config.local
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
override:
|
override:
|
||||||
- pip install -r requirements.txt
|
- pip install -r requirements.txt
|
||||||
|
- pip install -r test-requirements.txt
|
||||||
|
|
||||||
test:
|
test:
|
||||||
override:
|
override:
|
||||||
|
- make lint
|
||||||
- make test
|
- make test
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import *
|
from .models import * # NOQA
|
||||||
|
|
||||||
admin.site.register(Ability)
|
admin.site.register(Ability)
|
||||||
admin.site.register(AbilityName)
|
admin.site.register(AbilityName)
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from .models import *
|
from .models import * # NOQA
|
||||||
from .serializers import *
|
from .serializers import * # NOQA
|
||||||
import re
|
import re
|
||||||
from hits.models import ResourceView
|
from hits.models import ResourceView
|
||||||
|
|
||||||
|
@ -21,14 +21,14 @@ class ListOrDetailSerialRelation():
|
||||||
list_serializer_class = None
|
list_serializer_class = None
|
||||||
|
|
||||||
def get_serializer_class(self):
|
def get_serializer_class(self):
|
||||||
if (self.action == 'list' and self.list_serializer_class != None):
|
if (self.action == 'list' and self.list_serializer_class is not None):
|
||||||
return self.list_serializer_class
|
return self.list_serializer_class
|
||||||
return self.serializer_class
|
return self.serializer_class
|
||||||
|
|
||||||
|
|
||||||
class NameOrIdRetrieval():
|
class NameOrIdRetrieval():
|
||||||
"""
|
"""
|
||||||
Mixin to allow retrieval of resources by
|
Mixin to allow retrieval of resources by
|
||||||
pk (in this case ID) or by name
|
pk (in this case ID) or by name
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ class NameOrIdRetrieval():
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
queryset = self.get_queryset()
|
queryset = self.get_queryset()
|
||||||
queryset = self.filter_queryset(queryset)
|
queryset = self.filter_queryset(queryset)
|
||||||
lookup = self.kwargs['pk']
|
lookup = self.kwargs['pk']
|
||||||
|
|
||||||
if self.idPattern.match(lookup):
|
if self.idPattern.match(lookup):
|
||||||
resp = get_object_or_404(queryset, pk=lookup)
|
resp = get_object_or_404(queryset, pk=lookup)
|
||||||
|
@ -48,17 +48,20 @@ class NameOrIdRetrieval():
|
||||||
|
|
||||||
else:
|
else:
|
||||||
resp = get_object_or_404(queryset, pk="")
|
resp = get_object_or_404(queryset, pk="")
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
class IncrementingReadOnlyModelViewSet(viewsets.ReadOnlyModelViewSet):
|
class IncrementingReadOnlyModelViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
|
|
||||||
def retrieve(self, request, *args, **kwargs):
|
def retrieve(self, request, *args, **kwargs):
|
||||||
ResourceView.objects.increment_view_count(version=2)
|
ResourceView.objects.increment_view_count(version=2)
|
||||||
return super(IncrementingReadOnlyModelViewSet, self).retrieve(self, request, *args, **kwargs)
|
return super(
|
||||||
|
IncrementingReadOnlyModelViewSet, self).retrieve(self, request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class PokeapiCommonViewset(ListOrDetailSerialRelation, NameOrIdRetrieval, IncrementingReadOnlyModelViewSet):
|
class PokeapiCommonViewset(ListOrDetailSerialRelation,
|
||||||
|
NameOrIdRetrieval, IncrementingReadOnlyModelViewSet):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,6 +89,7 @@ class BerryFirmnessResource(PokeapiCommonViewset):
|
||||||
serializer_class = BerryFirmnessDetailSerializer
|
serializer_class = BerryFirmnessDetailSerializer
|
||||||
list_serializer_class = BerryFirmnessSummarySerializer
|
list_serializer_class = BerryFirmnessSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
class BerryFlavorResource(PokeapiCommonViewset):
|
class BerryFlavorResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
queryset = BerryFlavor.objects.all()
|
queryset = BerryFlavor.objects.all()
|
||||||
|
@ -342,7 +346,7 @@ class PokemonResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
queryset = Pokemon.objects.all()
|
queryset = Pokemon.objects.all()
|
||||||
serializer_class = PokemonDetailSerializer
|
serializer_class = PokemonDetailSerializer
|
||||||
list_serializer_class =PokemonSummarySerializer
|
list_serializer_class = PokemonSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
class PokemonSpeciesResource(PokeapiCommonViewset):
|
class PokemonSpeciesResource(PokeapiCommonViewset):
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,17 +1,16 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf.urls import patterns, include, url
|
from django.conf.urls import include, url
|
||||||
from django.views.generic import TemplateView
|
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
#
|
#
|
||||||
# V2 API setup using Django Rest
|
# V2 API setup using Django Rest
|
||||||
#
|
#
|
||||||
#####################################
|
#####################################
|
||||||
|
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
from pokemon_v2.api import *
|
from pokemon_v2.api import * # NOQA
|
||||||
|
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
|
|
||||||
|
@ -67,15 +66,9 @@ router.register(r"version-group", VersionGroupResource)
|
||||||
###########################
|
###########################
|
||||||
#
|
#
|
||||||
# Gotta Get Em' All
|
# Gotta Get Em' All
|
||||||
#
|
#
|
||||||
###########################
|
###########################
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
url(r'^api/v2/', include(router.urls)),
|
||||||
url(r'^api/v2/', include(router.urls)),
|
|
||||||
|
|
||||||
# url(r'^.*$',
|
|
||||||
# TemplateView.as_view(template_name='home.html'),
|
|
||||||
# name="home"
|
|
||||||
# )
|
|
||||||
]
|
]
|
||||||
|
|
4
setup.cfg
Normal file
4
setup.cfg
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[flake8]
|
||||||
|
|
||||||
|
exclude=*migrations*
|
||||||
|
max-line-length = 100
|
2
test-requirements.txt
Normal file
2
test-requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
flake8==2.5.4
|
||||||
|
pyflakes==1.0.0
|
Loading…
Reference in a new issue