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


Python models.Community类代码示例

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


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

示例1: test_basic_community_workflow

def test_basic_community_workflow(app, db, communities, deposit, deposit_file):
    """Test simple (without concurrent events) deposit publishing workflow."""
    deposit = _publish_and_expunge(db, deposit)
    assert InclusionRequest.query.count() == 0
    pid, record = deposit.fetch_published()
    assert not record.get('communities', [])

    # Open record for edit, request a community and publish
    deposit = deposit.edit()
    deposit['communities'] = ['c1', ]
    deposit = _publish_and_expunge(db, deposit)
    pid, record = deposit.fetch_published()

    # Should contain just an InclusionRequest
    assert not record.get('communities', [])
    assert InclusionRequest.query.count() == 1
    ir = InclusionRequest.query.one()
    assert ir.id_community == 'c1'
    assert ir.id_record == record.id

    # Accept a record to the community 'c1'
    c1 = Community.get('c1')
    c1.accept_record(record)
    record.commit()
    db.session.commit()
    assert InclusionRequest.query.count() == 0
    assert record['communities'] == ['c1', ]

    # Open for edit and request another community
    deposit = deposit.edit()
    assert deposit['communities'] == ['c1', ]
    deposit['communities'] = ['c1', 'c2', ]  # New request for community 'c2'
    deposit = _publish_and_expunge(db, deposit)
    deposit['communities'] = ['c1', 'c2', ]
    pid, record = deposit.fetch_published()
    assert record['communities'] == ['c1', ]
    assert InclusionRequest.query.count() == 1
    ir = InclusionRequest.query.one()
    assert ir.id_community == 'c2'
    assert ir.id_record == record.id

    # Reject the request for community 'c2'
    c2 = Community.get('c2')
    c2.reject_record(record)
    db.session.commit()
    deposit = deposit.edit()

    # The deposit should not contain obsolete inclusion requests
    assert deposit['communities'] == ['c1', ]
    assert InclusionRequest.query.count() == 0
    pid, record = deposit.fetch_published()
    assert record['communities'] == ['c1', ]

    # Request for removal from a previously accepted community 'c1'
    deposit['communities'] = []
    deposit = _publish_and_expunge(db, deposit)
    pid, record = deposit.fetch_published()
    assert not deposit.get('communities', [])
    assert not record.get('communities', [])
    assert InclusionRequest.query.count() == 0
开发者ID:PixelDragon,项目名称:zenodo,代码行数:60,代码来源:test_communities_merging.py

示例2: communities

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
开发者ID:krzysztof,项目名称:invenio-communities,代码行数:8,代码来源:conftest.py

示例3: communities

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
开发者ID:inveniosoftware,项目名称:invenio-communities,代码行数:9,代码来源:conftest.py

示例4: communities

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
开发者ID:nikofil,项目名称:zenodo,代码行数:12,代码来源:conftest.py

示例5: loadcommunities

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()
开发者ID:hachreak,项目名称:zenodo,代码行数:14,代码来源:communities.py

示例6: index

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,代码行数:33,代码来源:ui.py

示例7: index

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,代码行数:35,代码来源:ui.py

示例8: community_curation

def community_curation(record, user):
    """Generate a list of pending and accepted communities with permissions.

    Return a 4-tuple of lists (in order):
     * 'pending' communities, which can be curated by given user
     * 'accepted' communities, which can be curated by given user
     * All 'pending' communities
     * All 'accepted' communities
    """
    irs = ZenodoCommunity.get_irs(record).all()
    pending = list(set(ir.community for ir in irs))
    accepted = [Community.get(c) for c in record.get('communities', [])]
    # Additionally filter out community IDs that did not resolve (None)
    accepted = [c for c in accepted if c]

    # Check for global curation permission (all communities on this record).
    global_perm = None
    if user.is_anonymous:
        global_perm = False
    elif Permission(ActionNeed('admin-access')).can():
        global_perm = True

    if global_perm:
        return (pending, accepted, pending, accepted)
    else:
        return (
            [c for c in pending if _can_curate(c, user, record)],
            [c for c in accepted
             if _can_curate(c, user, record, accepted=True)],
            pending,
            accepted,
        )
开发者ID:zenodo,项目名称:zenodo,代码行数:32,代码来源:views.py

示例9: legacy_index

def legacy_index():
    """Legacy deposit."""
    c_id = request.args.get('c', type=str)
    if c_id:
        c = Community.get(c_id)
        return redirect('/communities/{0}/upload'.format(c.id))
    return redirect(url_for('invenio_deposit_ui.new'))
开发者ID:PixelDragon,项目名称:zenodo,代码行数:7,代码来源:views.py

示例10: test_fixed_communities_edit

def test_fixed_communities_edit(app, db, users, communities, deposit,
                                deposit_file, communities_autoadd_enabled):
    """Test automatic adding and requesting to fixed communities."""
    deposit = publish_and_expunge(db, deposit)
    pid, record = deposit.fetch_published()
    assert deposit['communities'] == ['zenodo', ]
    assert 'communities' not in record
    ir = InclusionRequest.query.one()
    assert ir.id_community == 'zenodo'
    assert ir.id_record == record.id

    # Open for edit
    deposit = deposit.edit()
    # Make sure 'zenodo' community is requested
    pid, record = deposit.fetch_published()
    assert deposit['communities'] == ['zenodo', ]
    assert not record.get('communities', [])
    assert InclusionRequest.query.count() == 1

    comm = Community.get('zenodo')
    comm.accept_record(record)
    record.commit()
    db.session.commit()

    # Publish and make sure nothing is missing
    deposit = publish_and_expunge(db, deposit)
    pid, record = deposit.fetch_published()
    assert deposit['communities'] == ['zenodo']
    assert record['communities'] == ['zenodo', ]
    assert record['_oai']['sets'] == ['user-zenodo', ]
    assert InclusionRequest.query.count() == 0
开发者ID:hachreak,项目名称:zenodo,代码行数:31,代码来源:test_communities_merging.py

示例11: test_accept_while_edit

def test_accept_while_edit(app, db, communities, deposit, deposit_file):
    """Test deposit publishing with concurrent events.

    Accept a record, while deposit in open edit and then published.
    """
    deposit['communities'] = ['c1', 'c2']
    deposit = _publish_and_expunge(db, deposit)
    assert InclusionRequest.query.count() == 2
    pid, record = deposit.fetch_published()
    assert deposit['communities'] == ['c1', 'c2']
    assert not record.get('communities', [])

    # Open for edit
    deposit = deposit.edit()
    pid, record = deposit.fetch_published()
    assert deposit['communities'] == ['c1', 'c2']
    assert not record.get('communities', [])
    assert InclusionRequest.query.count() == 2

    # Accept a record meanwhile
    c1 = Community.get('c1')
    c1.accept_record(record)
    record.commit()
    db.session.commit()

    # Publish and make sure nothing is missing
    deposit = _publish_and_expunge(db, deposit)
    pid, record = deposit.fetch_published()
    assert deposit['communities'] == ['c1', 'c2']
    assert record['communities'] == ['c1', ]
    assert InclusionRequest.query.count() == 1
    ir = InclusionRequest.query.one()
    assert ir.id_community == 'c2'
    assert ir.id_record == record.id
开发者ID:PixelDragon,项目名称:zenodo,代码行数:34,代码来源:test_communities_merging.py

示例12: community_curation

def community_curation(record, user):
    """Generate a list of pending and accepted communities with permissions.

    Return a 2-tuple containing two lists, first for 'pending' and second
    for 'accepted' communities. Each item in both of the list is another
    2-tuple of (Community, bool), describing community itself,
    and the permission (bool) to curate it.
    """
    irs = InclusionRequest.query.filter_by(id_record=record.id).order_by(InclusionRequest.id_community).all()
    pending = [ir.community for ir in irs]
    accepted = [Community.get(c) for c in record.get("communities", [])]
    # Additionally filter out community IDs that did not resolve (None)
    accepted = [c for c in accepted if c]

    # Check for global curation permission (all communites on this record).
    global_perm = None
    if user.is_anonymous:
        global_perm = False
    elif DynamicPermission(ActionNeed("admin-access")).can():
        global_perm = True

    if global_perm:
        return (pending, pending, accepted, accepted)
    else:
        return (
            [c for c in pending if _can_curate(c, user, record)],
            [c for c in accepted if _can_curate(c, user, record, accepted=True)],
            pending,
            accepted,
        )
开发者ID:krzysztof,项目名称:zenodo,代码行数:30,代码来源:views.py

示例13: communities_for_filtering

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
开发者ID:inveniosoftware,项目名称:invenio-communities,代码行数:17,代码来源:conftest.py

示例14: test_model_init

def test_model_init(app):
    """Test basic model initialization and actions."""
    with app.app_context():
        # Init the User and the Community
        user1 = create_test_user()
        comm1 = Community(id='comm1', id_user=user1.id)
        db.session.add(comm1)
        db.session.commit()
        communities_key = app.config["COMMUNITIES_RECORD_KEY"]
        # Create a record and accept it into the community by creating an
        # InclusionRequest and then calling the accept action
        rec1 = Record.create({'title': 'Foobar'})
        InclusionRequest.create(community=comm1, record=rec1)
        assert InclusionRequest.query.count() == 1
        comm1.accept_record(rec1)
        assert 'comm1' in rec1[communities_key]
        assert InclusionRequest.query.count() == 0

        # Likewise, reject a record from the community
        rec2 = Record.create({'title': 'Bazbar'})
        InclusionRequest.create(community=comm1, record=rec2)
        assert InclusionRequest.query.count() == 1
        comm1.reject_record(rec2)
        assert communities_key not in rec2  # dict key should not be created
        assert InclusionRequest.query.count() == 0

        # Add record to another community
        comm2 = Community(id='comm2', id_user=user1.id)
        db.session.add(comm2)
        db.session.commit()
        InclusionRequest.create(community=comm2, record=rec1)
        comm2.accept_record(rec1)
        assert communities_key in rec1
        assert len(rec1[communities_key]) == 2
        assert comm1.id in rec1[communities_key]
        assert comm2.id in rec1[communities_key]

        # Accept/reject a record to/from a community without inclusion request
        rec3 = Record.create({'title': 'Spam'})
        pytest.raises(InclusionRequestMissingError, comm1.accept_record, rec3)
        pytest.raises(InclusionRequestMissingError, comm1.reject_record, rec3)

        # Create two inclusion requests
        comm3 = Community(id='comm3', id_user=user1.id)
        db.session.add(comm3)
        db.session.commit()
        InclusionRequest.create(community=comm3, record=rec1)
        pytest.raises(InclusionRequestExistsError, InclusionRequest.create,
                      community=comm3, record=rec1)

        # Try to accept a record to a community twice (should raise)
        # (comm1 is already in rec1)
        pytest.raises(InclusionRequestObsoleteError, InclusionRequest.create,
                      community=comm1, record=rec1)
开发者ID:JavierDelgadoFernandez,项目名称:invenio-communities,代码行数:54,代码来源:test_invenio_communities.py

示例15: validate_publish

 def validate_publish(self):
     """Validate deposit."""
     super(ZenodoDeposit, self).validate()
     if len(self.files) == 0:
         raise MissingFilesError()
     if 'communities' in self:
         missing = [c for c in self['communities']
                    if Community.get(c) is None]
         if missing:
             raise MissingCommunityError(missing)
开发者ID:PixelDragon,项目名称:zenodo,代码行数:10,代码来源:api.py


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