Skip to content

Commit

Permalink
Merge pull request #491 from preranaandure/main
Browse files Browse the repository at this point in the history
New Count date for OCR/ OCC Community and fix issue with Plant count and Animal Observation dropdowns data
  • Loading branch information
xzzy committed Jul 25, 2024
2 parents 50c54b2 + b30a8c0 commit 08eab76
Show file tree
Hide file tree
Showing 10 changed files with 387 additions and 62 deletions.
260 changes: 260 additions & 0 deletions boranga/components/occurrence/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,136 @@ def observation_list_of_values(self, request, *args, **kwargs):
}
res_json = json.dumps(res_json)
return HttpResponse(res_json, content_type="application/json")

# used for Occurrence Report Observation Plant count external form
@list_route(
methods=[
"GET",
],
detail=False,
)
def plant_count_list_of_values(self, request, *args, **kwargs):
"""used for Occurrence Report external form"""

plant_count_method_list = []
values = PlantCountMethod.objects.all()
if values:
for val in values:
plant_count_method_list.append(
{
"id": val.id,
"name": val.name,
}
)
plant_count_accuracy_list = []
values = PlantCountAccuracy.objects.all()
if values:
for val in values:
plant_count_accuracy_list.append(
{
"id": val.id,
"name": val.name,
}
)
plant_condition_list = []
values = PlantCondition.objects.all()
if values:
for val in values:
plant_condition_list.append(
{
"id": val.id,
"name": val.name,
}
)
counted_subject_list = []
values = CountedSubject.objects.all()
if values:
for val in values:
counted_subject_list.append(
{
"id": val.id,
"name": val.name,
}
)
res_json = {
"plant_count_method_list": plant_count_method_list,
"plant_count_accuracy_list": plant_count_accuracy_list,
"plant_condition_list": plant_condition_list,
"counted_subject_list": counted_subject_list,
}
res_json = json.dumps(res_json)
return HttpResponse(res_json, content_type="application/json")

# used for Occurrence Report Observation external form
@list_route(
methods=[
"GET",
],
detail=False,
)
def animal_observation_list_of_values(self, request, *args, **kwargs):
"""used for Occurrence Report external form"""


primary_detection_method_list = []
values = PrimaryDetectionMethod.objects.all()
if values:
for val in values:
primary_detection_method_list.append(
{
"id": val.id,
"name": val.name,
}
)
secondary_sign_list = []
values = SecondarySign.objects.all()
if values:
for val in values:
secondary_sign_list.append(
{
"id": val.id,
"name": val.name,
}
)
reprod_state_list = []
values = ReproductiveState.objects.all()
if values:
for val in values:
reprod_state_list.append(
{
"id": val.id,
"name": val.name,
}
)
death_reason_list = []
values = DeathReason.objects.all()
if values:
for val in values:
death_reason_list.append(
{
"id": val.id,
"name": val.name,
}
)
animal_health_list = []
values = AnimalHealth.objects.all()
if values:
for val in values:
animal_health_list.append(
{
"id": val.id,
"name": val.name,
}
)
res_json = {
"primary_detection_method_list": primary_detection_method_list,
"secondary_sign_list": secondary_sign_list,
"reprod_state_list": reprod_state_list,
"death_reason_list": death_reason_list,
"animal_health_list": animal_health_list,
}
res_json = json.dumps(res_json)
return HttpResponse(res_json, content_type="application/json")

def unlocked_back_to_assessor(self):
instance = self.get_object()
Expand Down Expand Up @@ -5125,6 +5255,136 @@ def observation_list_of_values(self, request, *args, **kwargs):
}
res_json = json.dumps(res_json)
return HttpResponse(res_json, content_type="application/json")

# used for Occurrence Observation Plant count external form
@list_route(
methods=[
"GET",
],
detail=False,
)
def plant_count_list_of_values(self, request, *args, **kwargs):
"""used for Occurrence external form"""

plant_count_method_list = []
values = PlantCountMethod.objects.all()
if values:
for val in values:
plant_count_method_list.append(
{
"id": val.id,
"name": val.name,
}
)
plant_count_accuracy_list = []
values = PlantCountAccuracy.objects.all()
if values:
for val in values:
plant_count_accuracy_list.append(
{
"id": val.id,
"name": val.name,
}
)
plant_condition_list = []
values = PlantCondition.objects.all()
if values:
for val in values:
plant_condition_list.append(
{
"id": val.id,
"name": val.name,
}
)
counted_subject_list = []
values = CountedSubject.objects.all()
if values:
for val in values:
counted_subject_list.append(
{
"id": val.id,
"name": val.name,
}
)
res_json = {
"plant_count_method_list": plant_count_method_list,
"plant_count_accuracy_list": plant_count_accuracy_list,
"plant_condition_list": plant_condition_list,
"counted_subject_list": counted_subject_list,
}
res_json = json.dumps(res_json)
return HttpResponse(res_json, content_type="application/json")

# used for Occurrence Report Observation external form
@list_route(
methods=[
"GET",
],
detail=False,
)
def animal_observation_list_of_values(self, request, *args, **kwargs):
"""used for Occurrence Report external form"""


primary_detection_method_list = []
values = PrimaryDetectionMethod.objects.all()
if values:
for val in values:
primary_detection_method_list.append(
{
"id": val.id,
"name": val.name,
}
)
secondary_sign_list = []
values = SecondarySign.objects.all()
if values:
for val in values:
secondary_sign_list.append(
{
"id": val.id,
"name": val.name,
}
)
reprod_state_list = []
values = ReproductiveState.objects.all()
if values:
for val in values:
reprod_state_list.append(
{
"id": val.id,
"name": val.name,
}
)
death_reason_list = []
values = DeathReason.objects.all()
if values:
for val in values:
death_reason_list.append(
{
"id": val.id,
"name": val.name,
}
)
animal_health_list = []
values = AnimalHealth.objects.all()
if values:
for val in values:
animal_health_list.append(
{
"id": val.id,
"name": val.name,
}
)
res_json = {
"primary_detection_method_list": primary_detection_method_list,
"secondary_sign_list": secondary_sign_list,
"reprod_state_list": reprod_state_list,
"death_reason_list": death_reason_list,
"animal_health_list": animal_health_list,
}
res_json = json.dumps(res_json)
return HttpResponse(res_json, content_type="application/json")

@list_route(
methods=[
Expand Down
2 changes: 2 additions & 0 deletions boranga/components/occurrence/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2234,6 +2234,7 @@ class OCRHabitatCondition(models.Model):
default=0,
validators=[MinValueValidator(0), MaxValueValidator(100)],
)
count_date = models.DateTimeField(null=True, blank=True)

class Meta:
app_label = "boranga"
Expand Down Expand Up @@ -4322,6 +4323,7 @@ class OCCHabitatCondition(models.Model):
default=0,
validators=[MinValueValidator(0), MaxValueValidator(100)],
)
count_date = models.DateTimeField(null=True, blank=True)

class Meta:
app_label = "boranga"
Expand Down
16 changes: 16 additions & 0 deletions boranga/components/occurrence/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ def __init__(self, *args, **kwargs):


class OCRHabitatConditionSerializer(serializers.ModelSerializer):
count_date = serializers.DateTimeField(
format="%Y-%m-%d %H:%M:%S", allow_null=True
)

class Meta:
model = OCRHabitatCondition
Expand All @@ -495,6 +498,7 @@ class Meta:
"good",
"degraded",
"completely_degraded",
"count_date",
)


Expand Down Expand Up @@ -1567,6 +1571,9 @@ class SaveOCRHabitatConditionSerializer(serializers.ModelSerializer):
# occurrence_report_id = serializers.IntegerField(required=False, allow_null=True, write_only= True)
# write_only removed from below as the serializer will not return that field in serializer.data
occurrence_report_id = serializers.IntegerField(required=False, allow_null=True)
count_date = serializers.DateTimeField(
format="%Y-%m-%d %H:%M:%S", required=False, allow_null=True
)

class Meta:
model = OCRHabitatCondition
Expand All @@ -1579,6 +1586,7 @@ class Meta:
"good",
"degraded",
"completely_degraded",
"count_date",
)


Expand Down Expand Up @@ -2451,6 +2459,9 @@ def get_copied_ocr(self, obj):
class OCCHabitatConditionSerializer(serializers.ModelSerializer):

copied_ocr = serializers.SerializerMethodField()
count_date = serializers.DateTimeField(
format="%Y-%m-%d %H:%M:%S", allow_null=True
)

class Meta:
model = OCCHabitatCondition
Expand All @@ -2464,6 +2475,7 @@ class Meta:
"good",
"degraded",
"completely_degraded",
"count_date",
)

def get_copied_ocr(self, obj):
Expand Down Expand Up @@ -2787,6 +2799,9 @@ class SaveOCCHabitatConditionSerializer(serializers.ModelSerializer):
# occurrence_id = serializers.IntegerField(required=False, allow_null=True, write_only= True)
# write_only removed from below as the serializer will not return that field in serializer.data
occurrence_id = serializers.IntegerField(required=False, allow_null=True)
count_date = serializers.DateTimeField(
format="%Y-%m-%d %H:%M:%S", required=False, allow_null=True
)

class Meta:
model = OCCHabitatCondition
Expand All @@ -2799,6 +2814,7 @@ class Meta:
"good",
"degraded",
"completely_degraded",
"count_date",
)


Expand Down
Loading

0 comments on commit 08eab76

Please sign in to comment.