コード例 #1
0
ファイル: blog.py プロジェクト: jace/zine-main
def archive(req, year=None, month=None, day=None, page=1):
    """Render the monthly archives.

    Available template variables:

        `posts`:
            a list of post objects we want to display

        `pagination`:
            a pagination object to render a pagination

        `year` / `month` / `day`:
            integers or None, useful to entitle the page.

    :Template name: ``archive.html``
    :URL endpoint: ``blog/archive``
    """
    if not year:
        return render_response('archive.html', month_list=True,
                               **Post.query.published().for_index()
                                     .get_archive_summary())

    url_args = dict(year=year, month=month, day=day)
    per_page = req.app.theme.settings['archive.per_page']
    data = Post.query.theme_lightweight('archive_overview') \
               .published().for_index().date_filter(year, month, day) \
               .get_list(page=page, endpoint='blog/archive',
                         url_args=url_args, per_page=per_page)

    add_link('alternate', url_for('blog/atom_feed', **url_args),
             'application/atom+xml', _(u'Recent Posts Feed'))

    return render_response('archive.html', year=year, month=month, day=day,
                           date=date(year, month or 1, day or 1),
                           month_list=False, **data)
コード例 #2
0
ファイル: blog.py プロジェクト: adityaathalye/zine
def archive(req, year=None, month=None, day=None, page=1):
    """Render the monthly archives.

    Available template variables:

        `posts`:
            a list of post objects we want to display

        `pagination`:
            a pagination object to render a pagination

        `year` / `month` / `day`:
            integers or None, useful to entitle the page

    :Template name: ``archive.html``
    :URL endpoint: ``blog/archive``
    """
    if not year:
        return render_response('archive.html', month_list=True,
                               **Post.query.published().for_index()
                                     .get_archive_summary())

    url_args = dict(year=year, month=month, day=day)
    per_page = req.app.theme.settings['archive.per_page']
    data = Post.query.theme_lightweight('archive_overview') \
               .published().for_index().date_filter(year, month, day) \
               .get_list(page=page, endpoint='blog/archive',
                         url_args=url_args, per_page=per_page)

    add_link('alternate', url_for('blog/atom_feed', **url_args),
             'application/atom+xml', _(u'Recent Posts Feed'))

    return render_response('archive.html', year=year, month=month, day=day,
                           date=date(year, month or 1, day or 1),
                           month_list=False, **data)
コード例 #3
0
ファイル: blog.py プロジェクト: adityaathalye/zine
def show_author(req, username, page=1):
    """Show the user profile of an author / editor or administrator.

    Available template variables:

        `posts`:
            a list of post objects this author wrote and are
            visible on this page

        `pagination`:
            a pagination object to render a pagination

        `user`
            the user object for this author

    :Template name: ``show_author.html``
    :URL endpoint: ``blog/show_author``
    """
    user = User.query.filter_by(username=username).first()
    if user is None or not user.is_author:
        raise NotFound()

    per_page = req.app.theme.settings['author.per_page']
    data = user.posts.theme_lightweight('author').published() \
                     .get_list(page=page, per_page=per_page,
                               endpoint='blog/show_author',
                               url_args=dict(username=user.username))

    add_link('alternate', url_for('blog/atom_feed', author=user.username),
             'application/atom+xml', _(u'All posts written by %s') %
             user.display_name)

    return render_response('show_author.html', user=user, **data)
コード例 #4
0
ファイル: blog.py プロジェクト: adityaathalye/zine
def show_category(req, slug, page=1):
    """Show all posts categoryged with a given category slug.

    Available template variables:

        `posts`:
            a list of post objects we want to display

        `pagination`:
            a pagination object to render a pagination

        `category`
            the category object for this page

    :Template name: ``show_category.html``
    :URL endpoint: ``blog/show_category``
    """
    category = Category.query.filter_by(slug=slug).first(True)
    per_page = req.app.theme.settings['category.per_page']
    data = category.posts.theme_lightweight('category') \
                   .published().get_list(page=page, per_page=per_page,
                                         endpoint='blog/show_category',
                                         url_args=dict(slug=slug))

    add_link('alternate', url_for('blog/atom_feed', category=slug),
             'application/atom+xml', _(u'All posts in category %s') % category.name)
    return render_response('show_category.html', category=category, **data)
コード例 #5
0
ファイル: blog.py プロジェクト: jace/zine-main
def show_category(req, slug, page=1):
    """Show all posts categoryged with a given category slug.

    Available template variables:

        `posts`:
            a list of post objects we want to display

        `pagination`:
            a pagination object to render a pagination

        `category`
            the category object for this page.

    :Template name: ``show_category.html``
    :URL endpoint: ``blog/show_category``
    """
    category = Category.query.filter_by(slug=slug).first(True)
    per_page = req.app.theme.settings['category.per_page']
    data = category.posts.theme_lightweight('category') \
                   .published().get_list(page=page, per_page=per_page,
                                         endpoint='blog/show_category',
                                         url_args=dict(slug=slug))

    add_link('alternate', url_for('blog/atom_feed', category=slug),
             'application/atom+xml', _(u'All posts in category %s') % category.name)
    return render_response('show_category.html', category=category, **data)
コード例 #6
0
ファイル: blog.py プロジェクト: adityaathalye/zine
def show_tag(req, slug, page=1):
    """Show all posts categoryged with a given tag slug.

    Available template variables:

        `posts`:
            a list of post objects we want to display

        `pagination`:
            a pagination object to render a pagination

        `tag`
            the tag object for this page

    :Template name: ``show_tag.html``
    :URL endpoint: ``blog/show_tag``
    """
    tag = Tag.query.filter_by(slug=slug).first(True)
    per_page = req.app.theme.settings['tag.per_page']
    data = tag.posts.theme_lightweight('tag') \
                    .published().get_list(page=page, endpoint='blog/show_tag',
                                          per_page=per_page,
                                          url_args=dict(slug=slug))

    add_link('alternate', url_for('blog/atom_feed', tag=slug),
             'application/atom+xml', _(u'All posts tagged %s') % tag.name)
    return render_response('show_tag.html', tag=tag, **data)
コード例 #7
0
ファイル: blog.py プロジェクト: jace/zine-main
def show_author(req, username, page=1):
    """Show the user profile of an author / editor or administrator.

    Available template variables:

        `posts`:
            a list of post objects this author wrote and are
            visible on this page.

        `pagination`:
            a pagination object to render a pagination

        `user`
            The user object for this author

    :Template name: ``show_author.html``
    :URL endpoint: ``blog/show_author``
    """
    user = User.query.filter_by(username=username).first()
    if user is None or not user.is_author:
        raise NotFound()

    per_page = req.app.theme.settings['author.per_page']
    data = user.posts.theme_lightweight('author').published() \
                     .get_list(page=page, per_page=per_page,
                               endpoint='blog/show_author',
                               url_args=dict(username=user.username))

    add_link('alternate', url_for('blog/atom_feed', author=user.username),
             'application/atom+xml', _(u'All posts written by %s') %
             user.display_name)

    return render_response('show_author.html', user=user, **data)
コード例 #8
0
ファイル: blog.py プロジェクト: adityaathalye/zine
def authors(req):
    """Show a list of authors.

    Available template variables:

        `authors`:
            list of author objects to display

    :Template name: ``authors.html``
    :URL endpoint: ``blog/authors``
    """
    return render_response('authors.html', authors=User.query.authors().all())
コード例 #9
0
ファイル: blog.py プロジェクト: jace/zine-main
def authors(req):
    """Show a list of authors.

    Available template variables:

        `authors`:
            list of author objects to display.

    :Template name: ``authors.html``
    :URL endpoint: ``blog/authors``
    """
    return render_response('authors.html', authors=User.query.authors().all())
コード例 #10
0
ファイル: blog.py プロジェクト: jace/zine-main
def show_page(req, post, comment_form):
    """Shows a post that is a page."""
    response = comment_form.create_if_valid(req)
    if response is not None:
        return response

    cfg = req.app.cfg
    return render_response(['pages/%s.html' % post.slug.strip('/'),
                            post.extra.get('page_template'), 'page.html'],
        page=post,
        form=comment_form.as_widget(),
        show_title=cfg['show_page_title']
    )
コード例 #11
0
ファイル: blog.py プロジェクト: adityaathalye/zine
def show_page(req, post, comment_form):
    """Shows a post that is a page."""
    response = comment_form.create_if_valid(req)
    if response is not None:
        return response

    cfg = req.app.cfg
    return render_response(['pages/%s.html' % post.slug.strip('/'),
                            post.extra.get('page_template'), 'page.html'],
        page=post,
        form=comment_form.as_widget(),
        show_title=cfg['show_page_title']
    )
コード例 #12
0
ファイル: blog.py プロジェクト: jace/zine-main
def tags(req):
    """
    Show a tagcloud.

    Available template variables:

        `tags`:
            list of tag summaries that contain the size of the cloud
            item, the name of the tag and it's slug

    :Template name: ``tags.html``
    :URL endpoint: ``blog/tags``
    """
    return render_response('tags.html',
                           tags=Tag.query.get_cloud())
コード例 #13
0
ファイル: blog.py プロジェクト: adityaathalye/zine
def tags(req):
    """
    Show a tagcloud.

    Available template variables:

        `tags`:
            list of tag summaries that contain the size of the cloud
            item, the name of the tag and its slug

    :Template name: ``tags.html``
    :URL endpoint: ``blog/tags``
    """
    return render_response('tags.html',
                           tags=Tag.query.get_cloud())
コード例 #14
0
ファイル: blog.py プロジェクト: jace/zine-main
def show_entry(req, post, comment_form):
    """Show as post and give users the possibility to comment to this
    story if comments are enabled.

    Available template variables:

        `post`:
            The post object we display.

        `form`:
            A dict of form values (name, email, www and body)

        `errors`:
            List of error messages that occurred while posting the
            comment. If empty the form was not submitted or everyhing
            worked well.

    Events emitted:

        `before-comment-created`:
            this event is sent with the form as event data. Can return
            a list of error messages to prevent the user from posting
            that comment.

        `before-comment-saved`:
            executed right before the comment is saved to the database.
            The event data is set to the comment. This is usually used
            to block the comment (setting the status and blocked_msg
            attributes) so that administrators have to approve them.

        `after-comment-saved`:
            executed right after comment was saved to the database. Can be
            used to send mail notifications and stuff like that.

    This view supports pingbacks via `zine.pingback.pingback_post`

    :Template name: ``show_entry.html``
    """
    response = comment_form.create_if_valid(req)
    if response is not None:
        return response

    return render_response('show_entry.html',
        entry=post,
        form=comment_form.as_widget()
    )
コード例 #15
0
ファイル: blog.py プロジェクト: adityaathalye/zine
def show_entry(req, post, comment_form):
    """Show as post and give users the possibility to comment to this
    story if comments are enabled.

    Available template variables:

        `post`:
            the post object we display

        `form`:
            a dict of form values (name, email, www and body)

        `errors`:
            list of error messages that occurred while posting the
            comment, if empty the form was not submitted or everything
            worked well

    Events emitted:

        `before-comment-created`:
            this event is sent with the form as event data. Can return
            a list of error messages to prevent the user from posting
            that comment.

        `before-comment-saved`:
            executed right before the comment is saved to the database.
            The event data is set to the comment. This is usually used
            to block the comment (setting the status and blocked_msg
            attributes) so that administrators have to approve them.

        `after-comment-saved`:
            executed right after comment was saved to the database. Can be
            used to send mail notifications and stuff like that.

    This view supports pingbacks via `zine.pingback.pingback_post`

    :Template name: ``show_entry.html``
    """
    response = comment_form.create_if_valid(req)
    if response is not None:
        return response

    return render_response('show_entry.html',
        entry=post,
        form=comment_form.as_widget()
    )
コード例 #16
0
ファイル: blog.py プロジェクト: jace/zine-main
def index(req, page=1):
    """Render the most recent posts.

    Available template variables:

        `posts`:
            a list of post objects we want to display

        `pagination`:
            a pagination object to render a pagination

    :Template name: ``index.html``
    :URL endpoint: ``blog/index``
    """
    data = Post.query.published().for_index().get_list(endpoint='blog/index',
                                                       page=page)

    add_link('alternate', url_for('blog/atom_feed'), 'application/atom+xml',
             _(u'Recent Posts Feed'))
    return render_response('index.html', **data)
コード例 #17
0
ファイル: blog.py プロジェクト: adityaathalye/zine
def index(req, page=1):
    """Render the most recent posts.

    Available template variables:

        `posts`:
            a list of post objects we want to display

        `pagination`:
            a pagination object to render a pagination

    :Template name: ``index.html``
    :URL endpoint: ``blog/index``
    """
    data = Post.query.theme_lightweight('index').published() \
               .for_index().get_list(endpoint='blog/index',
                                     page=page)

    add_link('alternate', url_for('blog/atom_feed'), 'application/atom+xml',
             _(u'Recent Posts Feed'))
    return render_response('index.html', **data)