ENH: Collections DRF (#25)

This commit is contained in:
Matthew Ryan Dillon 2017-09-09 17:15:39 -07:00 committed by GitHub
parent b9659f6622
commit 04fd45e5de
8 changed files with 123 additions and 1 deletions

View file

@ -4,12 +4,27 @@ from rest_framework import routers
from . import views as api_v
from ..utils import viewsets as utils_viewsets
from ..collections_ccdb import viewsets as collections_viewsets
from ..projects import viewsets as projects_viewsets
from ..locations import viewsets as locations_viewsets
router = routers.DefaultRouter()
router = routers.DefaultRouter(trailing_slash=False)
router.register(r'admin-sections', utils_viewsets.AdminSectionViewSet)
router.register(r'admin-entries', utils_viewsets.AdminEntryViewSet)
# Collections
router.register(r'collections', collections_viewsets.CollectionViewSet)
router.register(r'collection-methods',
collections_viewsets.CollectionMethodViewSet)
router.register(r'collection-types',
collections_viewsets.CollectionTypeViewSet)
router.register(r'collection-flaws',
collections_viewsets.FlawViewSet)
# Projects
router.register(r'projects', projects_viewsets.ProjectViewSet)
# Locations
router.register(r'study-locations', locations_viewsets.StudyLocationViewSet)
urlpatterns = [
url(r'^auth/login/', api_v.Login.as_view()),

View file

@ -0,0 +1,43 @@
from rest_framework import serializers
from .models import Collection, CollectionMethod, CollectionType, Flaw
class CollectionSerializer(serializers.ModelSerializer):
included_serializers = {
'project': 'ccdb.projects.serializers.ProjectSerializer',
'study_location': 'ccdb.locations.serializers.StudyLocationSerializer',
'collection_method':
'ccdb.collections_ccdb.serializers.CollectionMethodSerializer',
'collection_type':
'ccdb.collections_ccdb.serializers.CollectionTypeSerializer',
'flaw': 'ccdb.collections_ccdb.serializers.FlawSerializer',
}
class Meta:
model = Collection
fields = ('id', 'project', 'study_location', 'collection_type',
'collection_method', 'number_of_traps',
'collection_start_date', 'collection_start_time',
'collection_end_date', 'collection_end_time',
'storage_location', 'specimen_state', 'process_type',
'reagent', 'adfg_permit', 'flaw', 'display_name')
class CollectionMethodSerializer(serializers.ModelSerializer):
class Meta:
model = CollectionMethod
fields = ('id', 'name', 'code', 'collection_method_class',
'sort_order')
class CollectionTypeSerializer(serializers.ModelSerializer):
class Meta:
model = CollectionType
fields = ('id', 'name', 'code', 'sort_order')
class FlawSerializer(serializers.ModelSerializer):
class Meta:
model = Flaw
fields = ('id', 'name', 'description', 'sort_order')

View file

@ -0,0 +1,25 @@
from rest_framework import viewsets
from .models import Collection, CollectionMethod, CollectionType, Flaw
from .serializers import (CollectionSerializer, CollectionMethodSerializer,
CollectionTypeSerializer, FlawSerializer)
class CollectionViewSet(viewsets.ModelViewSet):
queryset = Collection.objects.all()
serializer_class = CollectionSerializer
class CollectionMethodViewSet(viewsets.ModelViewSet):
queryset = CollectionMethod.objects.all()
serializer_class = CollectionMethodSerializer
class CollectionTypeViewSet(viewsets.ModelViewSet):
queryset = CollectionType.objects.all()
serializer_class = CollectionTypeSerializer
class FlawViewSet(viewsets.ModelViewSet):
queryset = Flaw.objects.all()
serializer_class = FlawSerializer

View file

@ -0,0 +1,10 @@
from rest_framework import serializers
from .models import StudyLocation
class StudyLocationSerializer(serializers.ModelSerializer):
class Meta:
model = StudyLocation
fields = ('name', 'code', 'study_location_type', 'treatment_type',
'collecting_location', 'description', 'sort_order')

View file

@ -0,0 +1,9 @@
from rest_framework import viewsets
from .models import StudyLocation
from .serializers import StudyLocationSerializer
class StudyLocationViewSet(viewsets.ModelViewSet):
queryset = StudyLocation.objects.all()
serializer_class = StudyLocationSerializer

View file

@ -0,0 +1,9 @@
from rest_framework import serializers
from .models import Project
class ProjectSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = ('name', 'code', 'iacuc_number', 'description', 'sort_order')

View file

@ -0,0 +1,9 @@
from rest_framework import viewsets
from .models import Project
from .serializers import ProjectSerializer
class ProjectViewSet(viewsets.ModelViewSet):
queryset = Project.objects.all()
serializer_class = ProjectSerializer

View file

@ -159,6 +159,8 @@ REST_FRAMEWORK = {
'TEST_REQUEST_DEFAULT_FORMAT': 'json',
}
JSON_API_FORMAT_KEYS = 'dasherize'
SITE_ID = 1
DJOSER = {