Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update site visit form for wetland #3457

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bims/enums/ecosystem_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@
(ECOSYSTEM_WETLAND, ECOSYSTEM_WETLAND),
(ECOSYSTEM_OPEN_WATERBODY, ECOSYSTEM_OPEN_WATERBODY)
)

HYDROPERIOD_INUNDATED = 'Inundated'
HYDROPERIOD_SATURATED = 'Saturated at surface'
HYDROPERIOD_DRY = 'Dry at surface'

HYDROPERIOD_CHOICES = (
(HYDROPERIOD_INUNDATED, HYDROPERIOD_INUNDATED),
(HYDROPERIOD_SATURATED, HYDROPERIOD_SATURATED),
(HYDROPERIOD_DRY, HYDROPERIOD_DRY),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.1.10 on 2023-08-24 07:37

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('bims', '0344_alter_bimsdocument_authors_notification'),
]

operations = [
migrations.AddField(
model_name='biologicalcollectionrecord',
name='hydroperiod',
field=models.CharField(blank=True, choices=[('Inundated', 'Inundated'), ('Saturated at surface', 'Saturated at surface'), ('Dry at surface', 'Dry at surface')], default='', max_length=255),
),
migrations.AlterField(
model_name='notification',
name='name',
field=models.CharField(choices=[('SITE_VISIT_VALIDATION', 'Site visit is ready to be validated'), ('SITE_VALIDATION', 'Site is ready to be validated'), ('DOWNLOAD_REQUEST', 'Download request notification'), ('ACCOUNT_CREATED', 'Account created email notification'), ('SASS_CREATED', 'SASS created email notification'), ('NEW_TAXONOMY', 'New taxonomy email notification')], max_length=255, unique=True),
),
]
20 changes: 20 additions & 0 deletions bims/migrations/0346_alter_bimsdocument_authors_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.1.10 on 2023-08-24 08:12

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('bims', '0345_biologicalcollectionrecord_hydroperiod_and_more'),
]

operations = [
migrations.AlterField(
model_name='biologicalcollectionrecord',
name='hydroperiod',
field=models.CharField(blank=True, choices=[('Inundated', 'Inundated'), ('Saturated at surface', 'Saturated at surface'), ('Dry at surface', 'Dry at surface')], default='', max_length=255, null=True),
),
]
12 changes: 11 additions & 1 deletion bims/models/biological_collection_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
from bims.enums.taxonomic_group_category import TaxonomicGroupCategory
from bims.models.bims_document import BimsDocument
from bims.models.survey import Survey
from bims.enums.ecosystem_type import ECOSYSTEM_TYPE_CHOICES
from bims.enums.ecosystem_type import (
ECOSYSTEM_TYPE_CHOICES, HYDROPERIOD_CHOICES
)
from td_biblio.models import Entry


Expand Down Expand Up @@ -268,6 +270,14 @@ class BiologicalCollectionRecord(AbstractValidation):
blank=True
)

hydroperiod = models.CharField(
max_length=255,
choices=HYDROPERIOD_CHOICES,
blank=True,
null=True,
default=''
)

biotope = models.ForeignKey(
'bims.Biotope',
null=True,
Expand Down
17 changes: 16 additions & 1 deletion bims/templates/collections_form_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,25 @@ <h2>Add {{ taxon_group_name }} data for site {% if location_site_code %}{{ locat
value="{{ user.id }}">
</div>
</div>
{% if location_site.ecosystem_type == 'Wetland' %}
<div class="form-group row">
<label for="date"
class="col-sm-2 col-form-label col-form-label">Hydroperiod</label>
<div class="col-sm-10">
<select class="form-control"
name="hydroperiod" id="hydroperiod">
<option value=""> Not specified</option>
{% for hydroperiod in hydroperiod_choices %}
<option value="{{ hydroperiod.0 }}">{{ hydroperiod.1 }}</option>
{% endfor %}
</select>
</div>
</div>
{% endif %}
<div class="form-group row">
<label for="date"
class="col-sm-2 col-form-label col-form-label">Broad
Biotope</label>
Biotope / Habitat</label>
<div class="col-sm-10">
<select class="form-control"
name="biotope" id="broad-biotope">
Expand Down
17 changes: 16 additions & 1 deletion bims/templates/site_visit/site_visit_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,25 @@ <h2>Detail {{ taxon_group.name }} data for site {% if object.site.site_code %}{{
</div>
</div>
</div>
{% if object.site.ecosystem_type == 'Wetland' %}
<div class="form-group row">
<label for="date"
class="col-sm-2 col-form-label col-form-label">Hydroperiod</label>
<div class="col-sm-10">
<select class="form-control"
name="hydroperiod" id="hydroperiod" disabled>
<option value=""> Not specified</option>
{% for hydroperiod_tuple in hydroperiod_choices %}
<option value="{{ hydroperiod_tuple.0 }}" {% if hydroperiod_tuple.0 == hydroperiod %} selected {% endif %}>{{ hydroperiod_tuple.1 }}</option>
{% endfor %}
</select>
</div>
</div>
{% endif %}
<div class="form-group row">
<label for="date"
class="col-sm-2 col-form-label col-form-label">Broad
Biotope</label>
Biotope / Habitat </label>
<div class="col-sm-10">
<select class="form-control"
name="biotope" id="broad-biotope" disabled>
Expand Down
17 changes: 16 additions & 1 deletion bims/templates/site_visit/site_visit_update.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,25 @@ <h2>Update {{ taxon_group.name }} data for site {% if object.site.site_code %}{{
</div>
</div>
</div>
{% if object.site.ecosystem_type == 'Wetland' %}
<div class="form-group row">
<label for="date"
class="col-sm-2 col-form-label col-form-label">Hydroperiod</label>
<div class="col-sm-10">
<select class="form-control"
name="hydroperiod" id="hydroperiod">
<option value=""> Not specified</option>
{% for hydroperiod_tuple in hydroperiod_choices %}
<option value="{{ hydroperiod_tuple.0 }}" {% if hydroperiod_tuple.0 == hydroperiod %} selected {% endif %}>{{ hydroperiod_tuple.1 }}</option>
{% endfor %}
</select>
</div>
</div>
{% endif %}
<div class="form-group row">
<label for="date"
class="col-sm-2 col-form-label col-form-label">Broad
Biotope</label>
Biotope / Habitat</label>
<div class="col-sm-10">
<select class="form-control"
name="biotope" id="broad-biotope">
Expand Down
7 changes: 6 additions & 1 deletion bims/views/collections_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from bims.enums.taxonomic_rank import TaxonomicRank
from bims.views.mixin.session_form.mixin import SessionFormMixin
from bims.models.algae_data import AlgaeData
from bims.enums.ecosystem_type import HYDROPERIOD_CHOICES

logger = logging.getLogger('bims')

Expand All @@ -46,6 +47,7 @@ def add_survey_occurrences(self, post_data, site_image = None) -> Survey:
date_string = post_data.get('date', None)
owner_id = post_data.get('owner_id', '').strip()
biotope_id = post_data.get('biotope', None)
hydroperiod = post_data.get('hydroperiod', None)
specific_biotope_id = post_data.get('specific_biotope', None)
substratum_id = post_data.get('substratum', None)
sampling_method_id = post_data.get('sampling_method', None)
Expand Down Expand Up @@ -259,7 +261,8 @@ def add_survey_occurrences(self, post_data, site_image = None) -> Survey:
abundance_type=abundance_type,
survey=self.survey,
record_type=record_type,
source_reference=source_reference
source_reference=source_reference,
hydroperiod=hydroperiod
)
)
collection_record_ids.append(collection_record.id)
Expand Down Expand Up @@ -362,13 +365,15 @@ def get_context_data(self, **kwargs):
context = super(CollectionFormView, self).get_context_data(**kwargs)
if not self.location_site:
return context
context['location_site'] = self.location_site
context['geoserver_public_location'] = get_key(
'GEOSERVER_PUBLIC_LOCATION')
context['location_site_name'] = self.location_site.name
context['location_site_code'] = self.location_site.site_code
context['location_site_lat'] = self.location_site.get_centroid().y
context['location_site_long'] = self.location_site.get_centroid().x
context['site_id'] = self.location_site.id
context['hydroperiod_choices'] = HYDROPERIOD_CHOICES

try:
context['bing_key'] = BaseMapLayer.objects.get(source_type='bing').key
Expand Down
9 changes: 9 additions & 0 deletions bims/views/site_visit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from bims.models.chemical_record import ChemicalRecord
from bims.models.chem import Chem
from bims.models.basemap_layer import BaseMapLayer
from bims.enums.ecosystem_type import HYDROPERIOD_CHOICES


class SiteVisitBaseView(View):
Expand All @@ -19,6 +20,12 @@ def taxon_group(self):
return self.collection_records[0].module_group
return None

def hydroperiod(self):
"""Get hydroperiod data from one of the occurrences"""
if self.collection_records.exists():
return self.collection_records.first().hydroperiod
return ''

def owner(self):
"""Get owner of the site visit"""
if self.object.owner:
Expand Down Expand Up @@ -157,6 +164,8 @@ def get_context_data(self, **kwargs):
context['sampling_effort_value'] = sampling_effort_value
context['sampling_effort_unit'] = sampling_effort_unit
context['abundance_type'] = self.abundance_type()
context['hydroperiod_choices'] = HYDROPERIOD_CHOICES
context['hydroperiod'] = self.hydroperiod()

context['broad_biotope_list'] = (
Biotope.objects.broad_biotope_list(
Expand Down
7 changes: 5 additions & 2 deletions bims/views/site_visit/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def form_valid(self, form):
taxa_id_list = form.data.get('taxa-id-list', '')
owner_id = form.data.get('owner_id', None)
collector_id = form.data.get('collector_id', None)
hydroperiod = form.data.get('hydroperiod', '')
owner = None
collector_user = None
if owner_id:
Expand Down Expand Up @@ -136,7 +137,8 @@ def form_valid(self, form):
sampling_method_id=form.data.get('sampling_method', None),
abundance_type=form.data.get('abundance_type', ''),
owner=owner,
collector_user=collector_user
collector_user=collector_user,
hydroperiod=hydroperiod
)

# Remove deleted collection records
Expand Down Expand Up @@ -199,7 +201,8 @@ def form_valid(self, form):
survey=self.object,
record_type=self._form_data(
form, 'record_type', ''
)
),
hydroperiod=hydroperiod
)
)
if status:
Expand Down
Loading