first step toward editstops

This commit is contained in:
Sanj 2012-02-20 18:58:22 +05:30
parent 9d2648e33c
commit caafe71240
7 changed files with 91 additions and 3 deletions

View File

@ -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()

View File

@ -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)

View File

View File

@ -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 = $('<li />')
.addClass("listItem")
.text(v)
.appendTo($list);
});
}, "json");
}
$('.listWrapper').hide();
$listWrapper.show();
$('.selected').removeClass("selected");
$that.addClass("selected");
});
});

View File

@ -1,6 +1,7 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript" src="/static/js/jquery-1.7.1.min.js"></script>
<title>ChaloBEST: {% block title %} {% endblock %}</title>
{% block head %}

View File

@ -0,0 +1,39 @@
{% extends 'base.html' %}
{% block head %}
<link rel="stylesheet" href="/static/css/editstops.css" />
<script type="text/javascript" src="/static/js/editstops.js"></script>
{% endblock %}
{% block body %}
<div id="listCol">
<div id="tabButtons">
<div id="areasTabBtn" class="tabButton" data-name="areas">
Areas
</div>
<div id="routesTabBtn" class="tabButton" data-name="routes">
Routes
</div>
</div>
<div id="listsWrapper">
<div id="areas" class="listWrapper">
<input type="text" id="areasSearch" class="listSearch" />
<ul id="areasList">
</ul>
</div>
<div id="routes" class="listWrapper">
<input type="text" id="routesSearch" class="listSearch" />
<ul id="routesList">
</ul>
</div>
</div>
</div>
<div id="mapCol">
</div>
<div id="formCol">
</div>
{% endblock %}

View File

@ -17,6 +17,7 @@ urlpatterns = patterns('',
(r'^route/(?P<alias>[a-zA-Z0-9\s\-]*?)/$', 'mumbai.views.route'),
(r'^areas/$', 'mumbai.views.areas'),
(r'^area/(?P<name>.*?)/$', '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')),