Skip to content

Commit

Permalink
Merge pull request #1122 from kartoza/feature/1101-Empty-Cell-Blank
Browse files Browse the repository at this point in the history
Export None and -9999 value in CSV as blank
  • Loading branch information
tinashechiraya authored Oct 16, 2024
2 parents 976c152 + 6ad8fca commit 29cd045
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions django_project/monitor/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ObservationPestImageInline(admin.TabularInline):
fields = ('group', 'image', 'image_preview', 'valid')
readonly_fields = ('image_preview', )


@admin.register(Observations)
class ObservationsAdmin(admin.ModelAdmin):
list_max_show_all = 1000
Expand Down
34 changes: 24 additions & 10 deletions django_project/monitor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def send_email_observation(observation, new_site=False):

send_mail(email_subject, email_content, email_sender, [observation.user.email])


def index(request):
site_form = SiteForm()
observation_form = ObservationForm(initial={'site': '1', 'score': '0.0'})
Expand Down Expand Up @@ -113,14 +114,17 @@ def index(request):
'map_form': map_form
})


def observations(request):
observations = Observations.objects.order_by('-time_stamp')[:10]
return render(request, 'monitor/observations.html', {'observations': observations})


def detail(request, monitor_id):
observation = get_object_or_404(Observations, pk=monitor_id)
return render(request, 'monitor/detail.html', {'observation': observation})


def wms_get_feature_info(request, wms_url, wms_params):
url = 'http://' + wms_url
response = requests.get(url, params=wms_params)
Expand All @@ -130,6 +134,7 @@ def wms_get_feature_info(request, wms_url, wms_params):
else:
return HttpResponse('Error in WMS request', status=500)


def get_sites(request, x, y, d):
select_query = '''
SELECT gid, ST_X(the_geom) as x, ST_Y(the_geom) as y, river_name, site_name, description, river_cat, date(time_stamp) AS time_stamp
Expand All @@ -153,6 +158,7 @@ def get_sites(request, x, y, d):

return render(request, 'monitor/sites.html', {'sites': sites_returned})


def get_closest_site(request, x, y, d):
xy_point = 'POINT(' + x + ' ' + y + ')'

Expand All @@ -178,11 +184,18 @@ def get_schools(request):
schools_returned = Schools.objects.filter(school__istartswith=search_str).order_by('school')
return render(request, 'monitor/schools.html', {'schools': schools_returned})


def get_observations(request, site_id):
observations = Observations.objects.filter(site=site_id).order_by('obs_date')
return render(request, 'monitor/site_observations.html', {'observations': observations})


def get_actual_value(val):
if val is None or int(val) == -9999:
return ''
return val


class DownloadObservations(APIView):

def get(self, request, site_id):
Expand Down Expand Up @@ -258,12 +271,12 @@ def get(self, request, site_id):
smart_str(obs.snails),
smart_str(obs.score),
smart_str(flag),
smart_str(obs.water_clarity),
smart_str(obs.water_temp),
smart_str(obs.ph),
smart_str(obs.diss_oxygen),
smart_str(get_actual_value(obs.water_clarity)),
smart_str(get_actual_value(obs.water_temp)),
smart_str(get_actual_value(obs.ph)),
smart_str(get_actual_value(obs.diss_oxygen)),
smart_str(obs.diss_oxygen_unit),
smart_str(obs.elec_cond),
smart_str(get_actual_value(obs.elec_cond)),
smart_str(obs.elec_cond_unit),
smart_str(obs.comment),
]
Expand Down Expand Up @@ -505,12 +518,12 @@ def download_observations(request, site_id):
smart_str(obs.snails),
smart_str(obs.score),
smart_str(flag),
smart_str(obs.water_clarity),
smart_str(obs.water_temp),
smart_str(obs.ph),
smart_str(obs.diss_oxygen),
smart_str(get_actual_value(obs.water_clarity)),
smart_str(get_actual_value(obs.water_temp)),
smart_str(get_actual_value(obs.ph)),
smart_str(get_actual_value(obs.diss_oxygen)),
smart_str(obs.diss_oxygen_unit),
smart_str(obs.elec_cond),
smart_str(get_actual_value(obs.elec_cond)),
smart_str(obs.elec_cond_unit),
smart_str(obs.comment),
])
Expand Down Expand Up @@ -602,6 +615,7 @@ def download_observations_filtered(request, filter_string):
])
return response


def zoom_observation(request, obs_id):
try:
observation = Observations.objects.get(pk=obs_id)
Expand Down

0 comments on commit 29cd045

Please sign in to comment.