added api call to edit stop

This commit is contained in:
Sanj 2012-02-19 18:24:28 +05:30
parent fe3c276ec7
commit ebdb732921
2 changed files with 19 additions and 0 deletions

View File

@ -1,5 +1,6 @@
from models import *
from ox.django.shortcuts import get_object_or_404_json, render_to_json_response
from django.contrib.auth.decorators import login_required
def route(request, alias):
@ -12,3 +13,10 @@ def route(request, alias):
'features': stops
}
})
@login_required(request, id):
if not id:
stop = Stop() #FIXME: should this return an error instead?
else:
stop = get_object_or_404_json(Stop, id=id)
return stop.from_geojson(request.POST)

View File

@ -1,4 +1,5 @@
from django.contrib.gis.db import models
from django.contrib.gis.geos import Point
from django import forms
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
@ -123,6 +124,16 @@ class Stop(models.Model):
'geometry': geom
}
def from_geojson(self, geojson):
geom = geojson['geometry']['coordinates']
data = geojson['properties']
self.point = Point(geom[0], geom[1])
self.display_name = data['display_name']
self.name_mr = data['name_mr']
#FIXME: add alt names logic
self.save()
return self.get_geojson()
def __unicode__(self):
return self.name