mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-22 03:13:06 +00:00
Fix for dealing with name format (#207)
* Allow plus in names (fix #146) * Handle id/name that does not match the format instead of throwing an error
This commit is contained in:
parent
1890ad9512
commit
fce9410c50
1 changed files with 3 additions and 2 deletions
|
@ -4,6 +4,7 @@ from rest_framework import status, viewsets
|
|||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.http import Http404
|
||||
from .models import * # NOQA
|
||||
from .serializers import * # NOQA
|
||||
import re
|
||||
|
@ -35,7 +36,7 @@ class NameOrIdRetrieval():
|
|||
"""
|
||||
|
||||
idPattern = re.compile("^-?[0-9]+$")
|
||||
namePattern = re.compile("^[0-9A-Za-z\-]+$")
|
||||
namePattern = re.compile("^[0-9A-Za-z\-\+]+$")
|
||||
|
||||
def get_object(self):
|
||||
queryset = self.get_queryset()
|
||||
|
@ -49,7 +50,7 @@ class NameOrIdRetrieval():
|
|||
resp = get_object_or_404(queryset, name=lookup)
|
||||
|
||||
else:
|
||||
resp = get_object_or_404(queryset, pk="")
|
||||
raise Http404
|
||||
|
||||
return resp
|
||||
|
||||
|
|
Loading…
Reference in a new issue