Exemple #1
0
def OnBlipSubmitted(event, wavelet):
  """The map gadget can only be edited when the blip
  is in write mode, so we can safely handle updates
  to the user location in the BlipSubmitted event.
  """
  blip = event.blip

  mapgadget = blip.all(element.Gadget).value()
  coord = None
  for key in mapgadget.keys():
    if key.startswith('overlay-'):
      mapdata = simplejson.loads(getattr(mapgadget, key))
      if mapdata['type'] == 'point':
        coord = mapdata['coordinates'][0]

  profile = Profile.get_or_insert(wavelet.wave_id)
  oldlocation = profile.location
  if coord:
    profile.location = db.GeoPt(coord['lat'], coord['lng']) 
    profile.update_location()
    logging.debug(profile.location)
    if ( oldlocation is None ) or ( oldlocation != profile.location ):
      if oldlocation:
        logging.debug(oldlocation)
      # search for gtugs
      logging.debug(profile.location)
      results = GTUG.proximity_fetch(
          GTUG.all(),
          profile.location,
          max_results=5,
          max_distance=80467
          ) 
      if results:
        gtugblip = blip.reply()
        gtugblip.append_markup("<p>Great news, we found a Google Technology User Group near you!</p>")
        gtugblip.append(element.Line())
        gtugblip.append(element.Line())
        gtugblip.append_markup("<p>The group name is </p>")
        gtugblip.append(results[0].key().name(), [
          ('link/manual', results[0].url)
          ])
  profile.put()
 def post(self): 
   key = self.request.get('key')
   chapters= simplejson.loads(key)
   if chapters:
     chapter = chapters.pop()
     logging.info(chapter)
     gtug = GTUG.get_or_insert(chapter['name'])
     gtug.location = db.GeoPt(chapter['latitude'], chapter['longitude'])
     gtug.update_location()
     gtug.gtugid = chapter['id']
     gtug.url = chapter['url']
     gtug.put()
     taskqueue.add(url='/update-task', params={'key': simplejson.dumps(chapters)})
   else:
     logging.info("Finished adding GTUG chapters via task queue")
Exemple #3
0
 def post(self): # should run at most 1/s
   key = self.request.get('key')
   chapters= simplejson.loads(key)
   if chapters:
     chapter = chapters.pop()
     logging.info(chapter)
     gtug = GTUG.get_or_insert(chapter['name'])
     gtug.location = db.GeoPt(chapter['latitude'], chapter['longitude'])
     gtug.update_location()
     gtug.gtugid = chapter['id']
     gtug.url = chapter['url']
     gtug.put()
     taskqueue.add(url='/update-task', params={'key': simplejson.dumps(chapters)})
   else:
     logging.info("Finished adding GTUG chapters via task queue")