generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NR-NMP-149] Added regions and subregions
- Loading branch information
1 parent
f2d4648
commit e9e5aed
Showing
30 changed files
with
2,216 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from django.contrib import admin | ||
from .models import Animals | ||
from .models import * | ||
|
||
admin.site.register(Animals) | ||
admin.site.register(AnimalSubtype) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
from rest_framework import serializers | ||
from .models import Animals | ||
from .models import * | ||
|
||
class AnimalsSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Animals | ||
fields = '__all__' | ||
|
||
class AnimalSubtypeSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = AnimalSubtype | ||
fields = '__all__' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
from rest_framework import routers | ||
from .views import AnimalsViewset | ||
|
||
urlpatterns = [ | ||
path('animals/', AnimalsViewset.as_view({'get': 'animals'})), | ||
path('animal_subtypes/', AnimalsViewset.as_view({'get': 'animalSubtypes'})), | ||
path('animal_subtypes/<int:animalId>/', AnimalsViewset.as_view({'get': 'animalSubtypes'})), | ||
] |
26 changes: 14 additions & 12 deletions
26
backend/apps/api/views.py → backend/apps/animals/views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
from rest_framework import status, viewsets | ||
from rest_framework.decorators import action | ||
from rest_framework.response import Response | ||
from apps.crops.models import CropTypes | ||
from apps.crops.serializers import CropTypesSerializer | ||
from apps.animals.models import * | ||
from apps.animals.serializers import * | ||
from .models import * | ||
from .serializers import * | ||
|
||
class APIViewSet(viewsets.ViewSet): | ||
class AnimalsViewset(viewsets.ViewSet): | ||
|
||
@action(detail=True, methods=['get']) | ||
def cropTypes(self, request, pk=None): | ||
crop_types = CropTypes.objects.all() | ||
serializer = CropTypesSerializer(crop_types, many=True) | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
||
@action(detail=True, methods=['get']) | ||
def animals(self, request, pk=None): | ||
def animals(self, request): | ||
animals = Animals.objects.all() | ||
serializer = AnimalsSerializer(animals, many=True) | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
||
@action(detail=True, methods=['get']) | ||
def animalSubtypes(self, request, animalId=None): | ||
animals = None | ||
if animalId == None: | ||
animals = AnimalSubtype.objects.all() | ||
else: | ||
animals = AnimalSubtype.objects.filter(animalid=animalId) | ||
serializer = AnimalSubtypeSerializer(animals, many=True) | ||
return Response(serializer.data, status=status.HTTP_200_OK) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls import path | ||
from rest_framework import routers | ||
from .views import CropsViewset | ||
|
||
urlpatterns = [ | ||
path('croptypes/', CropsViewset.as_view({'get': 'cropTypes'})), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from rest_framework import status, viewsets | ||
from rest_framework.decorators import action | ||
from rest_framework.response import Response | ||
from .models import * | ||
from .serializers import * | ||
|
||
class CropsViewset(viewsets.ViewSet): | ||
|
||
@action(detail=True, methods=['get']) | ||
def cropTypes(self, request): | ||
crop_types = CropTypes.objects.all() | ||
serializer = CropTypesSerializer(crop_types, many=True) | ||
return Response(serializer.data, status=status.HTTP_200_OK) |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.db import models | ||
|
||
class Regions(models.Model): | ||
id = models.IntegerField(primary_key=True) | ||
name = models.CharField(max_length=100) | ||
soiltestphosphorousregioncd = models.IntegerField() | ||
soiltestpotassiumregioncd = models.IntegerField() | ||
locationid = models.IntegerField() | ||
sortorder = models.IntegerField() | ||
|
||
class Meta: | ||
managed = False | ||
db_table = 'regions' | ||
|
||
class Subregion(models.Model): | ||
id = models.IntegerField(primary_key=True) | ||
name = models.CharField(max_length=100) | ||
annualprecipitation = models.IntegerField() | ||
annualprecipitationocttomar = models.IntegerField() | ||
regionid = models.IntegerField() | ||
|
||
class Meta: | ||
managed = False | ||
db_table = 'subregion' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from rest_framework import serializers | ||
from .models import * | ||
|
||
class RegionsSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Regions | ||
fields = '__all__' | ||
|
||
class SubregionSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Subregion | ||
fields = '__all__' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.urls import path | ||
from rest_framework import routers | ||
from .views import SharedViewset | ||
|
||
urlpatterns = [ | ||
path('regions/', SharedViewset.as_view({'get': 'regions'})), | ||
path('subregions/', SharedViewset.as_view({'get': 'subregions'})), | ||
path('subregions/<int:regionId>/', SharedViewset.as_view({'get': 'subregions'})), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from rest_framework import status, viewsets | ||
from rest_framework.decorators import action | ||
from rest_framework.response import Response | ||
from .models import * | ||
from .serializers import * | ||
|
||
class SharedViewset(viewsets.ViewSet): | ||
|
||
@action(detail=True, methods=['get']) | ||
def regions(self, request): | ||
regions = Regions.objects.all() | ||
serializer = RegionsSerializer(regions, many=True) | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
||
@action(detail=True, methods=['get']) | ||
def subregions(self, request, regionId=None): | ||
subregions = None | ||
if regionId == None: | ||
subregions = Subregion.objects.all() | ||
else: | ||
subregions = Subregion.objects.filter(regionid=regionId) | ||
serializer = SubregionSerializer(subregions, many=True) | ||
return Response(serializer.data, status=status.HTTP_200_OK) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.