diff --git a/pandora/event/models.py b/pandora/event/models.py index 26f65a51a..5333faf2f 100644 --- a/pandora/event/models.py +++ b/pandora/event/models.py @@ -5,6 +5,7 @@ from __future__ import division, with_statement from django.db import models from django.contrib.auth.models import User, Group +import ox from ox.django import fields import managers @@ -46,11 +47,16 @@ class Event(models.Model): self.name_find = self.name + '||'.join(self.alternativeNames) super(Event, self).save(*args, **kwargs) - def json(self): - return { - 'name': self.name, - 'alternativeNames': self.alternativeNames, - 'start': self.start, - 'end': self.end, - 'type': self.type + def get_id(self): + return ox.to32(self.id) + + def json(self, user=None): + j = { + 'id': self.get_id(), + 'user': self.user.username, } + for key in ('created', 'modified', + 'name', 'alternativeNames', 'start', 'end', + 'type'): + j[key] = getattr(self, key) + return j diff --git a/pandora/event/views.py b/pandora/event/views.py index aef32d7ba..c7db5e8df 100644 --- a/pandora/event/views.py +++ b/pandora/event/views.py @@ -89,7 +89,7 @@ def removeEvent(request): actions.register(removeEvent, cache=False) -def findEvent(request): +def findEvents(request): ''' param data {'query': query, 'sort': array, 'range': array} @@ -128,4 +128,4 @@ Positions for p in models.Event.objects.find(data['query']): response['data']['events'].append(p.json()) return render_to_json_response(response) -actions.register(findEvent) +actions.register(findEvents) diff --git a/pandora/place/models.py b/pandora/place/models.py index beace7898..eadd25c61 100644 --- a/pandora/place/models.py +++ b/pandora/place/models.py @@ -19,7 +19,7 @@ class Place(models.Model): user = models.ForeignKey(User, null=True, related_name='places') name = models.CharField(max_length=1024) - aliases = fields.TupleField(default=[]) + alternativeNames = fields.TupleField(default=[]) name_sort = models.CharField(max_length=200) name_find = models.TextField(default='', editable=False) @@ -36,7 +36,7 @@ class Place(models.Model): east = models.FloatField(default=0) lat = models.FloatField(default=0) lng = models.FloatField(default=0) - size = models.FloatField(default=0) + area = models.FloatField(default=0) matches = models.IntegerField(default=0) @@ -62,9 +62,9 @@ class Place(models.Model): 'user': self.user.username, } for key in ('created', 'modified', - 'name', 'aliases', 'geoname', 'countryCode', + 'name', 'alternativeNames', 'geoname', 'countryCode', 'south', 'west', 'north', 'east', - 'lat', 'lng', 'size', 'matches', 'type'): + 'lat', 'lng', 'area', 'matches', 'type'): j[key] = getattr(self, key) return j @@ -72,13 +72,13 @@ class Place(models.Model): if not self.name_sort: self.name_sort = self.name #', '.join(self.name) self.geoname_sort = ', '.join(reversed(self.geoname.split(', '))) - self.name_find = '|%s|'%'|'.join([self.name]+list(self.aliases)) + self.name_find = '|%s|'%'|'.join([self.name]+list(self.alternativeNames)) #update center #self.lat = ox.location.center(self.south, self.north) #self.lng = ox.location.center(self.east, self.west) #update area - #self.size = ox.location.area(self.south, self.west, self.north, self.east) + #self.area= ox.location.area(self.south, self.west, self.north, self.east) super(Place, self).save(*args, **kwargs) diff --git a/pandora/place/views.py b/pandora/place/views.py index 2b593b916..fcd062171 100644 --- a/pandora/place/views.py +++ b/pandora/place/views.py @@ -2,6 +2,8 @@ # vi:si:et:sw=4:sts=4:ts=4 from __future__ import division +from django.db.models import Max, Min + import ox from ox.utils import json @@ -29,7 +31,7 @@ def addPlace(request): east: float, lat: float, lng: float, - size: float, + area: float, } ''' data = json.loads(request.POST['data']) @@ -221,5 +223,15 @@ Positions response['data']['positions'] = utils.get_positions(ids, query['ids']) else: response['data']['items'] = qs.count() + ''' + r = qs.aggregate( + Min('south'), + Min('west'), + Max('north'), + Max('east'), + ) + print r + ''' + response['data']['area'] = {'south': -180.0, 'west': -180.0, 'north': 180.0, 'east': 180.0} return render_to_json_response(response) actions.register(findPlaces)