Unix timestamps, better exceptions
This commit is contained in:
parent
aaa92af032
commit
2624839689
|
@ -10,6 +10,10 @@ from frog_api.serializers import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MissingModelException(APIException):
|
||||||
|
status_code = status.HTTP_404_NOT_FOUND
|
||||||
|
|
||||||
|
|
||||||
class ProjectView(APIView):
|
class ProjectView(APIView):
|
||||||
"""
|
"""
|
||||||
API endpoint that allows projects to be viewed.
|
API endpoint that allows projects to be viewed.
|
||||||
|
@ -26,22 +30,20 @@ class ProjectView(APIView):
|
||||||
|
|
||||||
def get_latest_entry(project, version, category) -> dict:
|
def get_latest_entry(project, version, category) -> dict:
|
||||||
if not Project.objects.filter(slug=project).exists():
|
if not Project.objects.filter(slug=project).exists():
|
||||||
raise APIException(
|
raise MissingModelException(
|
||||||
f"Project {project} not found", code=status.HTTP_404_NOT_FOUND
|
f"Project {project} not found", code=status.HTTP_404_NOT_FOUND
|
||||||
)
|
)
|
||||||
|
|
||||||
if not Version.objects.filter(slug=version, project__slug=project).exists():
|
if not Version.objects.filter(slug=version, project__slug=project).exists():
|
||||||
raise APIException(
|
raise MissingModelException(
|
||||||
f"Version '{version}' not found for project '{project}'",
|
f"Version '{version}' not found for project '{project}'"
|
||||||
code=status.HTTP_404_NOT_FOUND,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if not Category.objects.filter(
|
if not Category.objects.filter(
|
||||||
slug=category, version__slug=version, version__project__slug=project
|
slug=category, version__slug=version, version__project__slug=project
|
||||||
).exists():
|
).exists():
|
||||||
raise APIException(
|
raise MissingModelException(
|
||||||
f"Category '{category}' not found for project '{project}' and version '{version}'",
|
f"Category '{category}' not found for project '{project}' and version '{version}'"
|
||||||
code=status.HTTP_404_NOT_FOUND,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
entry = Entry.objects.filter(
|
entry = Entry.objects.filter(
|
||||||
|
@ -51,7 +53,9 @@ def get_latest_entry(project, version, category) -> dict:
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if entry is None:
|
if entry is None:
|
||||||
raise APIException("Entry is None", code=status.HTTP_404_NOT_FOUND)
|
raise MissingModelException(
|
||||||
|
f"No data exists for project '{project}', version '{version}', and category '{category}'"
|
||||||
|
)
|
||||||
|
|
||||||
# Re-format the measures (TODO: DRF-ify this?)
|
# Re-format the measures (TODO: DRF-ify this?)
|
||||||
entry_data = TerseEntrySerializer(entry).data
|
entry_data = TerseEntrySerializer(entry).data
|
||||||
|
@ -98,9 +102,7 @@ class ProjectDigestView(APIView):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not Project.objects.filter(slug=project).exists():
|
if not Project.objects.filter(slug=project).exists():
|
||||||
return Response(
|
raise MissingModelException(f"Project {project} not found")
|
||||||
f"Project {project} not found", status=status.HTTP_404_NOT_FOUND
|
|
||||||
)
|
|
||||||
|
|
||||||
projects = {}
|
projects = {}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,10 @@ MIDDLEWARE = [
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
REST_FRAMEWORK = {
|
||||||
|
"DATETIME_FORMAT": "%s",
|
||||||
|
}
|
||||||
|
|
||||||
ROOT_URLCONF = "frogress.urls"
|
ROOT_URLCONF = "frogress.urls"
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
|
|
Loading…
Reference in New Issue