Adding the search term to the title bar, removing with_search argument
This commit is contained in:
@@ -326,6 +326,7 @@ class SubmissionContent(Content):
|
|||||||
self.max_indent_level = max_indent_level
|
self.max_indent_level = max_indent_level
|
||||||
self.name = submission_data['permalink']
|
self.name = submission_data['permalink']
|
||||||
self.order = order
|
self.order = order
|
||||||
|
self.query = None
|
||||||
self._loader = loader
|
self._loader = loader
|
||||||
self._submission = submission
|
self._submission = submission
|
||||||
self._submission_data = submission_data
|
self._submission_data = submission_data
|
||||||
@@ -662,6 +663,7 @@ class SubscriptionContent(Content):
|
|||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
self.order = None
|
self.order = None
|
||||||
|
self.query = None
|
||||||
self._loader = loader
|
self._loader = loader
|
||||||
self._subscriptions = subscriptions
|
self._subscriptions = subscriptions
|
||||||
self._subscription_data = []
|
self._subscription_data = []
|
||||||
|
|||||||
12
rtv/page.py
12
rtv/page.py
@@ -56,7 +56,7 @@ class Page(object):
|
|||||||
self._row = 0
|
self._row = 0
|
||||||
self._subwindows = None
|
self._subwindows = None
|
||||||
|
|
||||||
def refresh_content(self, order=None, name=None, with_search=False):
|
def refresh_content(self, order=None, name=None):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def _draw_item(self, window, data, inverted):
|
def _draw_item(self, window, data, inverted):
|
||||||
@@ -118,7 +118,7 @@ class Page(object):
|
|||||||
self.term.show_notification('Invalid option')
|
self.term.show_notification('Invalid option')
|
||||||
return
|
return
|
||||||
|
|
||||||
self.refresh_content(order=choices[ch], with_search=True)
|
self.refresh_content(order=choices[ch])
|
||||||
|
|
||||||
@PageController.register(Command('SORT_RISING'))
|
@PageController.register(Command('SORT_RISING'))
|
||||||
def sort_content_rising(self):
|
def sort_content_rising(self):
|
||||||
@@ -126,7 +126,7 @@ class Page(object):
|
|||||||
|
|
||||||
@PageController.register(Command('SORT_NEW'))
|
@PageController.register(Command('SORT_NEW'))
|
||||||
def sort_content_new(self):
|
def sort_content_new(self):
|
||||||
self.refresh_content(order='new', with_search=True)
|
self.refresh_content(order='new')
|
||||||
|
|
||||||
@PageController.register(Command('SORT_CONTROVERSIAL'))
|
@PageController.register(Command('SORT_CONTROVERSIAL'))
|
||||||
def sort_content_controversial(self):
|
def sort_content_controversial(self):
|
||||||
@@ -147,7 +147,7 @@ class Page(object):
|
|||||||
self.term.show_notification('Invalid option')
|
self.term.show_notification('Invalid option')
|
||||||
return
|
return
|
||||||
|
|
||||||
self.refresh_content(order=choices[ch], with_search=True)
|
self.refresh_content(order=choices[ch])
|
||||||
|
|
||||||
@PageController.register(Command('MOVE_UP'))
|
@PageController.register(Command('MOVE_UP'))
|
||||||
def move_cursor_up(self):
|
def move_cursor_up(self):
|
||||||
@@ -408,6 +408,10 @@ class Page(object):
|
|||||||
sub_name = sub_name.replace('/r/front', 'Front Page')
|
sub_name = sub_name.replace('/r/front', 'Front Page')
|
||||||
sub_name = sub_name.replace('/u/me', 'My Submissions')
|
sub_name = sub_name.replace('/u/me', 'My Submissions')
|
||||||
sub_name = sub_name.replace('/u/saved', 'My Saved Submissions')
|
sub_name = sub_name.replace('/u/saved', 'My Saved Submissions')
|
||||||
|
|
||||||
|
query = self.content.query
|
||||||
|
if query:
|
||||||
|
sub_name = 'Searching {0}: {1}'.format(sub_name, query)
|
||||||
self.term.add_line(window, sub_name, 0, 0)
|
self.term.add_line(window, sub_name, 0, 0)
|
||||||
|
|
||||||
# Set the terminal title
|
# Set the terminal title
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class SubmissionPage(Page):
|
|||||||
self.active = False
|
self.active = False
|
||||||
|
|
||||||
@SubmissionController.register(Command('REFRESH'))
|
@SubmissionController.register(Command('REFRESH'))
|
||||||
def refresh_content(self, order=None, name=None, with_search=False):
|
def refresh_content(self, order=None, name=None):
|
||||||
"Re-download comments and reset the page index"
|
"Re-download comments and reset the page index"
|
||||||
|
|
||||||
order = order or self.content.order
|
order = order or self.content.order
|
||||||
|
|||||||
@@ -36,12 +36,18 @@ class SubredditPage(Page):
|
|||||||
self.toggled_subreddit = None
|
self.toggled_subreddit = None
|
||||||
|
|
||||||
@SubredditController.register(Command('REFRESH'))
|
@SubredditController.register(Command('REFRESH'))
|
||||||
def refresh_content(self, order=None, name=None, with_search=False):
|
def refresh_content(self, order=None, name=None):
|
||||||
"Re-download all submissions and reset the page index"
|
"Re-download all submissions and reset the page index"
|
||||||
|
|
||||||
order = order or self.content.order
|
order = order or self.content.order
|
||||||
|
|
||||||
|
# Preserve the query if staying on the current page
|
||||||
|
if name is None:
|
||||||
|
query = self.content.query
|
||||||
|
else:
|
||||||
|
query = None
|
||||||
|
|
||||||
name = name or self.content.name
|
name = name or self.content.name
|
||||||
query = self.content.query if with_search else None
|
|
||||||
|
|
||||||
# Hack to allow an order specified in the name by prompt_subreddit() to
|
# Hack to allow an order specified in the name by prompt_subreddit() to
|
||||||
# override the current default
|
# override the current default
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class SubscriptionPage(Page):
|
|||||||
self.selected_subreddit = None
|
self.selected_subreddit = None
|
||||||
|
|
||||||
@SubscriptionController.register(Command('REFRESH'))
|
@SubscriptionController.register(Command('REFRESH'))
|
||||||
def refresh_content(self, order=None, name=None, with_search=False):
|
def refresh_content(self, order=None, name=None):
|
||||||
"Re-download all subscriptions and reset the page index"
|
"Re-download all subscriptions and reset the page index"
|
||||||
|
|
||||||
# reddit.get_my_subreddits() does not support sorting by order
|
# reddit.get_my_subreddits() does not support sorting by order
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class Terminal(object):
|
|||||||
self.loader = LoadScreen(self)
|
self.loader = LoadScreen(self)
|
||||||
self._display = None
|
self._display = None
|
||||||
self._mailcap_dict = mailcap.getcaps()
|
self._mailcap_dict = mailcap.getcaps()
|
||||||
self._term = os.environ['TERM']
|
self._term = os.environ.get('TERM')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def up_arrow(self):
|
def up_arrow(self):
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -81,7 +81,7 @@ def test_page_unauthenticated(reddit, terminal, config, oauth):
|
|||||||
page.controller.trigger('3')
|
page.controller.trigger('3')
|
||||||
page.refresh_content.assert_called_with(order='rising')
|
page.refresh_content.assert_called_with(order='rising')
|
||||||
page.controller.trigger('4')
|
page.controller.trigger('4')
|
||||||
page.refresh_content.assert_called_with(order='new', with_search=True)
|
page.refresh_content.assert_called_with(order='new')
|
||||||
|
|
||||||
logged_in_methods = [
|
logged_in_methods = [
|
||||||
'a', # Upvote
|
'a', # Upvote
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ def test_subreddit_title(subreddit_page, terminal, capsys):
|
|||||||
|
|
||||||
|
|
||||||
def test_subreddit_search(subreddit_page, terminal):
|
def test_subreddit_search(subreddit_page, terminal):
|
||||||
|
window = terminal.stdscr.subwin
|
||||||
|
|
||||||
# Search the current subreddit
|
# Search the current subreddit
|
||||||
with mock.patch.object(terminal, 'prompt_input'):
|
with mock.patch.object(terminal, 'prompt_input'):
|
||||||
@@ -96,12 +97,31 @@ def test_subreddit_search(subreddit_page, terminal):
|
|||||||
assert terminal.prompt_input.called
|
assert terminal.prompt_input.called
|
||||||
assert not terminal.loader.exception
|
assert not terminal.loader.exception
|
||||||
|
|
||||||
|
# The page title should display the query
|
||||||
|
subreddit_page.draw()
|
||||||
|
title = 'Searching /r/python: search term'.encode('utf-8')
|
||||||
|
window.addstr.assert_any_call(0, 0, title)
|
||||||
|
|
||||||
|
# Ordering the results should preserve the query
|
||||||
|
window.addstr.reset_mock()
|
||||||
|
subreddit_page.refresh_content(order='hot')
|
||||||
|
subreddit_page.refresh_content(order='top-all')
|
||||||
|
subreddit_page.refresh_content(order='new')
|
||||||
|
assert subreddit_page.content.name == '/r/python'
|
||||||
|
assert subreddit_page.content.query == 'search term'
|
||||||
|
assert not terminal.loader.exception
|
||||||
|
|
||||||
# Searching with an empty query shouldn't crash
|
# Searching with an empty query shouldn't crash
|
||||||
with mock.patch.object(terminal, 'prompt_input'):
|
with mock.patch.object(terminal, 'prompt_input'):
|
||||||
terminal.prompt_input.return_value = None
|
terminal.prompt_input.return_value = None
|
||||||
subreddit_page.controller.trigger('f')
|
subreddit_page.controller.trigger('f')
|
||||||
assert not terminal.loader.exception
|
assert not terminal.loader.exception
|
||||||
|
|
||||||
|
# Changing to a new subreddit should clear the query
|
||||||
|
window.addstr.reset_mock()
|
||||||
|
subreddit_page.refresh_content(name='/r/learnpython')
|
||||||
|
assert subreddit_page.content.query is None
|
||||||
|
|
||||||
|
|
||||||
def test_subreddit_prompt(subreddit_page, terminal):
|
def test_subreddit_prompt(subreddit_page, terminal):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user