forked from 0x2620/pandora
names
This commit is contained in:
parent
fe2163064d
commit
dc5c9607f7
4 changed files with 34 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue