Skip to content

Commit

Permalink
Fixes for #283, #286, #270
Browse files Browse the repository at this point in the history
  • Loading branch information
Elijahwalkerwest committed Apr 16, 2018
1 parent 2b8da16 commit bbe06d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ <h3>Calibration</h3>
<th>UTC Offset:</th>
<td>{{ Calibration.begindatetimeutcoffset }}</td>
<th>Variable Code:</th>
<td>{{ variable.instrumentoutputvariableid.variableid.variablecode }}</td>
<td>{{ Calibration.calibrationaction.instrumentoutputvariableid.variableid.variablecode }}</td>
<th>Check Value:</th>
<td>
{{ variable.calibrationcheckvalue|default:" -- " }}
{{ Calibration.calibrationaction.calibrationcheckvalue|default:" -- " }}
</td>
</tr>
<tr>
Expand All @@ -40,10 +40,10 @@ <h3>Calibration</h3>
<th>Action End DateTime:</th>
<td>{{ Calibration.enddatetime|default:"present" }}</td>
<th>Variable Name:</th>
<td> {{ variable.instrumentoutputvariableid.variableid.variablenamecv }}</td>
<td> {{ Calibration.calibrationaction.instrumentoutputvariableid.variableid.variablenamecv_id }}</td>
<th>Calibration Equation:</th>
<td>
{{ variable.calibrationequation|default:" -- " }}
{{ Calibration.calibrationaction.calibrationequation|default:" -- " }}
</td>
<th>Calibration Link:</th>
<td><a href="{{ MEDIA_URL }}{{ Calibration.actionfilelink }}">{{ Calibration.actionfilelink|get_media_file_name|default:" -- " }}</a></td>
Expand Down
46 changes: 29 additions & 17 deletions src/sensordatainterface/views/edit_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,9 @@ def get_forms_from_request(request, action_id=False):
if i is u'':
outputvariables_clean.append([])
else:
if not outputvariables_clean:
outputvariables_clean.append([])
outputvariables_clean[-1].append(i)
# for j in outputvariables_clean:
# if not j:
# j.pop()


action_form = []
annotation_forms = []
Expand Down Expand Up @@ -885,19 +883,21 @@ def set_up_site_visit(crew_form, site_visit_form, sampling_feature_form, action_
medium = CvMedium.objects.get(name=data['sampledmediumcv'].pk)

if not existing_results_ids:
result, created = Result.objects.update_or_create(
featureactionid=feature_action,
resulttypecv=result_type,
variableid=output_variable.variableid,
unitsid=units,
processinglevelid=processing_level,
resultdatetime=current_action.begindatetime,
resultdatetimeutcoffset=current_action.begindatetimeutcoffset,
statuscv=status,
sampledmediumcv=medium,
valuecount=0)
res = Result.objects.create(
resultid=None,
featureactionid=feature_action,
resulttypecv=result_type,
variableid=output_variable.variableid,
unitsid=units,
processinglevelid=processing_level,
resultdatetime=current_action.begindatetime,
resultdatetimeutcoffset=current_action.begindatetimeutcoffset,
statuscv=status,
sampledmediumcv=medium,
valuecount=0)

else:
result, created = Result.objects.update_or_create(resultid=existing_results_ids[result_id_counter],
res, created = Result.objects.update_or_create(resultid=existing_results_ids[result_id_counter],
featureactionid=feature_action,
resulttypecv=result_type,
variableid=output_variable.variableid,
Expand All @@ -908,7 +908,7 @@ def set_up_site_visit(crew_form, site_visit_form, sampling_feature_form, action_
statuscv=status,
sampledmediumcv=medium,
valuecount=0)
results_to_keep.append(result.resultid)
results_to_keep.append(res.resultid)
result_id_counter += 1
for result in existing_results:
if result.resultid not in results_to_keep:
Expand Down Expand Up @@ -1344,6 +1344,7 @@ def edit_retrieval(request, deployment_id=None, retrieval_id=None):
if request.method == 'POST':
updating = request.POST['action'] == 'update'
if request.POST.get('deployment_id'):
deployment_id = request.POST.get('deployment_id')
deployment_action = Action.objects.get(pk=request.POST.get('deployment_id'))
else:
deployment_action = Action.objects.get(pk=request.POST.get('deploymentaction'))
Expand All @@ -1361,6 +1362,12 @@ def edit_retrieval(request, deployment_id=None, retrieval_id=None):
retrieval_form = ActionForm(request.POST, request.FILES)

if site_visit_form.is_valid() and retrieval_form.is_valid():
retrieval_action_data = retrieval_form.cleaned_data
if not retrieval_action_data['begindatetime'] > deployment_action.enddatetime:
response = HttpResponseRedirect(
reverse('create_retrieval_from_deployment', args=deployment_id)
)
return response
retrieval_action = retrieval_form.save()
parent_site_visit = site_visit_form.cleaned_data['actionid']
if updating:
Expand Down Expand Up @@ -1412,6 +1419,11 @@ def edit_retrieval(request, deployment_id=None, retrieval_id=None):
)

return response
else:
response = HttpResponseRedirect(
reverse('create_retrieval_from_deployment', args=[deployment_id])
)
return response

elif retrieval_id:
action = 'update'
Expand Down

0 comments on commit bbe06d5

Please sign in to comment.