Skip to content

Commit

Permalink
Show favourite bus stops on the transport page, if any are set, inste…
Browse files Browse the repository at this point in the history
…ad of nearby bus stops. If location is not known, then show the update form on the transport page.
  • Loading branch information
cnorthwood committed Dec 15, 2010
1 parent 48e72fb commit 12010c0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions molly/apps/places/views.py
Expand Up @@ -237,6 +237,7 @@ def get_metadata(self, request, scheme, value):
return {
'title': entity.title,
'additional': additional,
'entity': entity,
}

def initial_context(self, request, scheme, value):
Expand Down
6 changes: 4 additions & 2 deletions molly/apps/transport/templates/transport/index.html
Expand Up @@ -35,14 +35,14 @@ <h2>Park and Rides</h2>

<div class="section">
<div class="header">
<h2><img src="http://chart.apis.google.com/chart?chst=d_simple_text_icon_left&chld=|14|000|bus|24|000|FFF" />Nearby bus stops - {% now "G:i:s "%}</h2>
<h2><img src="http://chart.apis.google.com/chart?chst=d_simple_text_icon_left&chld=|14|000|bus|24|000|FFF" />{{ bus_stops.results_type }} bus stops - {% now "G:i:s "%}</h2>
</div>

<table class="content">
<tbody>

{% for entity in bus_stops.entities %}
<tr class="sub-section-divider"><th colspan="3"><a href="{{ entity.get_absolute_url }}" style="color:inherit;">{{ entity.title }} <small>({{ entity.distance.km|floatformat:3 }} km{{ entity.bearing }})</small></a></th></tr>
<tr class="sub-section-divider"><th colspan="3"><a href="{{ entity.get_absolute_url }}" style="color:inherit;">{{ entity.title }}{% ifnotequal bus_stops.results_type "Favourites" %} <small>({{ entity.distance.km|floatformat:3 }} km{{ entity.bearing }})</small>{% endifnotequal %}</a></th></tr>
{% if entity.metadata.real_time_information.services %}
{% for service in entity.metadata.real_time_information.services %}
<tr>
Expand All @@ -54,6 +54,8 @@ <h2><img src="http://chart.apis.google.com/chart?chst=d_simple_text_icon_left&ch
{% else %}
<tr><td colspan="3">{{ entity.metadata.real_time_information.pip_info }}</td></tr>
{% endif %}
{% empty %}
<tr><td colspan="3">{% include "geolocation/update_location_embed.html" %}</td></tr>
{% endfor %}
</tbody>
</table>
Expand Down
24 changes: 18 additions & 6 deletions molly/apps/transport/views.py
Expand Up @@ -4,6 +4,7 @@

from molly.utils.views import BaseView
from molly.utils.breadcrumbs import *
from molly.favourites.utils import get_favourites

from molly.apps.places.models import Entity, EntityType

Expand Down Expand Up @@ -31,18 +32,29 @@ def initial_context(cls, request):
context['train_station'] = entity

for context_key in getattr(cls.conf, 'nearby', {}):
type_slug, count, without_location = cls.conf.nearby[context_key]
type_slug, count, without_location, fav_override = cls.conf.nearby[context_key]
et = EntityType.objects.get(slug=type_slug)
if location:
es = et.entities_completion.filter(location__isnull=False).distance(location).order_by('distance')[:count]
elif without_location:
es = et.entities_completion.order_by('title')[:count]
if fav_override:
favourites = filter(lambda e: e is not None and et in e.all_types_completion.all(), [f['metadata'].get('entity') for f in get_favourites(request)])

if not fav_override or len(favourites) == 0:
if location:
es = et.entities_completion.filter(location__isnull=False).distance(location).order_by('distance')[:count]
elif without_location:
es = et.entities_completion.order_by('title')[:count]
else:
context[context_key] = {
'results_type': 'Favourite'
}
continue
else:
continue
es = favourites

entities |= set(es)
context[context_key] = {
'type': et,
'entities': es,
'results_type': 'Favourite' if fav_override and len(favourites) > 0 else 'Nearby'
}

if getattr(cls.conf, 'travel_alerts', False):
Expand Down

0 comments on commit 12010c0

Please sign in to comment.