Merge pull request #74 from Brobin/user_profile_page

added user profile page for logged in users
This commit is contained in:
michael-lazar
2015-04-05 12:30:06 -07:00
5 changed files with 30 additions and 3 deletions

View File

@@ -71,6 +71,7 @@ In subreddit mode you can browse through the top submissions on either the front
:``►`` or ``l``: View comments for the selected submission
:``/``: Open a prompt to switch subreddits
:``f``: Open a prompt to search the current subreddit
:``p``: Post a Submission to the current subreddit
The ``/`` prompt accepts subreddits in the following formats
@@ -78,6 +79,7 @@ The ``/`` prompt accepts subreddits in the following formats
* ``/r/python/new``
* ``/r/python+linux`` supports multireddits
* ``/r/front`` will redirect to the front page
* ``/r/me`` will show you your submissions on all subs
**Submission Mode**

View File

@@ -310,6 +310,18 @@ class SubredditContent(BaseContent):
return content
@classmethod
def from_redditor(cls, reddit, loader, order='new'):
submissions = reddit.user.get_submitted(sort=order)
display_name = '/r/me'
content = cls(display_name, submissions, loader)
try:
content.get(0)
except (praw.errors.APIException, requests.HTTPError,
praw.errors.RedirectException):
raise SubredditError(display_name)
return content
def get(self, index, n_cols=70):
"""
Grab the `i`th submission, with the title field formatted to fit inside

View File

@@ -38,6 +38,7 @@ Subreddit Mode
`RIGHT` or `l` : View comments for the selected submission
`/` : Open a prompt to switch subreddits
`f` : Open a prompt to search the current subreddit
`p` : Post a Submission to the current subreddit
Submission Mode
`LEFT` or `h` : Return to subreddit mode

View File

@@ -31,8 +31,8 @@ class SubmissionPage(BasePage):
else:
raise ValueError('Must specify url or submission')
super(SubmissionPage, self).__init__(stdscr, reddit, content,
page_index=-1)
super(SubmissionPage, self).__init__(stdscr, reddit,
content, page_index=-1)
def loop(self):
self.active = True

View File

@@ -41,7 +41,9 @@ class SubredditPage(BasePage):
@SubredditController.register(curses.KEY_F5, 'r')
def refresh_content(self, name=None):
name = name or self.content.name
if name == 'me' or name == '/r/me':
self.redditor_profile()
return
try:
self.content = SubredditContent.from_name(
self.reddit, name, self.loader)
@@ -74,6 +76,16 @@ class SubredditPage(BasePage):
if name is not None:
self.refresh_content(name=name)
def redditor_profile(self):
if self.reddit.is_logged_in():
try:
self.content = SubredditContent.from_redditor(
self.reddit, self.loader)
except requests.HTTPError:
show_notification(self.stdscr, ['Could not reach subreddit'])
else:
show_notification(self.stdscr, ['Log in to view your submissions'])
@SubredditController.register(curses.KEY_RIGHT, 'l')
def open_submission(self):
"Select the current submission to view posts"