Skip to content

Commit

Permalink
avoid showing long lists where it isn't so neccessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jclgoodwin committed Jun 21, 2015
1 parent 6fb1896 commit 83d8893
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
41 changes: 23 additions & 18 deletions busstops/templates/busstops/adminarea_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,34 @@
<h1>{{ adminarea }}</h1>

{% if districts %}
<h2>Districts in {{ adminarea }}</h2>
<h2>Districts in {{ adminarea }}</h2>

<ul>
{% for d in districts %}
<li><a href="{{ d.get_absolute_url }}">{{ d }}</a></li>
{% endfor %}
</ul>
<ul>
{% for d in districts %}
<li><a href="{{ d.get_absolute_url }}">{{ d }}</a></li>
{% endfor %}
</ul>
{% endif %}

<h2>Localities in {{ adminarea }}</h2>

<ul>
{% for l in localities %}
<li><a href="{{ l.get_absolute_url }}">{{ l }}</a></li>
{% endfor %}
</ul>
{% if localities %}
<h2>Localities in {{ adminarea }}</h2>

<h2>Stops in {{ adminarea }}</h2>
<ul>
{% for l in localities %}
<li><a href="{{ l.get_absolute_url }}">{{ l }}</a></li>
{% endfor %}
</ul>
{% endif %}

{% if stops %}
<h2>Stops in {{ adminarea }}</h2>

<ul>
{% for s in stops %}
<li><a href="{{ s.get_absolute_url }}">{{ s }}</a></li>
{% endfor %}
</ul>
<ul>
{% for s in stops %}
<li><a href="{{ s.get_absolute_url }}">{{ s }}</a></li>
{% endfor %}
</ul>
{% endif %}

{% include 'footer.html' %}
10 changes: 7 additions & 3 deletions busstops/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ class AdminAreaDetailView(DetailView):

def get_context_data(self, **kwargs):
context = super(AdminAreaDetailView, self).get_context_data(**kwargs)
context['districts'] = District.objects.filter(admin_area=self.object)#.order_by('name')
context['localities'] = Locality.objects.filter(admin_area=self.object).order_by('name')
context['stops'] = StopPoint.objects.filter(admin_area=self.object).order_by('common_name')
# Districts in this administrative area, if any
context['districts'] = District.objects.filter(admin_area=self.object)
# Localities in this administrative area that don't belong to any district, if any
context['localities'] = Locality.objects.filter(admin_area=self.object, district=None).order_by('name')
# Stops in this administrative area whose locality belongs to a different administrative area
# These are usually National Rail/Air/Ferry. The second .exclude() excludes stops near the boundary of two areas
context['stops'] = StopPoint.objects.filter(admin_area=self.object).exclude(locality__admin_area=self.object).exclude(locality__admin_area__region=self.object.region).order_by('common_name')
return context


Expand Down

0 comments on commit 83d8893

Please sign in to comment.