Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Merge branch 'woorst-user_pages'
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-lazar committed Oct 2, 2018
2 parents 2970724 + 81e90fc commit 5f3c154
Show file tree
Hide file tree
Showing 17 changed files with 19,958 additions and 5,659 deletions.
54 changes: 43 additions & 11 deletions rtv/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,41 @@ def from_name(cls, reddit, name, loader, order=None, query=None):
if resource_root == 'user':
resource_root = 'u'
elif resource_root.startswith('user/'):
# Special check for multi-reddit resource roots
# E.g.
# before: resource_root = "user/civilization_phaze_3/m"
# After: resource_root = "u/civilization_phaze_3/m"
resource_root = 'u' + resource_root[4:]

# There should at most two parts left, the resource and the order
# The parts left should be in one of the following forms:
# [resource]
# [resource, order]
# [resource, user_room, order]

user_rooms = ['overview', 'submitted', 'comments']
private_user_rooms = ['upvoted', 'downvoted', 'hidden', 'saved']
user_room = None

if len(parts) == 1:
# E.g. /r/python
# parts = ["python"]
# resource = "python"
# resource_order = None
resource, resource_order = parts[0], None
elif resource_root == 'u' and len(parts) in [2, 3] \
and parts[1] in user_rooms + private_user_rooms:
# E.g. /u/spez/submitted/top ->
# parts = ["spez", "submitted", "top"]
# resource = "spez"
# user_room = "submitted"
# resource_order = "top"
resource, user_room = parts[:2]
resource_order = parts[2] if len(parts) == 3 else None
elif len(parts) == 2:
# E.g. /r/python/top
# parts = ["python", "top"]
# resource = "python
# resource_order = "top"
resource, resource_order = parts
else:
raise InvalidSubreddit('`{}` is an invalid format'.format(name))
Expand All @@ -550,6 +579,8 @@ def from_name(cls, reddit, name, loader, order=None, query=None):

display_order = order
display_name = '/'.join(['', resource_root, resource])
if user_room and resource_root == 'u':
display_name += '/' + user_room

# Split the order from the period E.g. controversial-all, top-hour
if order and '-' in order:
Expand Down Expand Up @@ -622,22 +653,23 @@ def from_name(cls, reddit, name, loader, order=None, query=None):
if not reddit.is_oauth_session():
raise exceptions.AccountError('Not logged in')
else:
user_room = user_room or 'overview'
order = order or 'new'
submissions = reddit.user.get_overview(sort=order, limit=None)

elif resource_root == 'u' and resource == 'saved':
if not reddit.is_oauth_session():
raise exceptions.AccountError('Not logged in')
else:
order = order or 'new'
submissions = reddit.user.get_saved(sort=order, limit=None)
period = period or 'all'
method = getattr(reddit.user, 'get_%s' % user_room)
submissions = method(sort=order, time=period, limit=None)

elif resource_root == 'u':
user_room = user_room or 'overview'
if user_room not in user_rooms:
# Tried to access a private room like "u/me/hidden" for a
# different redditor
raise InvalidSubreddit('Unavailable Resource')
order = order or 'new'
period = period or 'all'
redditor = reddit.get_redditor(resource)
submissions = redditor.get_overview(
sort=order, time=period, limit=None)
method = getattr(redditor, 'get_%s' % user_room)
submissions = method(sort=order, time=period, limit=None)

elif resource == 'front':
if order in (None, 'hot'):
Expand Down
8 changes: 5 additions & 3 deletions rtv/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@
- /r/python/comments/30rwj2 (submission comments)
- /comments/30rwj2 (submission comments shorthand)
- /r/front (front page)
- /u/me (your submissions)
- /u/saved (your saved posts)
- /u/spez (a user's submissions)
- /u/me (your submissions overview)
- /u/me/{saved,hidden} (your saved or hidden posts)
- /u/me/{upvoted,downvoted} (your voted posts)
- /u/spez (a user's submissions overview)
- /u/spez/{submitted,comments} (a user's posts or comments)
- /u/multi-mod/m/android (curated multireddit)
- /domain/python.org (search by domain)
"""
Expand Down
22 changes: 20 additions & 2 deletions rtv/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,26 @@ def _draw_header(self):

sub_name = self.content.name
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')

parts = sub_name.split('/')
if len(parts) == 1:
pass
elif '/m/' in sub_name:
_, _, user, _, multi = parts
sub_name = '{} Curated by {}'.format(multi, user)
elif parts[1] == 'u':
noun = 'My' if parts[2] == 'me' else parts[2] + "'s"
user_room = parts[3] if len(parts) == 4 else 'overview'
title_lookup = {
'overview': 'Overview',
'submitted': 'Submissions',
'comments': 'Comments',
'saved': 'Saved Content',
'hidden': 'Hidden Content',
'upvoted': 'Upvoted Content',
'downvoted': 'Downvoted Content'
}
sub_name = "{} {}".format(noun, title_lookup[user_room])

query = self.content.query
if query:
Expand Down
Loading

0 comments on commit 5f3c154

Please sign in to comment.