Skip to content

Accept empty filter on journey_list page #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions apps/web/templates/web/journey_create2.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load i18n %}
{% load static from staticfiles %}
{% load journey_tags %}
{% block extrahead %}
{% block head %}
<script type="text/javascript" src="{% static 'web/js/jquery.formset.js' %}"></script>
<script src="{% static 'web/jquery-ui-1.11.4/jquery-ui.js' %}"></script>
<script type="text/javascript">
Expand Down Expand Up @@ -43,9 +43,9 @@
<tr>
<th>&nbsp;</th>
<th scope="col">wpt</th>
<th scope="col">order (model)</th>
<th scope="col">label</th>
<th>price</th>
<th>output only</th>
<th></th>
<th></th>
</tr>
</thead>
Expand All @@ -63,8 +63,10 @@
{{ wpt.waypoint.errors }}
</td>
<td>
{{ wpt.order }}
{{ wpt.order.as_hidden }}
{{ wpt.order.errors }}
{{ wpt.label }}
{{ wpt.label.errors }}
</td>
<td>
{{ wpt.segment_price }}
Expand Down
8 changes: 7 additions & 1 deletion apps/web/templates/web/journey_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
</td>
<td>{{ journey.date }}</td>
<td>{{ journey.driver.first_name }} {{ journey.driver.last_name }}</td>
<td>{% count_free_seats journey filter.city_from filter.city_to %}/{{ journey.seats }}</td>
<td>
{% if is_filter_active %}
{% count_free_seats journey filter.city_from filter.city_to %}/{{ journey.seats }}
{% else %}
{% count_free_seats journey journey.journeywaypoints_set|first_city journey.journeywaypoints_set|last_city %}/{{ journey.seats }}
{% endif %}
</td>
</tr>
{% endfor %}
</table>
Expand Down
12 changes: 10 additions & 2 deletions apps/web/views/journey.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class JourneyList(ListView, FormView):
form_class = forms.SearchJourney
success_url = '/' # TODO: replace by generic URL of this page
filter = {
'city_from': models.Waypoint.objects.filter(pk=3).get(),
'city_to': models.Waypoint.objects.filter(pk=2).get(),
'city_from': None, #models.Waypoint.objects.filter(pk=3).get(),
'city_to': None #models.Waypoint.objects.filter(pk=2).get(),
}

GMAPS_CITY_COMPONENT = 'locality'
Expand All @@ -45,9 +45,14 @@ def get_context_data(self, **kwargs):

context['form_search_journey'] = forms.SearchJourney()
context['filter'] = self.filter
context['is_filter_active'] = self._is_filter_active()

return context

def _is_filter_active(self):
return (self.filter['city_from'] is not None and
self.filter['city_to'] is not None)

def __city_to_waypoint_model(self, long_city_name):
gmaps = googlemaps.Client(key='AIzaSyAen5jtHmdJ5ZW3ZOCoqDVjZLkDlILJ014')

Expand Down Expand Up @@ -87,6 +92,9 @@ def form_valid(self, form):
return super(JourneyList, self).form_valid(form)

def get_queryset(self):
if not self._is_filter_active():
return models.Journey.objects.all()

# TODO: add other restrictions such as date
qs = models.Journey.objects.raw('''
SELECT
Expand Down