names
This commit is contained in:
parent
0a139cd1d5
commit
228c612fff
3 changed files with 9 additions and 8 deletions
|
@ -375,6 +375,7 @@ class Item(models.Model):
|
|||
i[key] = value
|
||||
|
||||
#format datetime values
|
||||
# #FIXME: do this in render_tojson
|
||||
for key in i:
|
||||
if isinstance(i[key], datetime):
|
||||
i[key] = i[key].strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import division, with_statement
|
||||
|
||||
from datetime import datetime
|
||||
from django.db import models
|
||||
|
||||
import ox
|
||||
|
@ -34,7 +34,7 @@ class Place(models.Model):
|
|||
east = models.FloatField(default=0)
|
||||
lat = models.FloatField(default=0)
|
||||
lng = models.FloatField(default=0)
|
||||
size = models.FloatField(default=-1)
|
||||
size = models.FloatField(default=0)
|
||||
|
||||
objects = managers.PlaceManager()
|
||||
|
||||
|
@ -52,7 +52,7 @@ class Place(models.Model):
|
|||
def get_id(self):
|
||||
return ox.to32(self.id)
|
||||
|
||||
def json(self):
|
||||
def json(self, user=None):
|
||||
j = {
|
||||
'id': self.get_id(),
|
||||
'user': self.user.username,
|
||||
|
@ -62,6 +62,9 @@ class Place(models.Model):
|
|||
'south', 'west', 'north', 'east',
|
||||
'lat', 'lng', 'size'):
|
||||
j[key] = getattr(self, key)
|
||||
|
||||
if isinstance(j[key], datetime):
|
||||
j[key] = j[key].strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
return j
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
|
|
@ -32,7 +32,7 @@ def addPlace(request):
|
|||
'''
|
||||
data = json.loads(request.POST['data'])
|
||||
exists = False
|
||||
names = data['name']
|
||||
names = data.pop('name')
|
||||
if isinstance(names, basestring):
|
||||
names = [names]
|
||||
for name in names:
|
||||
|
@ -41,6 +41,7 @@ def addPlace(request):
|
|||
if not exists:
|
||||
place = models.Place()
|
||||
place.user = request.user
|
||||
place.name = tuple(names)
|
||||
for key in data:
|
||||
setattr(place, key, data[key])
|
||||
place.save()
|
||||
|
@ -193,9 +194,5 @@ Positions
|
|||
response['data']['positions'] = utils.get_positions(ids, query['ids'])
|
||||
else:
|
||||
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)
|
||||
actions.register(findPlaces)
|
||||
|
|
Loading…
Reference in a new issue