def OnDocumentChanged(event, wavelet): blip = event.blip interests = [] for e in blip.elements: if isinstance(e, element.Check): if e.value == 'true': interests.append(e.name) fullname = '' nameinput = blip.first(element.Input, name='fullname') if nameinput: fullname = nameinput.get('value','') profile = Profile.get_or_insert(wavelet.wave_id) profile.name = fullname profile.creator = wavelet.creator profile.interests = interests profile.put()
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()