This commit is contained in:
rlx 2011-02-24 19:22:20 +00:00
parent c9459265ca
commit 9bdf9b565b
3 changed files with 9 additions and 8 deletions

View file

@ -375,6 +375,7 @@ class Item(models.Model):
i[key] = value i[key] = value
#format datetime values #format datetime values
# #FIXME: do this in render_tojson
for key in i: for key in i:
if isinstance(i[key], datetime): if isinstance(i[key], datetime):
i[key] = i[key].strftime('%Y-%m-%dT%H:%M:%SZ') i[key] = i[key].strftime('%Y-%m-%dT%H:%M:%SZ')

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4 # vi:si:et:sw=4:sts=4:ts=4
from __future__ import division, with_statement from __future__ import division, with_statement
from datetime import datetime
from django.db import models from django.db import models
import ox import ox
@ -34,7 +34,7 @@ class Place(models.Model):
east = models.FloatField(default=0) east = models.FloatField(default=0)
lat = models.FloatField(default=0) lat = models.FloatField(default=0)
lng = models.FloatField(default=0) lng = models.FloatField(default=0)
size = models.FloatField(default=-1) size = models.FloatField(default=0)
objects = managers.PlaceManager() objects = managers.PlaceManager()
@ -52,7 +52,7 @@ class Place(models.Model):
def get_id(self): def get_id(self):
return ox.to32(self.id) return ox.to32(self.id)
def json(self): def json(self, user=None):
j = { j = {
'id': self.get_id(), 'id': self.get_id(),
'user': self.user.username, 'user': self.user.username,
@ -62,6 +62,9 @@ class Place(models.Model):
'south', 'west', 'north', 'east', 'south', 'west', 'north', 'east',
'lat', 'lng', 'size'): 'lat', 'lng', 'size'):
j[key] = getattr(self, key) j[key] = getattr(self, key)
if isinstance(j[key], datetime):
j[key] = j[key].strftime('%Y-%m-%dT%H:%M:%SZ')
return j return j
def save(self, *args, **kwargs): def save(self, *args, **kwargs):

View file

@ -32,7 +32,7 @@ def addPlace(request):
''' '''
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
exists = False exists = False
names = data['name'] names = data.pop('name')
if isinstance(names, basestring): if isinstance(names, basestring):
names = [names] names = [names]
for name in names: for name in names:
@ -41,6 +41,7 @@ def addPlace(request):
if not exists: if not exists:
place = models.Place() place = models.Place()
place.user = request.user place.user = request.user
place.name = tuple(names)
for key in data: for key in data:
setattr(place, key, data[key]) setattr(place, key, data[key])
place.save() place.save()
@ -193,9 +194,5 @@ Positions
response['data']['positions'] = utils.get_positions(ids, query['ids']) response['data']['positions'] = utils.get_positions(ids, query['ids'])
else: else:
response['data']['items'] = qs.count() response['data']['items'] = qs.count()
response['data']['items'] = []
#FIXME: add coordinates to limit search
for p in models.Place.objects.find(data['query']):
response['data']['items'].append(p.json())
return render_to_json_response(response) return render_to_json_response(response)
actions.register(findPlaces) actions.register(findPlaces)