Created
September 13, 2012 16:09
-
-
Save rweeks/3715400 to your computer and use it in GitHub Desktop.
StreamHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StreamHandler(SessionAwareWSHandler): | |
@property | |
def feed_id(self): | |
return str(self.current_user.id) if self.current_user is not None else self.get_session_id() | |
def _set_earliest_tile(self, timestamp): | |
self.session.set_view_position(timestamp) | |
self.save_session() | |
def _reverse_query_set(self, qs): | |
""" | |
Reverses a query set, returning a collection object. | |
Not refactored as a common function because it's a f!cking kludge. | |
""" | |
result = collections.deque() | |
for q in qs: result.appendleft(q) | |
return result | |
def open(self): | |
self.application.sub_user_tilefeed(self.feed_id, self.on_new_tile) | |
def on_close(self): | |
self.application.unsub_user_tilefeed(self.feed_id, self.on_new_tile) | |
def on_new_tile(self, tile_id): | |
tile = Tile.get_front(tile_id) | |
msg = dict(tiles=[tile], source='tilestream') | |
self.write_message(json.dumps(obj=msg, default=tiles_json.lossy_encode)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment