Refactoring

This commit is contained in:
Michael Lazar
2017-08-31 09:19:41 -04:00
parent c77cf89d16
commit 4bad3000e4

View File

@@ -104,46 +104,20 @@ class Page(object):
@PageController.register(Command('SORT_TOP')) @PageController.register(Command('SORT_TOP'))
def sort_content_top(self): def sort_content_top(self):
order = self._prompt_period('top')
choices = { if order is None:
'\n': 'top',
'1': 'top-hour',
'2': 'top-day',
'3': 'top-week',
'4': 'top-month',
'5': 'top-year',
'6': 'top-all'}
message = docs.TIME_ORDER_MENU.strip().splitlines()
ch = self.term.show_notification(message)
ch = six.unichr(ch)
if ch not in choices:
self.term.show_notification('Invalid option') self.term.show_notification('Invalid option')
return else:
self.refresh_content(order=order)
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):
if self.content.query: if self.content.query:
choices = { order = self._prompt_period('comments')
'\n': 'comments', if order is None:
'1': 'comments-hour',
'2': 'comments-day',
'3': 'comments-week',
'4': 'comments-month',
'5': 'comments-year',
'6': 'comments-all'}
message = docs.TIME_ORDER_MENU.strip().splitlines()
ch = self.term.show_notification(message)
ch = six.unichr(ch)
if ch not in choices:
self.term.show_notification('Invalid option') self.term.show_notification('Invalid option')
return else:
self.refresh_content(order=order)
self.refresh_content(order=choices[ch])
else: else:
self.refresh_content(order='rising') self.refresh_content(order='rising')
@@ -153,28 +127,14 @@ class Page(object):
@PageController.register(Command('SORT_CONTROVERSIAL')) @PageController.register(Command('SORT_CONTROVERSIAL'))
def sort_content_controversial(self): def sort_content_controversial(self):
if self.content.query: if self.content.query:
self.term.flash() self.term.flash()
return else:
order = self._prompt_period('controversial')
choices = { if order is None:
'\n': 'controversial', self.term.show_notification('Invalid option')
'1': 'controversial-hour', else:
'2': 'controversial-day', self.refresh_content(order=order)
'3': 'controversial-week',
'4': 'controversial-month',
'5': 'controversial-year',
'6': 'controversial-all'}
message = docs.TIME_ORDER_MENU.strip().splitlines()
ch = self.term.show_notification(message)
ch = six.unichr(ch)
if ch not in choices:
self.term.show_notification('Invalid option')
return
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):
@@ -613,3 +573,20 @@ class Page(object):
n_rows, _ = window.getmaxyx() n_rows, _ = window.getmaxyx()
for row in range(n_rows): for row in range(n_rows):
window.chgat(row, 0, 1, attribute) window.chgat(row, 0, 1, attribute)
def _prompt_period(self, order):
choices = {
'\n': order,
'1': '{0}-hour'.format(order),
'2': '{0}-day'.format(order),
'3': '{0}-week'.format(order),
'4': '{0}-month'.format(order),
'5': '{0}-year'.format(order),
'6': '{0}-all'.format(order)}
message = docs.TIME_ORDER_MENU.strip().splitlines()
ch = self.term.show_notification(message)
ch = six.unichr(ch)
return choices.get(ch)