From caafe71240127c2b282b0dc807f363e22a1ec368 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 20 Feb 2012 18:58:22 +0530 Subject: [PATCH] first step toward editstops --- chaloBEST/mumbai/models.py | 15 +++++++++--- chaloBEST/mumbai/views.py | 7 ++++++ chaloBEST/static/css/editstops.css | 0 chaloBEST/static/js/editstops.js | 31 ++++++++++++++++++++++++ chaloBEST/templates/base.html | 1 + chaloBEST/templates/editstops.html | 39 ++++++++++++++++++++++++++++++ chaloBEST/urls.py | 1 + 7 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 chaloBEST/static/css/editstops.css create mode 100644 chaloBEST/static/js/editstops.js create mode 100644 chaloBEST/templates/editstops.html diff --git a/chaloBEST/mumbai/models.py b/chaloBEST/mumbai/models.py index 212ee1c..5fc40d0 100644 --- a/chaloBEST/mumbai/models.py +++ b/chaloBEST/mumbai/models.py @@ -97,7 +97,6 @@ class Stop(models.Model): alt_names = generic.GenericRelation("AlternativeName") def get_dict(self): - routes = [r.route.alias for r in RouteDetail.objects.filter(stop=self)] return { 'id': self.id, 'code': self.code, @@ -107,8 +106,8 @@ class Stop(models.Model): 'road': self.road.name, 'area': self.area.name, 'name_mr': self.name_mr, - 'routes': routes - #FIXME: add alt names + 'routes': ",".join([r.route.alias for r in RouteDetail.objects.filter(stop=self)]), + 'alternative_names': ",".join([a.name for a in self.alt_names.all().filter(typ='common')]) } def get_geojson(self, srid=4326): @@ -131,6 +130,16 @@ class Stop(models.Model): self.point = Point(geom[0], geom[1]) self.display_name = data['display_name'] self.name_mr = data['name_mr'] + if data.has_key('alternative_names') and data['alternative_names'].strip() != '': + for a in self.alt_names.all(): + a.delete() + for a in data['alternative_names'].split(","): + alt_name = AlternativeName() + alt_name.name = a['name'] + alt_name.typ = 'common' + alt_name.save() + self.alt_names.add(alt_name) + #FIXME: add alt names logic self.save() return self.get_geojson() diff --git a/chaloBEST/mumbai/views.py b/chaloBEST/mumbai/views.py index 4a1c164..4affe51 100644 --- a/chaloBEST/mumbai/views.py +++ b/chaloBEST/mumbai/views.py @@ -2,6 +2,7 @@ from models import * from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext +from django.contrib.auth.decorators import login_required def index(request): return render_to_response("index.html", {}) @@ -36,3 +37,9 @@ def area(request, name): }) return render_to_response("area.html", context) +@login_required +def editstops(request): + context = RequestContext(request, {}) + return render_to_response("editstops.html", context) + + diff --git a/chaloBEST/static/css/editstops.css b/chaloBEST/static/css/editstops.css new file mode 100644 index 0000000..e69de29 diff --git a/chaloBEST/static/js/editstops.js b/chaloBEST/static/js/editstops.js new file mode 100644 index 0000000..50257d6 --- /dev/null +++ b/chaloBEST/static/js/editstops.js @@ -0,0 +1,31 @@ +var API_BASE = "/1.0/" +$(function() { + $('.tabButton').click(function() { + if ($(this).hasClass("selected")) { + return; + } + var $that = $(this); + var name = $that.attr("data-name"); + var $listWrapper = $('#' + name); + if ($that.data("loaded")) { + $.noop(); //dont load data + } else { + $that.data("loaded", true); + var $list = $('#' + name + 'List'); + $.post("/" + name, {}, function(items) { + $.each(items, function(i,v) { + var $li = $('
  • ') + .addClass("listItem") + .text(v) + .appendTo($list); + }); + }, "json"); + } + + $('.listWrapper').hide(); + $listWrapper.show(); + $('.selected').removeClass("selected"); + $that.addClass("selected"); + }); + +}); diff --git a/chaloBEST/templates/base.html b/chaloBEST/templates/base.html index 28ae2eb..a6eca7e 100644 --- a/chaloBEST/templates/base.html +++ b/chaloBEST/templates/base.html @@ -1,6 +1,7 @@ + ChaloBEST: {% block title %} {% endblock %} {% block head %} diff --git a/chaloBEST/templates/editstops.html b/chaloBEST/templates/editstops.html new file mode 100644 index 0000000..9320288 --- /dev/null +++ b/chaloBEST/templates/editstops.html @@ -0,0 +1,39 @@ +{% extends 'base.html' %} + +{% block head %} + + +{% endblock %} + + +{% block body %} +
    +
    +
    + Areas +
    +
    + Routes +
    +
    +
    +
    + +
      +
    +
    +
    + +
      +
    +
    +
    +
    +
    + +
    +
    + +
    + +{% endblock %} diff --git a/chaloBEST/urls.py b/chaloBEST/urls.py index f437764..807cce1 100644 --- a/chaloBEST/urls.py +++ b/chaloBEST/urls.py @@ -17,6 +17,7 @@ urlpatterns = patterns('', (r'^route/(?P[a-zA-Z0-9\s\-]*?)/$', 'mumbai.views.route'), (r'^areas/$', 'mumbai.views.areas'), (r'^area/(?P.*?)/$', 'mumbai.views.area'), + (r'^editstops/$', 'mumbai.views.editstops'), (r'^1.0/', include('mumbai.apiurls')), # Uncomment the admin/doc line below to enable admin documentation: (r'^admin/doc/', include('django.contrib.admindocs.urls')),