def put(self, lat, lng): logging.debug(self.request.body) kwargs = json.loads(self.request.body) if not kwargs.get('address'): kwargs['address'] = util.lookup_address(lat, lng) portal, created = models.Portal.get_or_insert(added_by=self.user, **kwargs) if created: # Add it to the cached JSON list of all portals. portals_json = memcache_chunker.get('portals') if portals_json is not None: portals = json.loads(portals_json) portals.append(portal) memcache_chunker.set('portals', json.dumps( portals, cls=PortalJSONEncoder)) if kwargs.get('watched'): xmpp.send_invite(self.user.email) if self.user.key() not in portal.subscribers: portal.subscribers.append(self.user.key()) else: try: portal.subscribers.remove(self.user.key()) except ValueError: pass portal.put() memcache.delete('watched-portals|%s' % self.user.key())
def put(self, lat, lng): logging.debug(self.request.body) kwargs = json.loads(self.request.body) if not kwargs.get('address'): kwargs['address'] = util.lookup_address(lat, lng) portal, created = models.Portal.get_or_insert(added_by=self.user, **kwargs) if created: # Add it to the cached JSON list of all portals. portals_json = memcache_chunker.get('portals') if portals_json is not None: portals = json.loads(portals_json) portals.append(portal) memcache_chunker.set( 'portals', json.dumps(portals, cls=PortalJSONEncoder)) if kwargs.get('watched'): xmpp.send_invite(self.user.email) if self.user.key() not in portal.subscribers: portal.subscribers.append(self.user.key()) else: try: portal.subscribers.remove(self.user.key()) except ValueError: pass portal.put() memcache.delete('watched-portals|%s' % self.user.key())
def get(self): self.response.headers['Content-Type'] = 'application/json' portals_query = models.Portal.all() if self.request.get('watched'): key = 'watched-portals|%s' % self.user.key() portals_json = memcache.get(key) if not portals_json: portals_query.filter('subscribers', self.user.key()) portals_json = json.dumps( portals_query.run(batch_size=1000), cls=PortalJSONEncoder) memcache.set(key, portals_json) else: key = 'portals' portals_json = memcache_chunker.get(key) if not portals_json: logging.info('Pulling portals from datastore') portals_json = json.dumps( portals_query.run(batch_size=1000), cls=PortalJSONEncoder) memcache_chunker.set(key, portals_json) self.response.out.write(")]}',\n" + portals_json)
def get(self): self.response.headers['Content-Type'] = 'application/json' portals_query = models.Portal.all() if self.request.get('watched'): key = 'watched-portals|%s' % self.user.key() portals_json = memcache.get(key) if not portals_json: portals_query.filter('subscribers', self.user.key()) portals_json = json.dumps(portals_query.run(batch_size=1000), cls=PortalJSONEncoder) memcache.set(key, portals_json) else: key = 'portals' portals_json = memcache_chunker.get(key) if not portals_json: logging.info('Pulling portals from datastore') portals_json = json.dumps(portals_query.run(batch_size=1000), cls=PortalJSONEncoder) memcache_chunker.set(key, portals_json) self.response.out.write(")]}',\n" + portals_json)