Linting for the entire project

This commit is contained in:
phalt 2016-03-05 09:27:25 +00:00
parent 3867a3bb8d
commit 341b635332
8 changed files with 482 additions and 448 deletions

View file

@ -1,6 +1,12 @@
install:
pip install -r requirements.txt
dev-install:
pip install -r test-requirements.txt
lint:
flake8 .
setup:
python manage.py migrate --settings=config.local
python manage.py loaddata dev-data.json --settings=config.local

View file

@ -1,7 +1,9 @@
dependencies:
override:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
test:
override:
- make lint
- make test

View file

@ -1,7 +1,7 @@
from __future__ import unicode_literals
from django.contrib import admin
from .models import *
from .models import * # NOQA
admin.site.register(Ability)
admin.site.register(AbilityName)

View file

@ -2,8 +2,8 @@
from __future__ import unicode_literals
from rest_framework import viewsets
from django.shortcuts import get_object_or_404
from .models import *
from .serializers import *
from .models import * # NOQA
from .serializers import * # NOQA
import re
from hits.models import ResourceView
@ -21,14 +21,14 @@ class ListOrDetailSerialRelation():
list_serializer_class = None
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.serializer_class
class NameOrIdRetrieval():
"""
Mixin to allow retrieval of resources by
Mixin to allow retrieval of resources by
pk (in this case ID) or by name
"""
@ -38,7 +38,7 @@ class NameOrIdRetrieval():
def get_object(self):
queryset = self.get_queryset()
queryset = self.filter_queryset(queryset)
lookup = self.kwargs['pk']
lookup = self.kwargs['pk']
if self.idPattern.match(lookup):
resp = get_object_or_404(queryset, pk=lookup)
@ -48,17 +48,20 @@ class NameOrIdRetrieval():
else:
resp = get_object_or_404(queryset, pk="")
return resp
class IncrementingReadOnlyModelViewSet(viewsets.ReadOnlyModelViewSet):
def retrieve(self, request, *args, **kwargs):
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
@ -86,6 +89,7 @@ class BerryFirmnessResource(PokeapiCommonViewset):
serializer_class = BerryFirmnessDetailSerializer
list_serializer_class = BerryFirmnessSummarySerializer
class BerryFlavorResource(PokeapiCommonViewset):
queryset = BerryFlavor.objects.all()
@ -342,7 +346,7 @@ class PokemonResource(PokeapiCommonViewset):
queryset = Pokemon.objects.all()
serializer_class = PokemonDetailSerializer
list_serializer_class =PokemonSummarySerializer
list_serializer_class = PokemonSummarySerializer
class PokemonSpeciesResource(PokeapiCommonViewset):

File diff suppressed because it is too large Load diff

View file

@ -1,17 +1,16 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from django.conf.urls import include, url
#####################################
#
# V2 API setup using Django Rest
#
#
#####################################
from rest_framework import routers
from pokemon_v2.api import *
from pokemon_v2.api import * # NOQA
router = routers.DefaultRouter()
@ -67,15 +66,9 @@ router.register(r"version-group", VersionGroupResource)
###########################
#
# Gotta Get Em' All
#
#
###########################
urlpatterns = [
url(r'^api/v2/', include(router.urls)),
# url(r'^.*$',
# TemplateView.as_view(template_name='home.html'),
# name="home"
# )
url(r'^api/v2/', include(router.urls)),
]

4
setup.cfg Normal file
View file

@ -0,0 +1,4 @@
[flake8]
exclude=*migrations*
max-line-length = 100

2
test-requirements.txt Normal file
View file

@ -0,0 +1,2 @@
flake8==2.5.4
pyflakes==1.0.0