当前位置: 首页>>代码示例>>Python>>正文


Python Community.filter_communities方法代码示例

本文整理汇总了Python中invenio_communities.models.Community.filter_communities方法的典型用法代码示例。如果您正苦于以下问题:Python Community.filter_communities方法的具体用法?Python Community.filter_communities怎么用?Python Community.filter_communities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在invenio_communities.models.Community的用法示例。


在下文中一共展示了Community.filter_communities方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import filter_communities [as 别名]
def index():
    """Index page with uploader and list of existing depositions."""
    ctx = mycommunities_ctx()

    p = request.args.get('p', type=str)
    so = request.args.get('so', type=str)
    page = request.args.get('page', type=int, default=1)

    so = so or current_app.config.get('COMMUNITIES_DEFAULT_SORTING_OPTION')

    communities = Community.filter_communities(p, so).all()
    communities = [c for c in communities
                   if _get_permission("communities-read", c).can()
                   or DynamicPermission(ActionNeed('admin-access')).can()]
    featured_community = FeaturedCommunity.get_featured_or_none()
    form = SearchForm(p=p)
    per_page = 10
    page = max(page, 1)
    p = Pagination(page, per_page, len(communities))

    ctx.update({
        'r_from': max(p.per_page * (p.page - 1), 0),
        'r_to': min(p.per_page * p.page, p.total_count),
        'r_total': p.total_count,
        'pagination': p,
        'form': form,
        'title': _('Communities'),
        'communities': communities[per_page * (page - 1):per_page * page],
        'featured_community': featured_community
    })

    return render_template(
        "invenio_communities/index.html",
        **ctx
    )
开发者ID:tind,项目名称:invenio-communities,代码行数:37,代码来源:ui.py

示例2: index

# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import filter_communities [as 别名]
def index():
    """Index page with uploader and list of existing depositions."""
    ctx = mycommunities_ctx()

    p = request.args.get('p', type=str)
    so = request.args.get('so', type=str)
    page = request.args.get('page', type=int, default=1)

    so = so or current_app.config.get('COMMUNITIES_DEFAULT_SORTING_OPTION')

    communities = Community.filter_communities(p, so)
    featured_community = FeaturedCommunity.get_featured_or_none()
    form = SearchForm(p=p)
    per_page = 10
    page = max(page, 1)
    p = Pagination(page, per_page, communities.count())

    ctx.update({
        'r_from': max(p.per_page * (p.page - 1), 0),
        'r_to': min(p.per_page * p.page, p.total_count),
        'r_total': p.total_count,
        'pagination': p,
        'form': form,
        'title': _('Communities'),
        'communities': communities.slice(
            per_page * (page - 1), per_page * page).all(),
        'featured_community': featured_community,
    })

    return render_template(
        "invenio_communities/index.html",
        **ctx
    )
开发者ID:krzysztof,项目名称:invenio-communities,代码行数:35,代码来源:ui.py

示例3: test_filter_community

# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import filter_communities [as 别名]
def test_filter_community(app, db, communities_for_filtering, user,
                          case_modifier):
    """Test the community filter task."""
    (comm0, comm1, comm2) = communities_for_filtering

    # Case insensitive
    results = Community.filter_communities(
                p=case_modifier('beautiful'),
                so='title').all()
    assert len(results) == 1
    assert {c.id for c in results} == {comm0.id}

    # Keyword search
    results = Community.filter_communities(
                p=case_modifier('errors'),
                so='title').all()
    assert len(results) == 1
    assert {c.id for c in results} == {comm2.id}

    # Partial keyword present
    results = Community.filter_communities(
                p=case_modifier('test'),
                so='title').all()
    assert len(results) == 3
    assert {c.id for c in results} == {comm0.id,
                                       comm1.id, comm2.id}

    # Order matter
    results = Community.filter_communities(
                p=case_modifier('explicit implicit'),
                so='title').all()
    assert len(results) == 1
    assert {c.id for c in results} == {comm0.id}

    results = Community.filter_communities(
                p=case_modifier('implicit explicit'),
                so='title').all()
    assert len(results) == 0
    assert {c.id for c in results} == set()
开发者ID:inveniosoftware,项目名称:invenio-communities,代码行数:41,代码来源:test_models.py

示例4: mycommunities_ctx

# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import filter_communities [as 别名]
def mycommunities_ctx():
    """Helper method for return ctx used by many views."""
    communities = Community.filter_communities("", "title").all()
    mycommunities = [c for c in communities
                     if _get_permission("communities-read", c).can()
                     or DynamicPermission(ActionNeed('admin-access')).can()]
    return {
        "mycommunities": mycommunities,
        "permission_admin": DynamicPermission(ActionNeed('admin-access')),
        "permission_cadmin": partial(_get_permission, "communities-admin"),
        "permission_curate": partial(_get_permission, "communities-curate"),
        "permission_manage": partial(_get_permission, "communities-manage"),
        "permission_read": partial(_get_permission, "communities-read"),
    }
开发者ID:tind,项目名称:invenio-communities,代码行数:16,代码来源:ui.py

示例5: get

# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import filter_communities [as 别名]
    def get(self, query, sort, page, size):
        """Get a list of all the communities.

        .. http:get:: /communities/(string:id)
            Returns a JSON list with all the communities.
            **Request**:
            .. sourcecode:: http
                GET /communities HTTP/1.1
                Accept: application/json
                Content-Type: application/json
                Host: localhost:5000
            :reqheader Content-Type: application/json
            **Response**:
            .. sourcecode:: http
                HTTP/1.0 200 OK
                Content-Length: 334
                Content-Type: application/json
                [
                    {
                        "id": "comm1"
                    },
                    {
                        "id": "comm2"
                    }
                ]
            :resheader Content-Type: application/json
            :statuscode 200: no error
        """
        urlkwargs = {
            'q': query,
            'sort': sort,
            'size': size,
        }

        communities = Community.filter_communities(query, sort)
        page = communities.paginate(page, size)

        links = default_links_pagination_factory(page, urlkwargs)

        links_headers = map(lambda key: ('link', 'ref="{0}" href="{1}"'.format(
            key, links[key])), links)

        return self.make_response(
            page,
            headers=links_headers,
            links_item_factory=default_links_item_factory,
            page=page,
            urlkwargs=urlkwargs,
            links_pagination_factory=default_links_pagination_factory,
        )
开发者ID:krzysztof,项目名称:invenio-communities,代码行数:52,代码来源:api.py


注:本文中的invenio_communities.models.Community.filter_communities方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。