From 228c612fffe7f5e08ece07991d58260de08c333a Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 24 Feb 2011 19:22:20 +0000 Subject: [PATCH] names --- pandora/item/models.py | 1 + pandora/place/models.py | 9 ++++++--- pandora/place/views.py | 7 ++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 6866ec93..bf299a1a 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -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') diff --git a/pandora/place/models.py b/pandora/place/models.py index ef5228fd..ca686120 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -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): diff --git a/pandora/place/views.py b/pandora/place/views.py index 5a64e0c7..e25e5b21 100644 --- a/pandora/place/views.py +++ b/pandora/place/views.py @@ -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)