mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-10 06:04:18 +00:00
final lints
This commit is contained in:
parent
341b635332
commit
4bbb7b0a44
16 changed files with 2393 additions and 1716 deletions
|
@ -1,5 +1,5 @@
|
|||
# Docker settings
|
||||
from .settings import *
|
||||
from .settings import * # NOQA
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from .settings import *
|
||||
from .settings import * # NOQA
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
|
|
|
@ -144,13 +144,11 @@ CORS_ALLOW_METHODS = (
|
|||
)
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
|
||||
'DEFAULT_RENDERER_CLASSES': (
|
||||
'rest_framework.renderers.JSONRenderer',
|
||||
),
|
||||
|
||||
'DEFAULT_PARSER_CLASSES': (
|
||||
'rest_framework.parsers.JSONParser',
|
||||
'DEFAULT_PARSER_CLASSES': (
|
||||
'rest_framework.parsers.JSONParser',
|
||||
),
|
||||
|
||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
|
||||
|
|
|
@ -26,30 +26,26 @@ urlpatterns = [
|
|||
|
||||
url(r'^$', 'config.views.home'),
|
||||
|
||||
url(r'^docsv1/$',
|
||||
url(r'^docsv1/$',
|
||||
TemplateView.as_view(template_name='pages/docsv1.html'),
|
||||
name="documentation"
|
||||
),
|
||||
|
||||
url(r'^docsv2/$',
|
||||
),
|
||||
url(r'^docsv2/$',
|
||||
TemplateView.as_view(template_name='pages/docsv2.html'),
|
||||
name="documentation_v2"
|
||||
),
|
||||
|
||||
url(r'^404/$',
|
||||
),
|
||||
url(r'^404/$',
|
||||
TemplateView.as_view(template_name='404.html'),
|
||||
name="404"
|
||||
),
|
||||
|
||||
url(r'^500/$',
|
||||
),
|
||||
url(r'^500/$',
|
||||
TemplateView.as_view(template_name='500.html'),
|
||||
name="500"
|
||||
),
|
||||
|
||||
),
|
||||
url(r'^about/$', 'config.views.about'),
|
||||
|
||||
url(r'^', include(pokemon_urls)),
|
||||
|
||||
|
||||
url(r'^', include(pokemon_v2_urls)),
|
||||
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # + v2
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # + v2
|
||||
|
|
121
config/views.py
121
config/views.py
|
@ -3,14 +3,8 @@
|
|||
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
# from pokemon.models import (
|
||||
# Pokemon, Sprite, Move, Description, Game,
|
||||
# EggGroup, Type, Ability, MovePokemon
|
||||
# )
|
||||
|
||||
from pokemon_v2.models import *
|
||||
from pokemon_v2.models import * # NOQA
|
||||
|
||||
from hits.models import ResourceView
|
||||
|
||||
|
@ -23,22 +17,8 @@ def _total_site_data():
|
|||
Using count() is drastically cheaper than len(objects.all())
|
||||
"""
|
||||
|
||||
# v1
|
||||
# data = dict(
|
||||
# pokemon=Pokemon.objects.count(),
|
||||
# sprites=Sprite.objects.count(),
|
||||
# moves=Move.objects.count(),
|
||||
# descriptions=Description.objects.count(),
|
||||
# games=Game.objects.count(),
|
||||
# egg_groups=EggGroup.objects.count(),
|
||||
# types=Type.objects.count(),
|
||||
# abilities=Ability.objects.count(),
|
||||
# move_pokes=MovePokemon.objects.count()
|
||||
# )
|
||||
|
||||
|
||||
# v2 Sorry for the brute force. Theres probably a better way to do this.
|
||||
data = dict (
|
||||
data = dict(
|
||||
abilities=Ability.objects.count(),
|
||||
abilitie_names=AbilityName.objects.count(),
|
||||
abilitie_effect_texts=AbilityEffectText.objects.count(),
|
||||
|
@ -176,61 +156,60 @@ def _total_site_data():
|
|||
version_groups=VersionGroup.objects.count(),
|
||||
version_group_move_learn_methods=VersionGroupMoveLearnMethod.objects.count(),
|
||||
version_group_regions=VersionGroupRegion.objects.count(),
|
||||
)
|
||||
)
|
||||
|
||||
lines = 0
|
||||
for i in data.iteritems():
|
||||
lines += i[1]
|
||||
|
||||
resources = 0
|
||||
resources += data['abilities'];
|
||||
resources += data['berries'];
|
||||
resources += data['berry_flavors'];
|
||||
resources += data['berry_firmnesses'];
|
||||
resources += data['characteristics'];
|
||||
resources += data['contest_types'];
|
||||
resources += data['contest_effects'];
|
||||
resources += data['egg_groups'];
|
||||
resources += data['encounter_methods'];
|
||||
resources += data['encounter_conditions'];
|
||||
resources += data['encounter_condition_values'];
|
||||
resources += data['evolution_chains'];
|
||||
resources += data['evolution_triggers'];
|
||||
resources += data['generations'];
|
||||
resources += data['genders'];
|
||||
resources += data['growth_rates'];
|
||||
resources += data['items'];
|
||||
resources += data['item_attributes'];
|
||||
resources += data['item_categories'];
|
||||
resources += data['item_fling_effects'];
|
||||
resources += data['item_pockets'];
|
||||
resources += data['languages'];
|
||||
resources += data['locations'];
|
||||
resources += data['location_areas'];
|
||||
resources += data['moves'];
|
||||
resources += data['move_ailments'];
|
||||
resources += data['move_categories'];
|
||||
resources += data['move_battle_styles'];
|
||||
resources += data['move_damage_classes'];
|
||||
resources += data['move_learn_methods'];
|
||||
resources += data['move_targets'];
|
||||
resources += data['natures'];
|
||||
resources += data['pal_park_areas'];
|
||||
resources += data['pokedexes'];
|
||||
resources += data['pokemon'];
|
||||
resources += data['pokemon_colors'];
|
||||
resources += data['pokemon_forms'];
|
||||
resources += data['pokemon_habitats'];
|
||||
resources += data['pokemon_shapes'];
|
||||
resources += data['pokemon_species'];
|
||||
resources += data['pokeathlon_stats'];
|
||||
resources += data['regions'];
|
||||
resources += data['stats'];
|
||||
resources += data['super_contest_effects'];
|
||||
resources += data['types'];
|
||||
resources += data['versions'];
|
||||
resources += data['version_groups'];
|
||||
|
||||
resources += data['abilities']
|
||||
resources += data['berries']
|
||||
resources += data['berry_flavors']
|
||||
resources += data['berry_firmnesses']
|
||||
resources += data['characteristics']
|
||||
resources += data['contest_types']
|
||||
resources += data['contest_effects']
|
||||
resources += data['egg_groups']
|
||||
resources += data['encounter_methods']
|
||||
resources += data['encounter_conditions']
|
||||
resources += data['encounter_condition_values']
|
||||
resources += data['evolution_chains']
|
||||
resources += data['evolution_triggers']
|
||||
resources += data['generations']
|
||||
resources += data['genders']
|
||||
resources += data['growth_rates']
|
||||
resources += data['items']
|
||||
resources += data['item_attributes']
|
||||
resources += data['item_categories']
|
||||
resources += data['item_fling_effects']
|
||||
resources += data['item_pockets']
|
||||
resources += data['languages']
|
||||
resources += data['locations']
|
||||
resources += data['location_areas']
|
||||
resources += data['moves']
|
||||
resources += data['move_ailment']
|
||||
resources += data['move_categories']
|
||||
resources += data['move_battle_styles']
|
||||
resources += data['move_damage_classes']
|
||||
resources += data['move_learn_methods']
|
||||
resources += data['move_targets']
|
||||
resources += data['natures']
|
||||
resources += data['pal_park_areas']
|
||||
resources += data['pokedexes']
|
||||
resources += data['pokemon']
|
||||
resources += data['pokemon_colors']
|
||||
resources += data['pokemon_forms']
|
||||
resources += data['pokemon_habitats']
|
||||
resources += data['pokemon_shapes']
|
||||
resources += data['pokemon_species']
|
||||
resources += data['pokeathlon_stats']
|
||||
resources += data['regions']
|
||||
resources += data['stats']
|
||||
resources += data['super_contest_effects']
|
||||
resources += data['types']
|
||||
resources += data['versions']
|
||||
resources += data['version_groups']
|
||||
|
||||
data['total_lines'] = lines
|
||||
data['total_resources'] = resources
|
||||
|
|
|
@ -14,6 +14,8 @@ framework.
|
|||
|
||||
"""
|
||||
import os
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
|
||||
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
|
||||
# if running multiple sites in the same mod_wsgi process. To fix this, use
|
||||
|
@ -24,7 +26,6 @@ os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
|||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
application = get_wsgi_application()
|
||||
|
||||
# Apply WSGI middleware here.
|
||||
|
|
|
@ -1 +1 @@
|
|||
from build import *
|
||||
from build import * # NOQA
|
||||
|
|
|
@ -1 +1 @@
|
|||
from build import *
|
||||
from build import * # NOQA
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# $ build_all()
|
||||
#
|
||||
# Each time the build script is run it will iterate over each table in the database,
|
||||
# wipe it and rewrite each row using the data found in data/v2/csv.
|
||||
# wipe it and rewrite each r§ow using the data found in data/v2/csv.
|
||||
# If you don't need all of the data just go into data/v2/build.py and
|
||||
# just call one of the build functions found in this script
|
||||
|
||||
|
@ -21,8 +21,8 @@ import os
|
|||
import os.path
|
||||
import re
|
||||
import json
|
||||
from django.db import migrations, connection
|
||||
from pokemon_v2.models import *
|
||||
from django.db import connection
|
||||
from pokemon_v2.models import * # NOQA
|
||||
|
||||
|
||||
# why this way? how about use `__file__`
|
||||
|
@ -39,10 +39,12 @@ imageDir = os.getcwd() + '/data/v2/sprites/'
|
|||
resourceImages = []
|
||||
for root, dirs, files in os.walk(imageDir):
|
||||
for file in files:
|
||||
resourceImages.append(os.path.join(root.replace(imageDir, ""), file));
|
||||
resourceImages.append(os.path.join(root.replace(imageDir, ""), file))
|
||||
|
||||
|
||||
mediaDir = '/media/sprites/{0}'
|
||||
|
||||
|
||||
def filePathOrNone(fileName):
|
||||
return mediaDir.format(fileName) if fileName in resourceImages else None
|
||||
|
||||
|
@ -66,14 +68,15 @@ def clear_table(model):
|
|||
print('building ' + table_name)
|
||||
# Reset DB auto increments to start at 1
|
||||
if DB_VENDOR == 'sqlite':
|
||||
db_cursor.execute("DELETE FROM sqlite_sequence WHERE name = " + "'" + table_name + "'" )
|
||||
db_cursor.execute("DELETE FROM sqlite_sequence WHERE name = " + "'" + table_name + "'")
|
||||
else:
|
||||
db_cursor.execute("SELECT setval(pg_get_serial_sequence(" + "'" + table_name + "'" + ",'id'), 1, false);")
|
||||
db_cursor.execute(
|
||||
"SELECT setval(pg_get_serial_sequence(" + "'" + table_name + "'" + ",'id'), 1, false);")
|
||||
|
||||
|
||||
def process_csv(file_name, data_to_models):
|
||||
daten = load_data(file_name)
|
||||
next(daten, None) # skip header
|
||||
next(daten, None) # skip header
|
||||
for data in daten:
|
||||
for model in data_to_models(data):
|
||||
model.save()
|
||||
|
@ -87,7 +90,7 @@ def build_generic(model_classes, file_name, data_to_models):
|
|||
|
||||
def scrubStr(str):
|
||||
"""
|
||||
The purpose of this function is to scrub the weird template mark-up out of strings
|
||||
The purpose of this function is to scrub the weird template mark-up out of strings
|
||||
that Veekun is using for their pokedex.
|
||||
Example:
|
||||
[]{move:dragon-tail} will effect the opponents [HP]{mechanic:hp}.
|
||||
|
@ -113,16 +116,17 @@ def scrubStr(str):
|
|||
|
||||
def _build_languages():
|
||||
def data_to_language(info):
|
||||
yield Language (
|
||||
id = int(info[0]),
|
||||
iso639 = info[1],
|
||||
iso3166 = info[2],
|
||||
name = info[3],
|
||||
official = bool(int(info[4])),
|
||||
order = info[5],
|
||||
yield Language(
|
||||
id=int(info[0]),
|
||||
iso639=info[1],
|
||||
iso3166=info[2],
|
||||
name=info[3],
|
||||
official=bool(int(info[4])),
|
||||
order=info[5],
|
||||
)
|
||||
build_generic((Language,), 'languages.csv', data_to_language)
|
||||
|
||||
|
||||
def build_languages():
|
||||
_build_languages()
|
||||
|
||||
|
@ -132,20 +136,19 @@ def build_languages():
|
|||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
languageName = LanguageName (
|
||||
language = Language.objects.get(pk = int(info[0])),
|
||||
local_language = Language.objects.get(pk = int(info[1])),
|
||||
name = info[2]
|
||||
languageName = LanguageName(
|
||||
language=Language.objects.get(pk=int(info[0])),
|
||||
local_language=Language.objects.get(pk=int(info[1])),
|
||||
nam=info[2]
|
||||
)
|
||||
|
||||
languageName.save()
|
||||
|
||||
|
||||
|
||||
############
|
||||
# REGION #
|
||||
############
|
||||
|
||||
|
||||
def build_regions():
|
||||
clear_table(Region)
|
||||
data = load_data('regions.csv')
|
||||
|
@ -153,13 +156,12 @@ def build_regions():
|
|||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
model = Region (
|
||||
id = int(info[0]),
|
||||
name = info[1]
|
||||
model = Region(
|
||||
id=int(info[0]),
|
||||
name=info[1]
|
||||
)
|
||||
model.save()
|
||||
|
||||
|
||||
clear_table(RegionName)
|
||||
data = load_data('region_names.csv')
|
||||
|
||||
|
@ -689,7 +691,7 @@ def build_items():
|
|||
id = index,
|
||||
item = Item.objects.get(pk=int(info[0])),
|
||||
sprites = json.dumps(sprites)
|
||||
)
|
||||
)
|
||||
imageModel.save()
|
||||
|
||||
|
||||
|
@ -1489,20 +1491,20 @@ def build_natures():
|
|||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
|
||||
decreased_stat = None
|
||||
increased_stat = None
|
||||
hates_flavor = None
|
||||
likes_flavor = None
|
||||
|
||||
|
||||
if (info[2] != info[3]):
|
||||
decreased_stat = Stat.objects.get(pk = int(info[2]))
|
||||
increased_stat = Stat.objects.get(pk = int(info[3]))
|
||||
|
||||
|
||||
if (info[4] != info[5]):
|
||||
hates_flavor = BerryFlavor.objects.get(pk = int(info[4]))
|
||||
likes_flavor = BerryFlavor.objects.get(pk = int(info[5]))
|
||||
|
||||
|
||||
nature = Nature (
|
||||
id = int(info[0]),
|
||||
name = info[1],
|
||||
|
@ -1520,7 +1522,7 @@ def build_natures():
|
|||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
|
||||
natureName = NatureName (
|
||||
nature = Nature.objects.get(pk = int(info[0])),
|
||||
language = Language.objects.get(pk = int(info[1])),
|
||||
|
@ -1534,7 +1536,7 @@ def build_natures():
|
|||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
|
||||
naturePokeathlonStat = NaturePokeathlonStat (
|
||||
nature = Nature.objects.get(pk = int(info[0])),
|
||||
pokeathlon_stat = PokeathlonStat.objects.get(pk = int(info[1])),
|
||||
|
@ -1548,7 +1550,7 @@ def build_natures():
|
|||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
|
||||
model = NatureBattleStylePreference (
|
||||
nature = Nature.objects.get(pk = int(info[0])),
|
||||
move_battle_style = MoveBattleStyle.objects.get(pk = int(info[1])),
|
||||
|
@ -1730,7 +1732,7 @@ def build_locations():
|
|||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
|
||||
model = Location (
|
||||
id = int(info[0]),
|
||||
region = Region.objects.get(pk = int(info[1])) if info[1] != '' else None,
|
||||
|
@ -1744,7 +1746,7 @@ def build_locations():
|
|||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
|
||||
model = LocationName (
|
||||
location = Location.objects.get(pk = int(info[0])),
|
||||
language = Language.objects.get(pk = int(info[1])),
|
||||
|
@ -1758,7 +1760,7 @@ def build_locations():
|
|||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
|
||||
model = LocationGameIndex (
|
||||
location = Location.objects.get(pk = int(info[0])),
|
||||
generation = Generation.objects.get(pk = int(info[1])),
|
||||
|
@ -1772,14 +1774,14 @@ def build_locations():
|
|||
|
||||
for index, info in enumerate(data):
|
||||
if index > 0:
|
||||
|
||||
|
||||
location = Location.objects.get(pk = int(info[1]))
|
||||
|
||||
|
||||
model = LocationArea (
|
||||
id = int(info[0]),
|
||||
location = location,
|
||||
game_index = int(info[2]),
|
||||
name = '{}-{}'.format(location.name, info[3]) if info[3] else '{}-{}'.format(location.name, 'area')
|
||||
name = '{}-{}'.format(location.name, info[3]) if info[3] else '{}-{}'.format(location.name, 'area')
|
||||
)
|
||||
model.save()
|
||||
|
||||
|
@ -1798,7 +1800,7 @@ def build_locations():
|
|||
model.save()
|
||||
|
||||
|
||||
|
||||
|
||||
#############
|
||||
# POKEMON #
|
||||
#############
|
||||
|
@ -1994,7 +1996,7 @@ def build_pokemons():
|
|||
id = index,
|
||||
pokemon = Pokemon.objects.get(pk=int(info[0])),
|
||||
sprites = json.dumps(sprites)
|
||||
)
|
||||
)
|
||||
imageModel.save()
|
||||
|
||||
clear_table(PokemonAbility)
|
||||
|
@ -2114,7 +2116,7 @@ def build_pokemons():
|
|||
id = index,
|
||||
pokemon_form = PokemonForm.objects.get(pk=int(info[0])),
|
||||
sprites = json.dumps(sprites)
|
||||
)
|
||||
)
|
||||
imageModel.save()
|
||||
|
||||
|
||||
|
@ -2471,4 +2473,4 @@ def build_all():
|
|||
build_pal_parks()
|
||||
|
||||
if __name__ == '__main__':
|
||||
build_all()
|
||||
build_all()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.db import models
|
||||
|
||||
from datetime import date, timedelta
|
||||
from datetime import date
|
||||
|
||||
|
||||
class ViewManager(models.Manager):
|
||||
|
@ -42,4 +42,3 @@ class ResourceView(models.Model):
|
|||
count = models.IntegerField(max_length=1000, default=0)
|
||||
version = models.IntegerField(max_length=1, default=1)
|
||||
date = models.DateField(auto_now=True)
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.test import TestCase
|
||||
|
||||
|
||||
class HeaderTest(TestCase):
|
||||
|
||||
def test_pokemon(self):
|
||||
def test_pokemon(self):
|
||||
|
||||
response = self.client.get(
|
||||
'/api/v1/pokemon/1/',
|
||||
HTTP_ORIGIN="http://pokemon.com"
|
||||
)
|
||||
|
||||
self.assertEqual(response['Access-Control-Allow-Origin'], '*')
|
||||
response = self.client.get(
|
||||
'/api/v1/pokemon/1/',
|
||||
HTTP_ORIGIN="http://pokemon.com"
|
||||
)
|
||||
|
||||
self.assertEqual(response['Access-Control-Allow-Origin'], '*')
|
||||
|
|
|
@ -2,17 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import patterns, include, url
|
||||
|
||||
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
##################################
|
||||
#
|
||||
# V1 API setup using Tastypie
|
||||
#
|
||||
##################################
|
||||
from django.conf.urls import include, url
|
||||
|
||||
from tastypie.api import Api
|
||||
|
||||
|
@ -22,6 +12,16 @@ from pokemon.api import (
|
|||
PokedexResource
|
||||
)
|
||||
|
||||
|
||||
from django.contrib import admin
|
||||
admin.autodiscover()
|
||||
|
||||
##################################
|
||||
#
|
||||
# V1 API setup using Tastypie
|
||||
#
|
||||
##################################
|
||||
|
||||
api_resources = Api()
|
||||
api_resources.register(PokemonResource())
|
||||
api_resources.register(AbilityResource())
|
||||
|
@ -36,4 +36,4 @@ api_resources.register(PokedexResource())
|
|||
urlpatterns = [
|
||||
|
||||
url(r'^api/', include(api_resources.urls)),
|
||||
]
|
||||
]
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,16 +1,17 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.test import TestCase
|
||||
from pokemon_v2.models import *
|
||||
from pokemon_v2.models import * # NOQA
|
||||
|
||||
|
||||
class AbilityTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
Ability.objects.create(
|
||||
name = "Smell",
|
||||
generation_id = 3,
|
||||
is_main_series = true
|
||||
)
|
||||
def setUp(self):
|
||||
Ability.objects.create(
|
||||
name="Smell",
|
||||
generation_id=3,
|
||||
is_main_series=True
|
||||
)
|
||||
|
||||
def fields_are_valid(self):
|
||||
smell = Ability.objects.get(name="Smell")
|
||||
self.assertEqual(smell.generation_id, 3)
|
||||
def fields_are_valid(self):
|
||||
smell = Ability.objects.get(name="Smell")
|
||||
self.assertEqual(smell.generation_id, 3)
|
||||
|
|
3333
pokemon_v2/tests.py
3333
pokemon_v2/tests.py
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
|||
[flake8]
|
||||
|
||||
exclude=*migrations*
|
||||
exclude=*migrations*,*build.py
|
||||
max-line-length = 100
|
||||
|
|
Loading…
Reference in a new issue