Пример #1
0
def project_blog_posts(max_number=5, sort="timestamp", summary=False, mount_point=None):
    from forgeblog import model as BM
    from allura.lib.widgets.macros import BlogPosts

    app_config_ids = []
    for conf in c.project.app_configs:
        if conf.tool_name.lower() == "blog" and (mount_point is None or conf.options.mount_point == mount_point):
            app_config_ids.append(conf._id)
    posts = BM.BlogPost.query.find({"app_config_id": {"$in": app_config_ids}, "state": "published"})
    posts = posts.sort(sort, pymongo.DESCENDING).limit(int(max_number)).all()
    output = (
        (
            dict(
                href=post.url(),
                title=post.title,
                author=post.author().display_name,
                ago=h.ago(post.timestamp),
                description=summary and " " or g.markdown.convert(post.text),
            )
        )
        for post in posts
        if security.has_access(post, "read", project=post.app.project)()
        and security.has_access(post.app.project, "read", project=post.app.project)()
    )
    posts = BlogPosts(posts=output)
    g.resource_manager.register(posts)
    response = posts.display(posts=output)
    return response
Пример #2
0
def project_blog_posts(max_number=5,
                       sort='timestamp',
                       summary=False,
                       mount_point=None):
    from forgeblog import model as BM
    from allura.lib.widgets.macros import BlogPosts
    app_config_ids = []
    for conf in c.project.app_configs:
        if conf.tool_name.lower() == 'blog' and (mount_point is None
                                                 or conf.options.mount_point
                                                 == mount_point):
            app_config_ids.append(conf._id)
    posts = BM.BlogPost.query.find({
        'app_config_id': {
            '$in': app_config_ids
        },
        'state': 'published',
    })
    posts = posts.sort(sort, pymongo.DESCENDING).limit(int(max_number)).all()
    output = ((dict(href=post.url(),
                    title=post.title,
                    author=post.author().display_name,
                    ago=h.ago(post.timestamp),
                    description=summary and ' '
                    or g.markdown.cached_convert(post, 'text')))
              for post in posts
              if security.has_access(post, 'read', project=post.app.project)()
              and security.has_access(
                  post.app.project, 'read', project=post.app.project)())
    posts = BlogPosts(posts=output)
    g.resource_manager.register(posts)
    response = posts.display(posts=output)
    return response
Пример #3
0
def neighborhood_blog_posts(max_number=5, sort="timestamp", summary=False):
    from forgeblog import model as BM
    from allura.lib.widgets.macros import BlogPosts

    posts = BM.BlogPost.query.find(dict(neighborhood_id=c.project.neighborhood._id, state="published"))
    posts = posts.sort(sort, pymongo.DESCENDING).limit(int(max_number)).all()
    output = (
        (
            dict(
                href=post.url(),
                title=post.title,
                author=post.author().display_name,
                ago=h.ago(post.timestamp),
                description=summary and " " or g.markdown.convert(post.text),
            )
        )
        for post in posts
        if post.app
        and security.has_access(post, "read", project=post.app.project)()
        and security.has_access(post.app.project, "read", project=post.app.project)()
    )

    posts = BlogPosts(posts=output)
    g.resource_manager.register(posts)
    response = posts.display(posts=output)
    return response
Пример #4
0
def neighborhood_blog_posts(max_number=5, sort='timestamp', summary=False):
    from forgeblog import model as BM
    from allura.lib.widgets.macros import BlogPosts
    posts = BM.BlogPost.query.find(
        dict(neighborhood_id=c.project.neighborhood._id, state='published'))
    posts = posts.sort(sort, pymongo.DESCENDING).limit(int(max_number)).all()
    output = ((dict(href=post.url(),
                    title=post.title,
                    author=post.author().display_name,
                    ago=h.ago(post.timestamp),
                    description=summary and ' '
                    or g.markdown.cached_convert(post, 'text')))
              for post in posts if post.app and security.has_access(
                  post, 'read', project=post.app.project)() and security.
              has_access(post.app.project, 'read', project=post.app.project)())

    posts = BlogPosts(posts=output)
    g.resource_manager.register(posts)
    response = posts.display(posts=output)
    return response