Ejemplo n.º 1
0
 def get(self, server_key=None):
     server = self.get_server_by_key(server_key, abort=False)
     if server is None:
         self.redirect_to_server('chats')
         return
     self.request.user.record_chat_view()
     query_string = self.request.get('q', None)
     # Search
     if query_string:
         page = 0
         cursor = self.request.get('cursor', None)
         if cursor and cursor.startswith('PAGE_'):
             page = int(cursor.strip()[5:])
         offset = page*RESULTS_PER_PAGE
         results, number_found, _ = search.search_log_lines(
             'chat:{0}'.format(query_string),
             server_key=server.key,
             limit=RESULTS_PER_PAGE,
             offset=offset
         )
         previous_cursor = next_cursor = None
         if page > 0:
             previous_cursor = u'PAGE_{0}&q={1}'.format(page - 1 if page > 0 else 0, query_string)
         if number_found > offset + RESULTS_PER_PAGE:
             next_cursor = u'PAGE_{0}&q={1}'.format(page + 1, query_string)
     # Latest
     else:
         results, previous_cursor, next_cursor = self.get_results_with_cursors(
             LogLine.query_latest_events(server.key), LogLine.query_oldest_events(server.key), RESULTS_PER_PAGE
         )
     context = {'chats': results, 'query_string': query_string or ''}
     if self.request.is_xhr:
         self.render_xhr_response(server.key, context, next_cursor)
     else:
         self.render_html_response(server.key, context, next_cursor, previous_cursor)
Ejemplo n.º 2
0
 def get(self, server_key=None):
     server = self.get_server_by_key(server_key, abort=False)
     if server is None:
         self.redirect_to_server('home')
         return
     # Get new chats
     new_chats_query = LogLine.query_latest_events(server.key)
     last_chat_view = self.request.user.last_chat_view
     if last_chat_view is not None:
         new_chats_query = new_chats_query.filter(LogLine.timestamp > last_chat_view)
     new_chats, chats_cursor, more = new_chats_query.fetch_page(20)
     if new_chats:
         self.request.user.record_chat_view(new_chats[0].timestamp)
     # Render with context
     context = {
         'open_sessions': server.open_sessions,
         'new_chats': new_chats,
         'chats_cursor': chats_cursor
     }
     self.render_template('home.html', context=context)
Ejemplo n.º 3
0
 def get(self, server_key=None):
     server = self.get_server_by_key(server_key, abort=False)
     if server is None:
         self.redirect_to_server('home')
         return
     # Get new chats
     new_chats_query = LogLine.query_latest_events(server.key)
     last_chat_view = self.request.user.last_chat_view
     if last_chat_view is not None:
         new_chats_query = new_chats_query.filter(
             LogLine.timestamp > last_chat_view)
     new_chats, chats_cursor, more = new_chats_query.fetch_page(20)
     if new_chats:
         self.request.user.record_chat_view(new_chats[0].timestamp)
     # Render with context
     context = {
         'open_sessions': server.open_sessions,
         'new_chats': new_chats,
         'chats_cursor': chats_cursor
     }
     self.render_template('home.html', context=context)
Ejemplo n.º 4
0
 def get(self, server_key=None):
     server = self.get_server_by_key(server_key, abort=False)
     if server is None:
         self.redirect_to_server('chats')
         return
     self.request.user.record_chat_view()
     query_string = self.request.get('q', None)
     # Search
     if query_string:
         page = 0
         cursor = self.request.get('cursor', None)
         if cursor and cursor.startswith('PAGE_'):
             page = int(cursor.strip()[5:])
         offset = page * RESULTS_PER_PAGE
         results, number_found, _ = search.search_log_lines(
             'chat:{0}'.format(query_string),
             server_key=server.key,
             limit=RESULTS_PER_PAGE,
             offset=offset)
         previous_cursor = next_cursor = None
         if page > 0:
             previous_cursor = u'PAGE_{0}&q={1}'.format(
                 page - 1 if page > 0 else 0, query_string)
         if number_found > offset + RESULTS_PER_PAGE:
             next_cursor = u'PAGE_{0}&q={1}'.format(page + 1, query_string)
     # Latest
     else:
         results, previous_cursor, next_cursor = self.get_results_with_cursors(
             LogLine.query_latest_events(server.key),
             LogLine.query_oldest_events(server.key), RESULTS_PER_PAGE)
     context = {'chats': results, 'query_string': query_string or ''}
     if self.request.is_xhr:
         self.render_xhr_response(server.key, context, next_cursor)
     else:
         self.render_html_response(server.key, context, next_cursor,
                                   previous_cursor)