Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit eea988c

Browse files
committed
feat: spruce up list
1 parent 93d6106 commit eea988c

3 files changed

Lines changed: 49 additions & 15 deletions

File tree

locations/templates/locations/center_edit.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
{{ form.id }}
1414
<div class="form-group">
1515
<label for="{{ form.name.name }}">{{ form.name.label }}</label>
16-
<input type="text" class="form-control" id="{{ form.name.auto_id }}" name="{{ form.name.name }}" value="{{ form.name.value }}">
16+
{% render_field form.name class='form-control' %}
1717
</div>
1818
<div class="form-group">
1919
<label for="{{ form.code.name }}">{{ form.code.label }}</label>
20-
<input type="text" class="form-control" id="{{ form.code.auto_id }}" name="{{ form.code.name }}" value="{{ form.code.value }}">
20+
{% render_field form.code class='form-control' %}
2121
</div>
2222
<div class="form-group">
2323
<label for="{{ form.state.name }}">{{ form.state.label }}</label>
@@ -46,7 +46,7 @@
4646
</div>
4747
{% endblock %}
4848
{% block scripts %}
49-
<script src="{% static 'base/vendor/jquery/dist/jquery.min.js' %}"></script>
49+
{{ block.super }}
5050
{% javascript 'centers' %}
5151
<script type="text/javascript">
5252
$(document).ready(function() {

locations/templates/locations/non_reporting_centre_list.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ <h1 class="page-title">{{ page_title }}</h1>
3131
<fieldset>
3232
<div class="form-group row">
3333
<div class="col-md-12">
34+
<select name="{{ filter_form.location.name }}" id="{{ filter_form.location.id_for_label }}" data-placeholder="Location">
35+
{% if filter_form.cleaned_data.location %}<option value="{{ filter_form.cleaned_data.location.pk }}">{{ filter_form.cleaned_data.location.name }}</option>{% endif %}
36+
</select>
3437
{% render_field filter_form.year class="form-control" %}
3538
{% render_field filter_form.month class="form-control" %}
3639
<button type="submit" class="btn btn-primary" id="filter_button">Filter</button>
3740
<a class="btn btn-inverse" href="{% url 'locations:non_reporting_center_list' %}">Clear</a>
38-
<a class="btn btn-primary-outline" href="{% url 'locations:non_reporting_center_list' %}?export=1&year={{ year }}&month={{ month }}">Export</a>
41+
<a class="btn btn-primary-outline" href="{% url 'locations:non_reporting_center_list' %}?export=1&year={{ year }}&month={{ month }}&location={{ location }}">Export</a>
3942
</div>
4043
</div>
4144
</fieldset>
@@ -48,6 +51,7 @@ <h1 class="page-title">{{ page_title }}</h1>
4851
<section class="widget">
4952
<div class="widget-table">
5053
<table class="table table-striped table-bordered table-hover">
54+
<caption>{{ caption }}</caption>
5155
<thead>
5256
<tr>
5357
<th>State</th>
@@ -100,8 +104,8 @@ <h1 class="page-title">{{ page_title }}</h1>
100104
<script src="{% static "js/select2/select2.min.js" %}"></script>
101105
<script>
102106
document.addEventListener('DOMContentLoaded', function () {
103-
var endpoint = '{% url "api:location_list_typed" %}?type=lga';
104-
$('#{{ filter_form.lga.id_for_label }}').select2({
107+
var endpoint = '{% url "api:location_list_typed" %}?type=state,lga';
108+
$('#{{ filter_form.location.id_for_label }}').select2({
105109
ajax: {
106110
url: endpoint,
107111
data: function(params) {

locations/views.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# vim: ai ts=4 sts=4 et sw=4
2+
import calendar
23
import csv
34
import json
45

@@ -206,7 +207,6 @@ def facilities(request):
206207
return response
207208

208209

209-
210210
class CSVBuffer(object):
211211
def write(self, value):
212212
return value
@@ -258,10 +258,34 @@ def get_context_data(self, **kwargs):
258258

259259
context['page_title'] = self.page_title
260260
context['filter_form'] = self.filter_form
261-
context['year'] = self.request.GET.get('year') or now().year
262-
context['month'] = self.request.GET.get('month') or ''
261+
context['year'] = self.selected_year
262+
context['month'] = self.selected_month or ''
263+
context['location'] = self.filter_location.pk if self.filter_location else ''
264+
context['caption'] = self.get_header_title()
263265

264266
return context
267+
268+
def get_header_title(self):
269+
if self.selected_month and self.filter_location:
270+
return 'Non-reporting centres for {}, {} {}'.format(
271+
self.filter_location.name,
272+
calendar.month_name[int(self.selected_month)],
273+
self.selected_year
274+
)
275+
elif self.selected_month:
276+
return 'Non-reporting centres for {} {}'.format(
277+
calendar.month_name[int(self.selected_month)],
278+
self.selected_year
279+
)
280+
elif self.filter_location:
281+
return 'Non-reporting centres for {}, {}'.format(
282+
self.filter_location.name,
283+
self.selected_year
284+
)
285+
else:
286+
return 'Non-reporting centres for {}'.format(
287+
self.selected_year
288+
)
265289

266290
def get_queryset(self):
267291
self.filter_form = NonReportingCentresFilterForm(self.request.GET)
@@ -271,17 +295,23 @@ def get_queryset(self):
271295
filter_data = {}
272296

273297
filter_kwargs = {}
274-
year = filter_data.get('year') or now().year
275-
filter_kwargs['birthregistration_records__time__year'] = int(year)
276-
month = filter_data.get('month')
277-
if month:
278-
filter_kwargs['birthregistration_records__time__month'] = int(month)
298+
alt_filter_kwargs = {'type__name': 'RC'}
299+
self.selected_year = filter_data.get('year') or now().year
300+
filter_kwargs['birthregistration_records__time__year'] = int(self.selected_year)
301+
self.selected_month = filter_data.get('month')
302+
if self.selected_month:
303+
filter_kwargs['birthregistration_records__time__month'] = int(self.selected_month)
304+
305+
self.filter_location = filter_data.get('location')
306+
if self.filter_location:
307+
alt_filter_kwargs['lft__gt'] = self.filter_location.lft
308+
alt_filter_kwargs['rgt__lt'] = self.filter_location.rgt
279309

280310
if len(filter_kwargs) == 0:
281311
centres = Location.objects.none()
282312
else:
283313
centres = Location.objects.filter(
284-
type__name='RC'
314+
**alt_filter_kwargs
285315
).annotate(
286316
cnt=Count(Case(When(then=1, **filter_kwargs)))
287317
).filter(cnt=0)

0 commit comments

Comments
 (0)