Merge branch 'woorst-search_sorting'
This commit is contained in:
@@ -326,6 +326,7 @@ class SubmissionContent(Content):
|
||||
self.max_indent_level = max_indent_level
|
||||
self.name = submission_data['permalink']
|
||||
self.order = order
|
||||
self.query = None
|
||||
self._loader = loader
|
||||
self._submission = submission
|
||||
self._submission_data = submission_data
|
||||
@@ -435,10 +436,12 @@ class SubredditContent(Content):
|
||||
list for repeat access.
|
||||
"""
|
||||
|
||||
def __init__(self, name, submissions, loader, order=None, max_title_rows=4):
|
||||
def __init__(self, name, submissions, loader, order=None,
|
||||
max_title_rows=4, query=None):
|
||||
|
||||
self.name = name
|
||||
self.order = order
|
||||
self.query = query
|
||||
self.max_title_rows = max_title_rows
|
||||
self._loader = loader
|
||||
self._submissions = submissions
|
||||
@@ -603,7 +606,8 @@ class SubredditContent(Content):
|
||||
display_name = '/r/{0}'.format(subreddit.display_name)
|
||||
|
||||
# We made it!
|
||||
return cls(display_name, submissions, loader, order=display_order)
|
||||
return cls(display_name, submissions, loader, order=display_order,
|
||||
query=query)
|
||||
|
||||
@property
|
||||
def range(self):
|
||||
@@ -659,6 +663,7 @@ class SubscriptionContent(Content):
|
||||
|
||||
self.name = name
|
||||
self.order = None
|
||||
self.query = None
|
||||
self._loader = loader
|
||||
self._subscriptions = subscriptions
|
||||
self._subscription_data = []
|
||||
|
||||
@@ -408,6 +408,10 @@ class Page(object):
|
||||
sub_name = sub_name.replace('/r/front', 'Front Page')
|
||||
sub_name = sub_name.replace('/u/me', 'My 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)
|
||||
|
||||
# Set the terminal title
|
||||
|
||||
@@ -40,6 +40,13 @@ class SubredditPage(Page):
|
||||
"Re-download all submissions and reset the page index"
|
||||
|
||||
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
|
||||
|
||||
# Hack to allow an order specified in the name by prompt_subreddit() to
|
||||
@@ -49,7 +56,7 @@ class SubredditPage(Page):
|
||||
|
||||
with self.term.loader('Refreshing page'):
|
||||
self.content = SubredditContent.from_name(
|
||||
self.reddit, name, self.term.loader, order=order)
|
||||
self.reddit, name, self.term.loader, order=order, query=query)
|
||||
if not self.term.loader.exception:
|
||||
self.nav = Navigator(self.content.get)
|
||||
|
||||
@@ -290,4 +297,4 @@ class SubredditPage(Page):
|
||||
self.term.add_line(win, text, attr=Color.YELLOW)
|
||||
if data['flair']:
|
||||
text = ' {flair}'.format(**data)
|
||||
self.term.add_line(win, text, attr=Color.RED)
|
||||
self.term.add_line(win, text, attr=Color.RED)
|
||||
|
||||
@@ -59,7 +59,7 @@ class Terminal(object):
|
||||
self.loader = LoadScreen(self)
|
||||
self._display = None
|
||||
self._mailcap_dict = mailcap.getcaps()
|
||||
self._term = os.environ['TERM']
|
||||
self._term = os.environ.get('TERM')
|
||||
|
||||
@property
|
||||
def up_arrow(self):
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -119,4 +119,4 @@ def test_page_authenticated(reddit, terminal, config, oauth, refresh_token):
|
||||
# Logout
|
||||
terminal.stdscr.getch.return_value = ord('y')
|
||||
page.controller.trigger('u')
|
||||
assert not reddit.is_oauth_session()
|
||||
assert not reddit.is_oauth_session()
|
||||
|
||||
@@ -87,6 +87,7 @@ def test_subreddit_title(subreddit_page, terminal, capsys):
|
||||
|
||||
|
||||
def test_subreddit_search(subreddit_page, terminal):
|
||||
window = terminal.stdscr.subwin
|
||||
|
||||
# Search the current subreddit
|
||||
with mock.patch.object(terminal, 'prompt_input'):
|
||||
@@ -96,12 +97,31 @@ def test_subreddit_search(subreddit_page, terminal):
|
||||
assert terminal.prompt_input.called
|
||||
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
|
||||
with mock.patch.object(terminal, 'prompt_input'):
|
||||
terminal.prompt_input.return_value = None
|
||||
subreddit_page.controller.trigger('f')
|
||||
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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user