From 53669913e947aa5b4d0600ea19e030a966ae1b65 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 16 Feb 2012 19:10:12 +0530 Subject: [PATCH 1/9] 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')), From 7e4dd89b4a22c33f597f5d50891936ad812c26a9 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 16 Feb 2012 19:11:28 +0530 Subject: [PATCH 2/9] ups, forgot to add templates --- chaloBEST/templates/area.html | 33 +++++++++++++++++++++++++++++++ chaloBEST/templates/areas.html | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 chaloBEST/templates/area.html create mode 100644 chaloBEST/templates/areas.html diff --git a/chaloBEST/templates/area.html b/chaloBEST/templates/area.html new file mode 100644 index 0000000..c4a097d --- /dev/null +++ b/chaloBEST/templates/area.html @@ -0,0 +1,33 @@ +{% extends 'base.html' %} + +{% block title %} Area: {{ area.name }} {% endblock %} + +{% block head %} + + +{% endblock %} + +{% block body %} +
    + {% for s in stops %} +
  • + {{ s.name }} +
  • + + {% endfor %} + +
+ +{% endblock %} diff --git a/chaloBEST/templates/areas.html b/chaloBEST/templates/areas.html new file mode 100644 index 0000000..c08815a --- /dev/null +++ b/chaloBEST/templates/areas.html @@ -0,0 +1,36 @@ +{% extends 'base.html' %} + +{% block title %} + Areas +{% endblock %} + +{% block head %} + +{% endblock %} + +{% block body %} + Filter: +
    + {% for a in areas %} +
  • + {{ a.name }} +
  • + {% endfor %} +
+ +{% endblock %} From cd295a2511f767bfdccd0099fa0143cfeacf38a6 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 16 Feb 2012 19:29:33 +0530 Subject: [PATCH 3/9] some fixes on search filter for areas and routes views --- chaloBEST/mumbai/models.py | 3 +++ chaloBEST/templates/areas.html | 8 ++++---- chaloBEST/templates/routes.html | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 7efee12..aaeee15 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -124,6 +124,9 @@ class Route(models.Model): distance = models.DecimalField(max_digits=3, decimal_places=1) stages = models.IntegerField() + def get_absolute_url(self): + return "/route/%s/" % self.alias + def __unicode__(self): return self.alias diff --git a/chaloBEST/templates/areas.html b/chaloBEST/templates/areas.html index c08815a..50e0ffb 100644 --- a/chaloBEST/templates/areas.html +++ b/chaloBEST/templates/areas.html @@ -7,9 +7,9 @@ {% block head %}