本文整理汇总了Python中invenio_communities.models.Community.create方法的典型用法代码示例。如果您正苦于以下问题:Python Community.create方法的具体用法?Python Community.create怎么用?Python Community.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类invenio_communities.models.Community
的用法示例。
在下文中一共展示了Community.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: communities
# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import create [as 别名]
def communities(app, db, user):
"""Create some example communities."""
user1 = db_.session.merge(user)
comm0 = Community.create(community_id="comm1", user_id=user1.id, title="Title1", description="Description1")
comm1 = Community.create(community_id="comm2", user_id=user1.id, title="A")
comm2 = Community.create(community_id="oth3", user_id=user1.id)
return comm0, comm1, comm2
示例2: communities
# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import create [as 别名]
def communities(app, db, user):
"""Create some example communities."""
user1 = db_.session.merge(user)
comm0 = Community.create(community_id='comm1', user_id=user1.id,
title='Title1', description='Description1')
comm1 = Community.create(community_id='comm2', user_id=user1.id, title='A')
comm2 = Community.create(community_id='oth3', user_id=user1.id)
return comm0, comm1, comm2
示例3: communities
# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import create [as 别名]
def communities(db, users):
"""Create communities."""
comm_data = [
{'id': 'c1', 'user_id': users[1]['id']},
{'id': 'c2', 'user_id': users[1]['id']},
{'id': 'c3', 'user_id': users[0]['id']},
{'id': 'c4', 'user_id': users[0]['id']},
]
for c in comm_data:
Community.create(c['id'], user_id=c['user_id'])
db.session.commit()
return comm_data
示例4: loadcommunities
# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import create [as 别名]
def loadcommunities(owner_email):
"""Load the Zenodo communities fixture.
Create extra PID if license is to be mapped and already exists, otherwise
create a new license record and a PID.
"""
data = read_json('data/communities.json')
owner = User.query.filter_by(email=owner_email).one()
for comm_data in data:
community_id = comm_data.pop('id')
user_id = owner.id
Community.create(community_id, user_id, **comm_data)
db.session.commit()
示例5: communities_for_filtering
# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import create [as 别名]
def communities_for_filtering(app, db, user):
"""Create some example communities."""
user1 = db_.session.merge(user)
comm0 = Community.create(community_id='comm1', user_id=user1.id,
title='Test1',
description=('Beautiful is better than ugly. '
'Explicit is better than implicit.'))
comm1 = Community.create(community_id='comm2', user_id=user1.id,
title='Testing case 2',
description=('Flat is better than nested. '
'Sparse is better than dense.'))
comm2 = Community.create(community_id='oth3', user_id=user1.id,
title='A word about testing',
description=('Errors should never pass silently. '
'Unless explicitly silenced.'))
return comm0, comm1, comm2
示例6: loadcommunity
# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import create [as 别名]
def loadcommunity(comm_data):
"""Load the Zenodo communities fixture."""
logo_path = comm_data.pop('logo', None)
community_id = comm_data.pop('id')
owner_email = comm_data.pop('owner_email')
owner_id = User.query.filter_by(email=owner_email).one().id
c = Community.create(community_id, owner_id, **comm_data)
if logo_path:
logo = file_stream(logo_path)
ext = save_and_validate_logo(logo, logo.name, community_id)
c.logo_ext = ext
db.session.commit()
示例7: new
# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import create [as 别名]
def new():
"""Create a new community."""
form = CommunityForm(request.values)
ctx = mycommunities_ctx()
ctx.update({
'form': form,
'is_new': True,
'community': None,
})
if form.validate_on_submit():
data = copy.deepcopy(form.data)
community_id = data.pop('identifier')
del data['logo']
community = Community.create(
community_id, current_user.get_id(), **data)
file = request.files.get('logo', None)
if file:
if not community.save_logo(file.stream, file.filename):
form.logo.errors.append(_(
'Cannot add this file as a logo. Supported formats: '
'PNG, JPG and SVG. Max file size: 1.5 MB.'))
db.session.rollback()
community = None
if community:
permissions = _get_permissions()
for permission in permissions:
db.session.add(ActionUsers(action=permission,
user=current_user,
argument=community_id))
db.session.commit()
flash("{} was successfully created.".format(
current_app.config["COMMUNITIES_NAME"].capitalize()),
category='success')
return redirect(url_for('.edit', community_id=community.id))
return render_template(
"/invenio_communities/new.html",
community_form=form,
**ctx
)
示例8: test_oai_set_correspondence
# 需要导入模块: from invenio_communities.models import Community [as 别名]
# 或者: from invenio_communities.models.Community import create [as 别名]
def test_oai_set_correspondence(db, users, oai_communities, oai_sets,
missing_oai_set, missing_community):
for c in oai_communities:
with db.session.begin_nested():
new_comm = Community.create(community_id=c, user_id=1)
db.session.commit()
# Delete the automatically created OAI Set id required by test case
if new_comm.oaiset_spec not in oai_sets:
with db.session.begin_nested():
db.session.delete(new_comm.oaiset)
db.session.commit()
for s in oai_sets:
if not OAISet.query.filter_by(spec=s).one_or_none():
with db.session.begin_nested():
db.session.add(OAISet(spec=s))
db.session.commit()
check = OAICorrespondenceCheck()
check.perform()
assert set(check.issues.get('missing_oai_set', [])) == set(missing_oai_set)
assert set(check.issues.get('missing_community', [])) == \
set(missing_community)