Source

GtugGoSandbox / mapgame / position.py

Full commit
from google.appengine.ext import webapp
from google.appengine.api import users
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.db import GeoPt
from django.utils import simplejson as json
from models import Player
from models import Location


class Position(webapp.RequestHandler):
    def post(self):
        user = user.get_current_user()
        player = Player.get('player =',user.email)
        x_point = self.request.get('x_point')
        y_point = self.request.get('y_point')
        l = Location()
        l.x_pt = float(x_point)
        l.y_pt = float(y_point)
        l.put()
        output = []
        output.append(
            approximate_post(l.x_pt,l.x_pt-5.0,'x_pt <','x_pt >')
        )
        output.append(
            approximate_post(l.x_pt+5,l.x_pt,'x_pt >','x_pt <')
        )
        output.append(
            approximate_post(l.y_pt,l.y_pt-5.0,'y_pt <','y_pt >')
        )
        output.append(
            approximate_post(l.y_pt+5,l.y_pt,'y_pt >','y_pt <')
        )
        self.response.out.write(json.loads(output))     
        
def approximate_post(x_pt1,x_pt2,query1,query2):
    output = []
    nl = db.Query(Location)
    nl.filter(query1,x_pt1)
    nl.filter(query2,x_pt2)
    for i in nl.fetch(limit=5):
        temp = {}
        temp['location'] = i.player.player.email
        temp['position'] = [i.x_pt,i.y_pt]
        output.append(temp)
    return output