Ejemplo n.º 1
0
 def public_posts(self):
     nav = browse.Navigation.load_json_or_404({
         'userpage_type': 'new',
         'user': self.user,
         'offset': self.skip,
         'public_api': True,
     })
     posts = browse.get_user_data(AnonymousUser(), nav)
     return [BriefPublicAPICommentDetails(x.comment.to_dict()).to_client() for x in posts]
Ejemplo n.º 2
0
 def test_user_data_with_invalid_type_404s(self):
     user = create_user()
     nav_data = {
         'userpage_type': 'stickered',
         'user': create_user().username
     }
     nav = Navigation.load_json_or_404(nav_data)
     nav.userpage_type = 'INVALID_TYPE'
     self.assertRaises(Http404, lambda: get_user_data(user, nav))
Ejemplo n.º 3
0
def user_view(request, username, userpage_type):
    nav = browse.Navigation.load_json_or_404({
        'userpage_type': userpage_type,
        'user': username,
        'offset': request.GET.get('offset'),
        'mobile': request.is_mobile,
    })

    nav_data = nav.dump_json()

    posts = browse.get_user_data(request.user, nav)

    viewer_is_staff = request.user.is_authenticated() and request.user.is_staff
    user = get_object_or_404(User, username=username)
    private_beta_member = (user.id <= 63015)
    user_is_staff = user.is_staff
    friendlyname = "you" if user == request.user else username
    # A template variable that tells us if the current user is viewing her profile.
    user_is_self = user == request.user
    user_can_see_anonymous = (request.user == user or viewer_is_staff)
    showing_anonymous = True

    viewer_is_following = request.user.is_authenticated() and request.user.is_following(user)

    hide_userpage_from_google = user.has_lab('hide_userpage_from_google')

    if userpage_type == 'top' or userpage_type == 'top_anonymous':
        sort_method = 'top'
    elif userpage_type == 'new' or userpage_type == 'new_anonymous':
        sort_method = 'new'
    elif userpage_type == 'stickered':
        sort_method = 'stickered'

    # Can this comment be deleted by this user?
    # We only want to show the delete button if the user is looking at her user page. So we suppress it in the
    # browse pages for two reasons:
    # 1. It adds clutter to the page. There is already a lot of stuff going on in browse pages.
    # 2. It might encourage deletes.
    show_delete_option = user_is_self and userpage_type not in ['stickered']

    sort = sort_method
    # The Jinja template expects "posts" to be called "tiles".
    tiles = posts
    render_options = tile_render_options(sort, False)

    avatar_comment = None
    bio = ""

    if user.userinfo.profile_image is not None:
        avatar_comment = Comment.details_by_id(user.userinfo.profile_image.id)()
        bio = user.userinfo.profile_image.reply_text

    if request.is_mobile:
        return r2r_jinja('mobile/user.html', locals())

    return r2r_jinja('user/profile.html', locals())
Ejemplo n.º 4
0
 def public_posts(self):
     nav = browse.Navigation.load_json_or_404({
         'userpage_type': 'new',
         'user': self.user,
         'offset': self.skip,
         'public_api': True,
     })
     posts = browse.get_user_data(AnonymousUser(), nav)
     return [
         BriefPublicAPICommentDetails(x.comment.to_dict()).to_client()
         for x in posts
     ]
Ejemplo n.º 5
0
def user_more(request, nav_data={}, offset=0, tile_renderer="explore_tiles"):
    """ Fetches more posts for infinite scroll on the user page. """
    offset = int(offset)
    nav = browse.Navigation.load_json_or_404(nav_data, offset=offset)

    posts = browse.get_user_data(request.user, nav)

    show_delete_option = nav.user == request.user and nav.userpage_type != 'stickered'

    context = dict(request=request, show_delete_option=show_delete_option)

    return _disposition_tiles(request, context, posts, nav, show_pins=False, tile_renderer=tile_renderer)
Ejemplo n.º 6
0
def user_more(request, nav_data={}, offset=0, tile_renderer="explore_tiles"):
    """ Fetches more posts for infinite scroll on the user page. """
    offset = int(offset)
    nav = browse.Navigation.load_json_or_404(nav_data, offset=offset)

    posts = browse.get_user_data(request.user, nav)

    show_delete_option = nav.user == request.user and nav.userpage_type != 'stickered'

    context = dict(request=request, show_delete_option=show_delete_option)

    return _disposition_tiles(request,
                              context,
                              posts,
                              nav,
                              show_pins=False,
                              tile_renderer=tile_renderer)
Ejemplo n.º 7
0
 def test_user_data_with_invalid_type_404s(self):
     user = create_user()
     nav_data = {'userpage_type': 'stickered', 'user': create_user().username}
     nav = Navigation.load_json_or_404(nav_data)
     nav.userpage_type = 'INVALID_TYPE'
     self.assertRaises(Http404, lambda: get_user_data(user, nav))