Пример #1
0
def board_index(request):
    """Render the board index page

    Available template variables:

        `categories`:
            Ordered Dictionary with 'catname': 'forums'

    :Template name: ``board_index.html``
    :URL endpoint: ``board/index``
    """
    renderdict = OrderedDict()
    categories = Category.query.order_by(db.asc('ordering')).all()
    for category in categories:
        forums = category.forums.order_by(db.asc('ordering')).all()
        if forums:
            user = request.user
            forumlist = [forum for forum in \
                         forums if forum.can_see(request.user)]
            if forumlist:
                renderdict[category] = forumlist

    return render_response('board_index.html', categories=renderdict)
Пример #2
0
def locate_post(searchpost, per_page=None):
    """Locate a post and return page and topic which it is on"""

    assert searchpost is not None
    topic = searchpost.topic
    posts = Post.query.filter(Post.topic==topic).order_by(db.asc(Post.date)).all()
    number = -1
    for postnr, post in enumerate(posts):
        if post.id == searchpost.id:
            number = postnr
            break
    if number == -1:
        raise get_application.InternalError('Post searching returned invalid id, check database consistency')

    page = 1
    if per_page:
        page = ceil(postnr/perpage)

    return (postnr, page, topic.id)
Пример #3
0
    def get_list(self, endpoint=None, page=1, per_page=None,
                 url_args=None, raise_if_empty=True, paginator=Pagination):
        """Return a dict with pagination and categories."""

        if per_page is None:
            per_page = 20

        # send the query
        offset = per_page * (page - 1)
        categorylist = self.order_by(db.asc(Category.ordering)) \
                           .offset(offset).limit(per_page).all()

        # if raising exceptions is wanted, raise i
        if raise_if_empty and (page != 1 and not categorylist):
            raise NotFound()

        pagination = paginator(endpoint, page, per_page,
                                self.count(), url_args=url_args)

        return {
            'categories':       categorylist,
            'pagination':       pagination,
        }