backend functions for queries + templates for area, route, stop

This commit is contained in:
Sanj 2012-05-23 16:48:40 +05:30
parent ddfeee1226
commit c400b561de
4 changed files with 64 additions and 13 deletions

View File

@ -214,6 +214,11 @@ class Stop(models.Model):
tup = (self.point, dist,) tup = (self.point, dist,)
return Stop.objects.filter(point__distance_lte=tup) return Stop.objects.filter(point__distance_lte=tup)
@property
def routes(self):
return Route.objects.filter(routedetail__stop=self)
def __unicode__(self): def __unicode__(self):
return self.name return self.name
@ -263,6 +268,9 @@ class Route(models.Model):
'url': self.get_absolute_url() 'url': self.get_absolute_url()
} }
def areas_passed(self):
return Area.objects.filter(stop__routedetail__route=self).distinct()
class RouteDetail(models.Model): class RouteDetail(models.Model):
route_code = models.TextField() route_code = models.TextField()
route = models.ForeignKey(Route, to_field="code", null=True, blank=True) route = models.ForeignKey(Route, to_field="code", null=True, blank=True)

View File

@ -21,10 +21,11 @@ a:hover {
{% block body %} {% block body %}
<div id="stopListWrapper" class="listColumn"> <div id="stopListWrapper" class="listColumn">
<input class="listFilterInput" placeholder="Filter..." />
<ul id="stopList"> <ul id="stopList">
{% for stop in stops %} {% for stop in stops %}
<li> <li>
<a href="{{ stop.get_absolute_url }}">{{ s.name }}</a> <a href="{{ stop.get_absolute_url }}">{{ s.display_name }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
@ -40,6 +41,18 @@ a:hover {
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
<div id="areaListWrapper" class="listColumn">
<input class="listFilterInput" placeholder="Filter..." />
<ul id="areaList">
{% for area in area.nearby_areas %}
<li>
<a href="{{ area.get_absolute_url }}">{{ area.display_name }}</a>
</li>
{% endfor %}
</ul>
</div>
<div id="map"></div> <div id="map"></div>
{% endblock %} {% endblock %}

View File

@ -7,6 +7,25 @@
console.firebug=true;//fix the openlayer problem console.firebug=true;//fix the openlayer problem
</script> </script>
<script type="text/javascript" src="http://openlayers.org/dev/OpenLayers.js"></script> <script type="text/javascript" src="http://openlayers.org/dev/OpenLayers.js"></script>
<style type="text/css">
body,html {
width: 100%;
}
#wrapper {
width: 100%;
}
.listColumn {
width: 15%;
float: left;
}
#map {
float: left;
width: 50%;
}
</style>
<title>ChaloBEST: {% block title %} {% endblock %}</title> <title>ChaloBEST: {% block title %} {% endblock %}</title>
{% block head %} {% block head %}

View File

@ -105,17 +105,28 @@ function onFeatureUnselect(obj) {
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<ul id="stopList"> <div id="stopListWrapper">
{% for r in routeDetails %} <input class="listFilterInput" placeholder="Filter..." />
<li> <ul id="stopList">
<a href="{{ r.stop.get_absolute_url }}" class="{% if r.stop.point %} has_point {% else %} no_point {% endif %}">{{ r.stop.name }}</a> {% for r in routeDetails %}
</li> <li>
<a href="{{ r.stop.get_absolute_url }}">{{ r.stop.name }}</a>
{% endfor %} </li>
{% endfor %}
</ul> </ul>
<div id="map">
</div> </div>
<div id="areaListWrapper">
<input class="listFilterInput" placeholder="Filter..." />
<ul id="areaList">
{% for area in route.areas_passed %}
<li>
<a href="{{ area.get_absolute_url }}">{{ area.name }}</a>
</li>
{% endfor %}
</ul>
</div>
<div id="map"></div>
{% endblock %} {% endblock %}