Updating sorting options for search results
This commit is contained in:
@@ -478,7 +478,7 @@ class SubredditContent(Content):
|
||||
query (text): Content to search for on the given subreddit or
|
||||
user's page.
|
||||
"""
|
||||
# TODO: refactor this into smaller methods
|
||||
# TODO: This desperately needs to be refactored
|
||||
|
||||
# Strip leading, trailing, and redundant backslashes
|
||||
parts = [seg for seg in name.strip(' /').split('/') if seg]
|
||||
@@ -521,13 +521,26 @@ class SubredditContent(Content):
|
||||
else:
|
||||
period = None
|
||||
|
||||
if order not in ['hot', 'top', 'rising', 'new', 'controversial', None]:
|
||||
raise InvalidSubreddit('Invalid order `%s`' % order)
|
||||
if query:
|
||||
# The allowed order for sorting search results
|
||||
if order not in ['relevance', 'top', 'comments', 'new', None]:
|
||||
raise InvalidSubreddit('Invalid order `%s`' % order)
|
||||
else:
|
||||
if order not in ['hot', 'top', 'rising', 'new', 'controversial', None]:
|
||||
raise InvalidSubreddit('Invalid order `%s`' % order)
|
||||
|
||||
if period not in ['all', 'day', 'hour', 'month', 'week', 'year', None]:
|
||||
raise InvalidSubreddit('Invalid period `%s`' % period)
|
||||
if period and order not in ['top', 'controversial']:
|
||||
raise InvalidSubreddit('`%s` order does not allow sorting by'
|
||||
' period' % order)
|
||||
|
||||
if query:
|
||||
# The allowed order for sorting search results
|
||||
if period and order not in ['top', 'comments']:
|
||||
raise InvalidSubreddit('`%s` order does not allow sorting by'
|
||||
' period' % order)
|
||||
else:
|
||||
if period and order not in ['top', 'controversial']:
|
||||
raise InvalidSubreddit('`%s` order does not allow sorting by'
|
||||
' period' % order)
|
||||
|
||||
# On some objects, praw doesn't allow you to pass arguments for the
|
||||
# order and period. Instead you need to call special helper functions
|
||||
|
||||
Reference in New Issue
Block a user