Skip to content

Commit

Permalink
Add filtering to existing list pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubz committed Nov 3, 2017
1 parent 7b6c9fb commit 2da699c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 14 deletions.
20 changes: 20 additions & 0 deletions babybuddy/templates/babybuddy/filter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% load widget_tweaks %}

<form role="form" action="" method="get">
<div class="form-group form-row">
{% for field in filter.form %}
<label for="id_{{ field.name }}" class="col-xs-2 col-sm-auto col-form-label col-form-label-sm">
{{ field.label }}
</label>
<div class="col-xs-10 col-sm-auto">
{{ field|add_class:"form-control form-control-sm" }}
</div>
{% endfor %}
<div class="col-xs-12 col-sm-auto">
<button type="submit" class="btn btn-sm btn-primary">Filter</button>
</div>
<div class="col-xs-12 col-sm-auto">
<a href="{{ request.path }}" class="btn btn-sm btn-dark">Reset</a>
</div>
</div>
</form>
4 changes: 2 additions & 2 deletions core/templates/core/child_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{% block content %}
<h1>Children</h1>
{% include 'babybuddy/filter.html' %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-inverse">
Expand Down Expand Up @@ -50,9 +51,8 @@ <h1>Children</h1>
{% endfor %}
</tbody>
</table>

{% include 'babybuddy/paginator.html' %}
</div>
{% include 'babybuddy/paginator.html' %}

{% if perms.core.add_child %}
<a href="{% url 'child-add' %}" class="btn btn-sm btn-success">
Expand Down
4 changes: 2 additions & 2 deletions core/templates/core/diaperchange_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

{% block content %}
<h1>Diaper Changes</h1>
{% include 'babybuddy/filter.html' %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-inverse">
Expand Down Expand Up @@ -55,9 +56,8 @@ <h1>Diaper Changes</h1>
{% endfor %}
</tbody>
</table>

{% include 'babybuddy/paginator.html' %}
</div>
{% include 'babybuddy/paginator.html' %}

{% if perms.core.add_diaperchange %}
<a href="{% url 'diaperchange-add' %}" class="btn btn-sm btn-success">
Expand Down
4 changes: 2 additions & 2 deletions core/templates/core/feeding_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

{% block content %}
<h1>Feedings</h1>
{% include 'babybuddy/filter.html' %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-inverse">
Expand Down Expand Up @@ -61,9 +62,8 @@ <h1>Feedings</h1>
{% endfor %}
</tbody>
</table>

{% include 'babybuddy/paginator.html' %}
</div>
{% include 'babybuddy/paginator.html' %}

{% if perms.core.add_feeding %}
<a href="{% url 'feeding-add' %}" class="btn btn-sm btn-success">
Expand Down
4 changes: 2 additions & 2 deletions core/templates/core/note_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{% block content %}
<h1>Notes</h1>
{% include 'babybuddy/filter.html' %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-inverse">
Expand Down Expand Up @@ -50,9 +51,8 @@ <h1>Notes</h1>
{% endfor %}
</tbody>
</table>

{% include 'babybuddy/paginator.html' %}
</div>
{% include 'babybuddy/paginator.html' %}

{% if perms.core.add_note %}
<a href="{% url 'note-add' %}" class="btn btn-sm btn-success">
Expand Down
4 changes: 2 additions & 2 deletions core/templates/core/sleep_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

{% block content %}
<h1>Sleep</h1>
{% include 'babybuddy/filter.html' %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-inverse">
Expand Down Expand Up @@ -53,9 +54,8 @@ <h1>Sleep</h1>
{% endfor %}
</tbody>
</table>

{% include 'babybuddy/paginator.html' %}
</div>
{% include 'babybuddy/paginator.html' %}

{% if perms.core.add_sleep %}
<a href="{% url 'sleep-add' %}" class="btn btn-sm btn-success">
Expand Down
4 changes: 2 additions & 2 deletions core/templates/core/timer_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

{% block content %}
<h1>Timers</h1>
{% include 'babybuddy/filter.html' %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-inverse">
Expand Down Expand Up @@ -38,7 +39,6 @@ <h1>Timers</h1>
{% endfor %}
</tbody>
</table>

{% include 'babybuddy/paginator.html' %}
</div>
{% include 'babybuddy/paginator.html' %}
{% endblock %}
4 changes: 2 additions & 2 deletions core/templates/core/tummytime_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

{% block content %}
<h1>Tummy Time</h1>
{% include 'babybuddy/filter.html' %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="thead-inverse">
Expand Down Expand Up @@ -55,9 +56,8 @@ <h1>Tummy Time</h1>
{% endfor %}
</tbody>
</table>

{% include 'babybuddy/paginator.html' %}
</div>
{% include 'babybuddy/paginator.html' %}

{% if perms.core.add_tummytime %}
<a href="{% url 'tummytime-add' %}" class="btn btn-sm btn-success">
Expand Down
7 changes: 7 additions & 0 deletions core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ChildList(PermissionRequiredMixin, FilterView):
template_name = 'core/child_list.html'
permission_required = ('core.view_child',)
paginate_by = 10
filter_fields = ('first_name', 'last_name')


class ChildAdd(PermissionRequiredMixin, CreateView):
Expand Down Expand Up @@ -53,6 +54,7 @@ class DiaperChangeList(PermissionRequiredMixin, FilterView):
template_name = 'core/diaperchange_list.html'
permission_required = ('core.view_diaperchange',)
paginate_by = 10
filter_fields = ('child', 'wet', 'solid', 'color')


class DiaperChangeAdd(PermissionRequiredMixin, CreateView):
Expand Down Expand Up @@ -80,6 +82,7 @@ class FeedingList(PermissionRequiredMixin, FilterView):
template_name = 'core/feeding_list.html'
permission_required = ('core.view_feeding',)
paginate_by = 10
filter_fields = ('child', 'type', 'method')


class FeedingAdd(PermissionRequiredMixin, CreateView):
Expand Down Expand Up @@ -113,6 +116,7 @@ class NoteList(PermissionRequiredMixin, FilterView):
template_name = 'core/note_list.html'
permission_required = ('core.view_note',)
paginate_by = 10
filter_fields = ('child',)


class NoteAdd(PermissionRequiredMixin, CreateView):
Expand Down Expand Up @@ -140,6 +144,7 @@ class SleepList(PermissionRequiredMixin, FilterView):
template_name = 'core/sleep_list.html'
permission_required = ('core.view_sleep',)
paginate_by = 10
filter_fields = ('child',)


class SleepAdd(PermissionRequiredMixin, CreateView):
Expand Down Expand Up @@ -173,6 +178,7 @@ class TimerList(PermissionRequiredMixin, FilterView):
template_name = 'core/timer_list.html'
permission_required = ('core.view_timer',)
paginate_by = 10
filter_fields = ('active', 'user')


class TimerDetail(PermissionRequiredMixin, DetailView):
Expand Down Expand Up @@ -254,6 +260,7 @@ class TummyTimeList(PermissionRequiredMixin, FilterView):
template_name = 'core/tummytime_list.html'
permission_required = ('core.view_tummytime',)
paginate_by = 10
filter_fields = ('child',)


class TummyTimeAdd(PermissionRequiredMixin, CreateView):
Expand Down

0 comments on commit 2da699c

Please sign in to comment.