From d01393e4b43cd98d25c705d6882a207b8806c292 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sun, 1 Feb 2015 21:19:01 -0800 Subject: [PATCH] Increased stability for self posts. Still more work to be done. --- rtv/content.py | 26 +++++++++++++------------- rtv/page.py | 11 +++++++---- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/rtv/content.py b/rtv/content.py index 6c9515c..d8c66f9 100644 --- a/rtv/content.py +++ b/rtv/content.py @@ -55,6 +55,18 @@ def default_loader(self): class BaseContent(object): + def get(self, index, n_cols): + raise NotImplementedError + + def iterate(self, index, step, n_cols): + + while True: + try: + yield self.get(index, n_cols) + except IndexError: + break + index += step + @staticmethod def flatten_comments(comments, root_level=0): """ @@ -251,12 +263,6 @@ class SubmissionContent(BaseContent): else: raise ValueError('% type not recognized' % data['type']) - def iterate(self, index, step, n_cols=70): - - while True: - yield self.get(index, n_cols=n_cols) - index += step - class SubredditContent(BaseContent): """ @@ -315,10 +321,4 @@ class SubredditContent(BaseContent): data['n_rows'] = len(data['split_title']) + 3 data['offset'] = 0 - return data - - def iterate(self, index, step, n_cols): - - while True: - yield self.get(index, n_cols) - index += step \ No newline at end of file + return data \ No newline at end of file diff --git a/rtv/page.py b/rtv/page.py index e17bad0..161d02a 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -41,10 +41,13 @@ class Navigator(object): if forward: if self.page_index < 0: - # Special case - advance the page index if less than zero - self.page_index = 0 - self.cursor_index = 0 - redraw = True + if self._is_valid(0): + # Special case - advance the page index if less than zero + self.page_index = 0 + self.cursor_index = 0 + redraw = True + else: + valid = False else: self.cursor_index += 1 if self.cursor_index >= n_windows - 1: