Refactoring

This commit is contained in:
Michael Lazar
2017-08-31 10:26:04 -04:00
parent 4bad3000e4
commit 03ef3c254d

View File

@@ -522,25 +522,20 @@ class SubredditContent(Content):
period = None period = None
if query: if query:
# The allowed order for sorting search results # The allowed orders for sorting search results are different
if order not in ['relevance', 'top', 'comments', 'new', None]: orders = ['relevance', 'top', 'comments', 'new', None]
raise InvalidSubreddit('Invalid order `%s`' % order) period_allowed = ['top', 'comments']
else: else:
if order not in ['hot', 'top', 'rising', 'new', 'controversial', None]: orders = ['hot', 'top', 'rising', 'new', 'controversial', None]
raise InvalidSubreddit('Invalid order `%s`' % order) period_allowed = ['top', 'controversial']
if order not in orders:
raise InvalidSubreddit('Invalid order `%s`' % order)
if period not in ['all', 'day', 'hour', 'month', 'week', 'year', None]: if period not in ['all', 'day', 'hour', 'month', 'week', 'year', None]:
raise InvalidSubreddit('Invalid period `%s`' % period) raise InvalidSubreddit('Invalid period `%s`' % period)
if period and order not in period_allowed:
if query: raise InvalidSubreddit(
# The allowed order for sorting search results '`%s` order does not allow sorting by period' % order)
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 # On some objects, praw doesn't allow you to pass arguments for the
# order and period. Instead you need to call special helper functions # order and period. Instead you need to call special helper functions