本文整理汇总了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
)
示例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
)
示例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()
示例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"),
}
示例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,
)