From 53669913e947aa5b4d0600ea19e030a966ae1b65 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 16 Feb 2012 19:10:12 +0530 Subject: [PATCH] add page for areas listing --- chaloBEST/mumbai/models.py | 2 ++ chaloBEST/mumbai/views.py | 16 ++++++++++++++++ chaloBEST/urls.py | 3 +++ 3 files changed, 21 insertions(+) diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 2e23921..7efee12 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -49,6 +49,8 @@ class Area(models.Model): geometry = models.PolygonField(blank=True, null=True) alt_names = generic.GenericRelation("AlternativeName") + def get_absolute_url(self): + return "/area/%s/" % self.name def __unicode__(self): return self.name diff --git a/chaloBEST/mumbai/views.py b/chaloBEST/mumbai/views.py index 81fe267..41d9edc 100644 --- a/chaloBEST/mumbai/views.py +++ b/chaloBEST/mumbai/views.py @@ -20,3 +20,19 @@ def route(request, alias): 'routeDetails': routeDetails }) return render_to_response("route.html", context) + +def areas(request): + context = RequestContext(request, { + 'areas': Area.objects.all() + }) + return render_to_response("areas.html", context) + +def area(request, name): + area = get_object_or_404(Area, name=name) + stops = Stop.objects.filter(area=area) + context = RequestContext(request, { + 'area': area, + 'stops': stops + }) + return render_to_response("area.html", context) + diff --git a/chaloBEST/urls.py b/chaloBEST/urls.py index d6d733a..2ecc4de 100644 --- a/chaloBEST/urls.py +++ b/chaloBEST/urls.py @@ -12,6 +12,9 @@ urlpatterns = patterns('', url(r'^static/(?P.*)$','django.views.static.serve', {'document_root':'./static'}), (r'^routes/$', 'mumbai.views.routes'), (r'^route/(?P[a-zA-Z0-9\s\-]*?)/$', 'mumbai.views.route'), + (r'^areas/$', 'mumbai.views.areas'), + (r'^area/(?P.*?)/$', 'mumbai.views.area'), + # Uncomment the admin/doc line below to enable admin documentation: (r'^admin/doc/', include('django.contrib.admindocs.urls')), #(r'^grappelli/', include('grappelli.urls')),