Skip to content

Commit

Permalink
Fixed error in update view when updating sampling feature code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcaraballo17 committed Nov 10, 2017
1 parent 3dfdb29 commit 602c106
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
19 changes: 18 additions & 1 deletion src/dataloaderinterface/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from django.db.models.aggregates import Min

from dataloader.models import SamplingFeature, Affiliation, Result, TimeSeriesResultValue
from dataloader.models import SamplingFeature, Affiliation, Result, TimeSeriesResultValue, EquipmentModel, Variable, \
Unit, Medium
from django.contrib.auth.models import User
from django.db import models

Expand Down Expand Up @@ -85,6 +86,22 @@ class SiteSensor(models.Model):
activation_date = models.DateTimeField(db_column='ActivationDate', blank=True, null=True)
activation_date_utc_offset = models.IntegerField(db_column='ActivationDateUtcOffset', blank=True, null=True)

@property
def equipment_model(self):
return EquipmentModel.objects.filter(model_name=self.model_name).first()

@property
def variable(self):
return Variable.objects.filter(variable_code=self.variable_code).first()

@property
def unit(self):
return Unit.objects.filter(unit_name=self.unit_name).first()

@property
def medium(self):
return Medium.objects.filter(name=self.sampled_medium).first()

@property
def make_model(self):
return "{0}_{1}".format(self.model_manufacturer, self.model_name)
Expand Down
22 changes: 11 additions & 11 deletions src/dataloaderinterface/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,16 @@ def get_success_url(self):
return reverse_lazy('site_detail', kwargs={'sampling_feature_code': self.object.sampling_feature_code})

def get_formset_initial_data(self, *args):
sampling_feature = self.get_object().sampling_feature
results = Result.objects.filter(feature_action__in=(sampling_feature.feature_actions.values_list('feature_action_id')))
registration = self.get_object()
result_form_data = [
{
'result_id': result.result_id,
# this is kinda ugly as shit but works. keep it to be safe, or don't. in case there's results without datalogger column.
'equipment_model': result.data_logger_file_columns.first() and result.data_logger_file_columns.first().instrument_output_variable.model,
'variable': result.variable,
'unit': result.unit,
'sampled_medium': result.sampled_medium
'result_id': sensor.result_id,
'equipment_model': sensor.equipment_model,
'variable': sensor.variable,
'unit': sensor.unit,
'sampled_medium': sensor.medium
}
for result in results.prefetch_related('data_logger_file_columns__instrument_output_variable__model')
for sensor in registration.sensors.all()
]
return result_form_data

Expand Down Expand Up @@ -231,7 +229,7 @@ def post(self, request, *args, **kwargs):

if all_forms_valid(registration_form, sampling_feature_form, site_form, action_by_form, results_formset):
affiliation = action_by_form.cleaned_data['affiliation'] or request.user.odm2user.affiliation
data_logger_file = DataLoggerFile.objects.filter(data_logger_file_name=sampling_feature.sampling_feature_code).first()
data_logger_file = DataLoggerFile.objects.filter(data_logger_file_name=site_registration.sampling_feature_code).first()
data_logger_program = data_logger_file.program

# Update sampling feature
Expand Down Expand Up @@ -473,7 +471,9 @@ def create_result(site_registration, result_form, sampling_feature, affiliation,
site_sensor.save()

# Create csv file to hold the sensor data.
# TODO: have this send a signal and the call to create the file be somewhere else. lol should've done it.
# TODO: have this send a signal and the call to create the file be somewhere else.
# lol should've done it.
# once more i regret not doing it...
serializer = SiteResultSerializer(result)
serializer.build_csv()

Expand Down

0 comments on commit 602c106

Please sign in to comment.