Пример #1
0
Файл: views.py Проект: hnk/pjuu
def alerts():
    """Display a users alerts (notifications) to them on the site."""
    uid = current_user.get('_id')

    # Pagination
    page = handle_page(request)

    _results = get_alerts(uid, page)
    return render_template('alerts.html', pagination=_results)
Пример #2
0
def alerts():
    """Display a users alerts (notifications) to them on the site."""
    uid = current_user.get('_id')

    # Pagination
    page = handle_page(request)

    _results = get_alerts(uid, page,
                          current_user.get('alerts_pagination_size'))
    return render_template('alerts.html', pagination=_results)
Пример #3
0
    def test_handle_page(self):
        """Check the handle_page function, this is important as it stops Redis
        going crazy if the index is too high on a list or sorted set.

        """
        # Create a mock request object so that this functon does not require
        # a request. It gets a request object passed in.
        class Request(object):
            args = {}
        request = Request()

        # Check a couple of values
        self.assertEqual(handle_page(request), 1)
        request.args['page'] = 1000000
        self.assertEqual(handle_page(request), 1000000)
        # Ensure our minimum value can't be broken
        request.args['page'] = -1
        self.assertEqual(handle_page(request), 1)
        # Ensure the maximum value (4294967295) can't be broken
        request.args['page'] = 1000000000000
        self.assertEqual(handle_page(request), 4294967295)

        # Ensure it does not brake with invalid types
        request.args['page'] = None
        self.assertEqual(handle_page(request), 1)
        request.args['page'] = {}
        self.assertEqual(handle_page(request), 1)
Пример #4
0
    def test_handle_page(self):
        """Check the handle_page function, this is important as it stops Redis
        going crazy if the index is too high on a list or sorted set.

        """

        # Create a mock request object so that this functon does not require
        # a request. It gets a request object passed in.
        class Request(object):
            args = {}

        request = Request()

        # Check a couple of values
        self.assertEqual(handle_page(request), 1)
        request.args['page'] = 1000000
        self.assertEqual(handle_page(request), 1000000)
        # Ensure our minimum value can't be broken
        request.args['page'] = -1
        self.assertEqual(handle_page(request), 1)
        # Ensure the maximum value (4294967295) can't be broken
        request.args['page'] = 1000000000000
        self.assertEqual(handle_page(request), 4294967295)

        # Ensure it does not brake with invalid types
        request.args['page'] = None
        self.assertEqual(handle_page(request), 1)
        request.args['page'] = {}
        self.assertEqual(handle_page(request), 1)
Пример #5
0
def hashtags(hashtag=None):
    """Used to view a list of posts which contain a specific hashtag.

    """
    # We need to check the conditions for a valid hashtag if not we will
    # perform a 404 ourselves.
    if not hashtag or len(hashtag) < 2:
        return abort(404)

    # Pagination
    page = handle_page(request)
    pagination = get_hashtagged_posts(hashtag.lower(), page)

    return render_template('hashtags.html', hashtag=hashtag,
                           pagination=pagination)
Пример #6
0
def hashtags(hashtag=None):
    """Used to view a list of posts which contain a specific hashtag.

    """
    # We need to check the conditions for a valid hashtag if not we will
    # perform a 404 ourselves.
    if not hashtag or len(hashtag) < 2:
        return abort(404)

    # Pagination
    page = handle_page(request)
    pagination = get_hashtagged_posts(hashtag.lower(), page)

    return render_template('hashtags.html',
                           hashtag=hashtag,
                           pagination=pagination)
Пример #7
0
def feed():
    """
    Returns the users feed
    """
    if not current_user:
        return redirect(url_for('signin'))

    # Pagination
    page = handle_page(request)
    # Get feed pagination
    pagination = get_feed(current_user.get('uid'), page)

    # Post form
    post_form = PostForm()
    return render_template('feed.html', pagination=pagination,
                           post_form=post_form)
Пример #8
0
Файл: views.py Проект: hnk/pjuu
def feed():
    """Displays the users feed or redirects the user to the signin if they are
    not already signed in.

    """
    if not current_user:
        return redirect(url_for('auth.signin'))

    # Pagination
    page = handle_page(request)
    # Get feed pagination
    pagination = get_feed(current_user.get('_id'), page)

    # Post form
    post_form = PostForm()
    return render_template('feed.html', pagination=pagination,
                           post_form=post_form)
Пример #9
0
def search():
    """Search for a users. This is all done via a GET query.

    .. note: Should be _NO_ CSRF this will appear in the URL and look shit.
    """
    # Pagination
    page = handle_page(request)

    form = SearchForm(request.form)

    # Get the query string. If its not there return an empty string
    query = request.args.get('query', '')

    _results = be_search(query, page,
                         current_user.get('feed_pagination_size'))

    return render_template('search.html', form=form, query=query,
                           pagination=_results)
Пример #10
0
def view_post(username, pid):
    """
    Displays a post along with its comments paginated. I am not sure if this
    should be here or in the 'posts' app.
    """
    if not check_post(get_uid(username), pid):
        return abort(404)

    # Pagination
    page = handle_page(request)

    # Get post
    post = get_post(pid)
    # Get comments
    pagination = get_comments(pid, page)
    post_form = PostForm()
    return render_template('view_post.html', post=post,
                           pagination=pagination, post_form=post_form)
Пример #11
0
Файл: views.py Проект: pjuu/pjuu
def followers(username):
    """Returns all a users followers as a pagination object."""
    user_id = get_uid(username)

    if user_id is None:
        abort(404)

    # Data
    _profile = get_profile(user_id)

    # Pagination
    page = handle_page(request)

    # Get a list of users you are following
    _followers = get_followers(user_id, page,
                               current_user.get('feed_pagination_size'))

    return render_template('followers.html', profile=_profile,
                           pagination=_followers)
Пример #12
0
Файл: views.py Проект: pjuu/pjuu
def feed():
    """Displays the users feed or redirects the user to the signin if they are
    not already signed in.

    """
    if not current_user:
        form = SignInForm(request.form)
        return render_template('landing.html', form=form)

    # Pagination
    page = handle_page(request)
    # Get feed pagination
    pagination = get_feed(current_user.get('_id'), page,
                          current_user.get('feed_pagination_size'))

    # Post form
    post_form = PostForm()
    return render_template('feed.html', pagination=pagination,
                           post_form=post_form)
Пример #13
0
def search():
    """Search for a users. This is all done via a GET query.

    .. note: Should be _NO_ CSRF this will appear in the URL and look shit.
    """
    # Pagination
    page = handle_page(request)

    form = SearchForm(request.form)

    # Get the query string. If its not there return an empty string
    query = request.args.get('query', '')

    _results = be_search(query, page, current_user.get('feed_pagination_size'))

    return render_template('search.html',
                           form=form,
                           query=query,
                           pagination=_results)
Пример #14
0
def feed():
    """Displays the users feed or redirects the user to the signin if they are
    not already signed in.

    """
    if not current_user:
        return redirect(url_for('auth.signin'))

    # Pagination
    page = handle_page(request)
    # Get feed pagination
    pagination = get_feed(current_user.get('_id'), page,
                          current_user.get('feed_pagination_size'))

    # Post form
    post_form = PostForm()
    return render_template('feed.html',
                           pagination=pagination,
                           post_form=post_form)
Пример #15
0
Файл: views.py Проект: hnk/pjuu
def followers(username):
    """Returns all a users followers as a pagination object."""
    user_id = get_uid(username)

    if user_id is None:
        abort(404)

    # Data
    _profile = get_profile(user_id)

    # Pagination
    page = handle_page(request)

    # Get a list of users you are following
    _followers = get_followers(user_id, page)
    # Post form
    post_form = PostForm()
    return render_template('followers.html', profile=_profile,
                           pagination=_followers, post_form=post_form)
Пример #16
0
Файл: views.py Проект: hnk/pjuu
def profile(username):
    """It will show the users posts. Referred to as "posts" on the site."""
    uid = get_uid_username(username)

    if uid is None:
        abort(404)

    # Data
    _profile = get_profile(uid)

    # Pagination
    page = handle_page(request)
    # Get the posts pagination
    pagination = get_posts(uid, page)

    # Post form
    post_form = PostForm()
    return render_template('posts.html', profile=_profile,
                           pagination=pagination, post_form=post_form)
Пример #17
0
def followers(username):
    """Returns all a users followers as a pagination object."""
    user_id = get_uid(username)

    if user_id is None:
        abort(404)

    # Data
    _profile = get_profile(user_id)

    # Pagination
    page = handle_page(request)

    # Get a list of users you are following
    _followers = get_followers(user_id, page,
                               current_user.get('feed_pagination_size'))

    return render_template('followers.html',
                           profile=_profile,
                           pagination=_followers)
Пример #18
0
def following(username):
    """Returns all users following the current user as a pagination."""
    user_id = get_uid(username)

    if user_id is None:
        abort(404)

    # Data
    _profile = get_profile(user_id)

    # Pagination
    page = handle_page(request)

    # Get a list of users you are following
    _following = get_following(user_id, page,
                               current_user.get('feed_pagination_size'))

    # Post form
    post_form = PostForm()
    return render_template('following.html', profile=_profile,
                           pagination=_following, post_form=post_form)
Пример #19
0
Файл: views.py Проект: pjuu/pjuu
def global_feed():
    """Show a weighted list of public/pjuu only posts depending if the user is
    logged in or not
    """
    if current_user:
        page_size = current_user.get('feed_pagination_size',
                                     app.config.get('FEED_ITEMS_PER_PAGE', 25))
    else:
        page_size = app.config.get('FEED_ITEMS_PER_PAGE', 25)

    if current_user:
        permission = 1
    else:
        permission = 0

    page = handle_page(request)

    _posts = get_global_feed(page, page_size, perm=permission)

    post_form = PostForm()
    return render_template('global_feed.html', pagination=_posts,
                           post_form=post_form)
Пример #20
0
def profile(username):
    """It will show the users posts. Referred to as "posts" on the site.

    .. note: Viewable to public! (Only public posts)
    """
    uid = get_uid_username(username)

    if uid is None:
        abort(404)

    # Data
    _profile = get_profile(uid)

    # Pagination
    page = handle_page(request)

    # Get the page sizes taking in to account non-logged in users
    if current_user:
        page_size = current_user.get('feed_pagination_size',
                                     app.config.get('FEED_ITEMS_PER_PAGE', 25))
    else:
        page_size = app.config.get('FEED_ITEMS_PER_PAGE', 25)

    # Get the posts pagination
    if current_user:
        current_user_id = current_user.get('_id')
    else:
        current_user_id = None
    permission = get_user_permission(_profile.get('_id'), current_user_id)

    _posts = get_posts(uid, page, page_size, perm=permission)

    # Post form
    post_form = PostForm()
    return render_template('posts.html',
                           profile=_profile,
                           pagination=_posts,
                           post_form=post_form)
Пример #21
0
Файл: views.py Проект: hnk/pjuu
def view_post(username, post_id):
    """
    Displays a post along with its comments paginated. I am not sure if this
    should be here or in the 'posts' app.
    """
    if not check_post(get_uid(username), post_id):
        return abort(404)

    # Pagination
    page = handle_page(request)

    # Get post and comments for the current page
    _post = get_post(post_id)

    # Stop a reply from ever being shown here
    if 'reply_to' in _post:
        return abort(404)

    pagination = get_replies(post_id, page)

    post_form = PostForm()
    return render_template('view_post.html', post=_post,
                           pagination=pagination, post_form=post_form)
Пример #22
0
def view_post(username, post_id):
    """
    Displays a post along with its comments paginated. I am not sure if this
    should be here or in the 'posts' app.
    """
    if not check_post(get_uid(username), post_id):
        return abort(404)

    # Pagination
    page = handle_page(request)

    # Handle explicit sort order
    # Fall back to user default else default
    sort = request.args.get('sort', None)
    if sort is None:
        sort = current_user.get('reply_sort_order', -1)
    else:
        try:
            sort = int(sort)
        except ValueError:
            sort = current_user.get('reply_sort_order', -1)

    # Get post and comments for the current page
    _post = get_post(post_id)

    # Stop a reply from ever being shown here
    if 'reply_to' in _post:
        return abort(404)

    pagination = get_replies(post_id, page,
                             current_user.get('replies_pagination_size'),
                             sort)

    post_form = PostForm()
    return render_template('view_post.html', post=_post,
                           pagination=pagination, post_form=post_form,
                           sort=sort)
Пример #23
0
Файл: views.py Проект: pjuu/pjuu
def profile(username):
    """It will show the users posts. Referred to as "posts" on the site.

    .. note: Viewable to public! (Only public posts)
    """
    uid = get_uid_username(username)

    if uid is None:
        abort(404)

    # Data
    _profile = get_profile(uid)

    # Pagination
    page = handle_page(request)

    # Get the page sizes taking in to account non-logged in users
    if current_user:
        page_size = current_user.get('feed_pagination_size',
                                     app.config.get('FEED_ITEMS_PER_PAGE', 25))
    else:
        page_size = app.config.get('FEED_ITEMS_PER_PAGE', 25)

    # Get the posts pagination
    if current_user:
        current_user_id = current_user.get('_id')
    else:
        current_user_id = None
    permission = get_user_permission(_profile.get('_id'), current_user_id)

    _posts = get_posts(uid, page, page_size, perm=permission)

    # Post form
    post_form = PostForm()
    return render_template('posts.html', profile=_profile,
                           pagination=_posts, post_form=post_form)
Пример #24
0
def view_post(username, post_id):
    """Displays a post along with its comments paginated. I am not sure if this
    should be here or in the 'posts' app.

    .. note: Viewable to the public if the post is public!
    """
    if not check_post(get_uid(username), post_id):
        return abort(404)

    # Get post and comments for the current page
    _post = get_post(post_id)

    # Stop a reply from ever being shown here
    if 'reply_to' in _post:
        return abort(404)

    _user = get_user(get_uid(username))

    # Only get the permission if the post is not owned by the current user
    if current_user:
        current_user_id = current_user.get('_id')
    else:
        current_user_id = None

    permission = get_user_permission(_user.get('_id'), current_user_id)

    if permission < _post.get('permission', k.PERM_PUBLIC):
        return abort(403)

    # Pagination
    page = handle_page(request)

    # Handle explicit sort order
    # Fall back to user default else default
    sort = request.args.get('sort', None)
    if sort is None:
        if current_user:
            sort = current_user.get('reply_sort_order', -1)
        else:
            sort = -1
    else:
        try:
            sort = 1 if int(sort) > 0 else -1
        except ValueError:
            if current_user:
                sort = current_user.get('reply_sort_order', -1)
            else:
                sort = -1

    # Get the page sizes taking in to account non-logged in users
    if current_user:
        page_size = current_user.get(
            'replies_pagination_size',
            app.config.get('REPLIES_ITEMS_PER_PAGE', 25)
        )
    else:
        page_size = app.config.get('REPLIES_ITEMS_PER_PAGE', 25)

    pagination = get_replies(post_id, page, page_size, sort)

    post_form = PostForm()
    return render_template('view_post.html', post=_post,
                           pagination=pagination, post_form=post_form,
                           sort=sort)
Пример #25
0
def view_post(username, post_id):
    """Displays a post along with its comments paginated. I am not sure if this
    should be here or in the 'posts' app.

    .. note: Viewable to the public if the post is public!
    """
    if not check_post(get_uid(username), post_id):
        return abort(404)

    # Get post and comments for the current page
    _post = get_post(post_id)

    # Stop a reply from ever being shown here
    if 'reply_to' in _post:
        return abort(404)

    _user = get_user(get_uid(username))

    # Only get the permission if the post is not owned by the current user
    if current_user:
        current_user_id = current_user.get('_id')
    else:
        current_user_id = None

    permission = get_user_permission(_user.get('_id'), current_user_id)

    if permission < _post.get('permission', k.PERM_PUBLIC):
        return abort(403)

    # Pagination
    page = handle_page(request)

    # Handle explicit sort order
    # Fall back to user default else default
    sort = request.args.get('sort', None)
    if sort is None:
        if current_user:
            sort = current_user.get('reply_sort_order', -1)
        else:
            sort = -1
    else:
        try:
            sort = 1 if int(sort) > 0 else -1
        except ValueError:
            if current_user:
                sort = current_user.get('reply_sort_order', -1)
            else:
                sort = -1

    # Get the page sizes taking in to account non-logged in users
    if current_user:
        page_size = current_user.get(
            'replies_pagination_size',
            app.config.get('REPLIES_ITEMS_PER_PAGE', 25))
    else:
        page_size = app.config.get('REPLIES_ITEMS_PER_PAGE', 25)

    pagination = get_replies(post_id, page, page_size, sort)

    post_form = PostForm()
    return render_template('view_post.html',
                           post=_post,
                           pagination=pagination,
                           post_form=post_form,
                           sort=sort)