Implement PeopleDetailView

This commit is contained in:
PCoder 2021-08-31 20:40:24 +05:30
parent 0a24aa01e1
commit 1bbed5eecc
2 changed files with 18 additions and 1 deletions

View file

@ -10,6 +10,7 @@ from django.core.files.base import ContentFile
from django.core.paginator import Paginator
from django.http import FileResponse, HttpResponsePermanentRedirect, HttpResponse, JsonResponse
from django.urls import reverse
from django.shortcuts import get_object_or_404
import os.path as ospath
from shutil import move
@ -225,6 +226,21 @@ class SearchView(View):
return JsonResponse(return_data)
class PeopleDetailView(View):
def get(self, request, people_id):
person = get_object_or_404(Person, id=people_id)
return_data = {
'data': person.dict(),
'resources': [r.dict() for r in person.resourcespeople_set.all()],
'ranges': [r.dict() for r in person.rangespeople_set.all()],
'fields': [r.name for r in person.fieldspeople_set.all()],
'methods': [r.name for r in person.methodspeople_set.all()],
'scales': [r.name for r in person.scalespeople_set.all()],
'taxa': [r.name for r in person.taxapeople_set.all()],
}
return JsonResponse(return_data)
class UploadView(TemplateView):
template_name = "app/admin/config.html"

View file

@ -18,7 +18,7 @@ from django.urls import path
from django.views.generic import TemplateView
from app.views import (
HomePageView, OfflinePageView, send_from_file, DemoPageView, ConfigurationPageView, get_progress, UploadView,
ReindexPageView, RefreshPageView, ConfigurationHomePageView, SearchView
ReindexPageView, RefreshPageView, ConfigurationHomePageView, SearchView, PeopleDetailView
)
@ -38,6 +38,7 @@ urlpatterns = [
path('reindex', ReindexPageView.as_view(), name='reindex'),
path('refresh', RefreshPageView.as_view(), name='refresh'),
path('api/search', SearchView.as_view(), name='api-search'),
path('api/people/<int:people_id>', PeopleDetailView.as_view(), name='api-people-detail'),
# TODO Implement the following