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


Python Idea.get_instance方法代码示例

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


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

示例1: put_extract

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def put_extract(request):
    """
    Updating an Extract
    """
    extract_id = request.matchdict['id']
    user_id = authenticated_userid(request)

    updated_extract_data = json.loads(request.body)
    extract = Extract.get_instance(extract_id)
    if not extract:
        raise HTTPNotFound("Extract with id '%s' not found." % extract_id)

    extract.owner_id = user_id or get_database_id("User", extract.owner_id)
    extract.order = updated_extract_data.get('order', extract.order)
    idea_id = updated_extract_data.get('idIdea', None)
    if idea_id:
        idea = Idea.get_instance(idea_id)
        if(idea.get_discussion_id() != extract.get_discussion_id()):
            raise HTTPBadRequest(
                "Extract from discussion %s cannot be associated with an idea from a different discussion." % extract.get_discussion_id())
        extract.idea = idea
    else:
        extract.idea = None

    Extract.db.add(extract)
    #TODO: Merge ranges. Sigh.

    return {'ok': True}
开发者ID:bastnic,项目名称:assembl,代码行数:30,代码来源:extract.py

示例2: widget_view

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def widget_view(request):
    # IF_OWNED not applicable for widgets... so far
    ctx = request.context
    user_id = authenticated_userid(request) or Everyone
    permissions = get_permissions(
        user_id, ctx.get_discussion_id())
    check_permissions(ctx, user_id, permissions, CrudPermissions.READ)
    view = (request.matchdict or {}).get('view', None)\
        or ctx.get_default_view() or 'default'
    json = ctx._instance.generic_json(view, user_id, permissions)
    # json['discussion'] = ...
    if user_id != Everyone:
        user = User.get(user_id)
        user_state = ctx._instance.get_user_state(user_id)
        json['user'] = user.generic_json(view, user_id, permissions)
        json['user_permissions'] = get_permissions(
            user_id, ctx._instance.get_discussion_id())
        if user_state is not None:
            json['user_state'] = user_state
    target_id = request.GET.get('target', None)
    if target_id:
        idea = Idea.get_instance(target_id)
        if idea:
            json['target'] = idea.generic_json(view, user_id, permissions)
        else:
            return HTTPNotFound("No idea "+target_id)
    return json
开发者ID:Lornz-,项目名称:assembl,代码行数:29,代码来源:widget.py

示例3: create_idea

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def create_idea(request):
    discussion_id = int(request.matchdict['discussion_id'])
    session = Discussion.default_db
    discussion = session.query(Discussion).get(int(discussion_id))
    user_id = request.authenticated_userid
    permissions = get_permissions(user_id, discussion.id)
    idea_data = json.loads(request.body)
    kwargs = {
        "discussion": discussion
    }

    for key, attr_name in langstring_fields.iteritems():
        if key in idea_data:
            ls_data = idea_data[key]
            if ls_data is None:
                continue
            assert isinstance(ls_data, dict)
            current = LangString.create_from_json(
                ls_data, user_id, permissions=permissions)
            kwargs[attr_name] = current

    new_idea = Idea(**kwargs)

    session.add(new_idea)

    if idea_data['parentId']:
        parent = Idea.get_instance(idea_data['parentId'])
    else:
        parent = discussion.root_idea
    session.add(IdeaLink(source=parent, target=new_idea, order=idea_data.get('order', 0.0)))

    session.flush()

    return {'ok': True, '@id': new_idea.uri()}
开发者ID:assembl,项目名称:assembl,代码行数:36,代码来源:idea.py

示例4: add_idea_to_synthesis

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def add_idea_to_synthesis(request):
    """Add an idea to an ExplictSubgraphView"""
    ctx = request.context
    graph_view = ctx.parent_instance
    if isinstance(graph_view, Synthesis) and not graph_view.is_next_synthesis:
        raise HTTPBadRequest("Synthesis is published")
    content = request.json
    idea_id = content.get('@id', None)
    if not idea_id:
        raise HTTPBadRequest("Post an idea with its @id")
    idea = Idea.get_instance(idea_id)
    if not idea:
        raise HTTPNotFound("Unknown idea")
    link = SubGraphIdeaAssociation(idea=idea, sub_graph=graph_view)
    duplicate = link.find_duplicate(False)
    if duplicate:
        link.delete()
        return duplicate.idea.generic_json()
    graph_view.db.add(link)
    graph_view.db.expire(graph_view, ["idea_assocs"])
    graph_view.send_to_changes()
    # special location
    return Response(
        json.dumps(idea.generic_json()), 201, content_type='application/json',
        location=request.url + "/" + str(idea.id))
开发者ID:festrade,项目名称:assembl,代码行数:27,代码来源:synthesis.py

示例5: post_to_vote_votables

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def post_to_vote_votables(request):
    ctx = request.context
    target_id = request.POST.get('id', None)
    idea = None
    if target_id:
        idea = Idea.get_instance(target_id)
    if not idea:
        raise HTTPNotFound
    widget = ctx.parent_instance
    widget.add_votable(idea)
    return HTTPOk()  # Not sure this can be called a creation
开发者ID:Lornz-,项目名称:assembl,代码行数:13,代码来源:widget.py

示例6: get_idea

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def get_idea(request):
    idea_id = request.matchdict['id']
    idea = Idea.get_instance(idea_id)
    view_def = request.GET.get('view')
    discussion_id = int(request.matchdict['discussion_id'])
    user_id = authenticated_userid(request)
    permissions = get_permissions(user_id, discussion_id)

    if not idea:
        raise HTTPNotFound("Idea with id '%s' not found." % idea_id)

    return idea.generic_json(view_def, user_id, permissions)
开发者ID:iilab,项目名称:assembl,代码行数:14,代码来源:idea.py

示例7: get_idea

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def get_idea(request):
    idea_id = request.matchdict['id']
    idea = Idea.get_instance(idea_id)
    view_def = request.GET.get('view')

    if not idea:
        raise HTTPNotFound("Idea with id '%s' not found." % idea_id)

    if view_def:
        return idea.generic_json(view_def)
    else:
        return idea.generic_json()
开发者ID:hellsingblack,项目名称:assembl,代码行数:14,代码来源:idea.py

示例8: get_idea_extracts

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def get_idea_extracts(request):
    idea_id = request.matchdict["id"]
    idea = Idea.get_instance(idea_id)
    view_def = request.GET.get("view") or "default"
    discussion_id = int(request.matchdict["discussion_id"])
    user_id = authenticated_userid(request) or Everyone
    permissions = get_permissions(user_id, discussion_id)

    if not idea:
        raise HTTPNotFound("Idea with id '%s' not found." % idea_id)

    extracts = Extract.default_db.query(Extract).filter(Extract.idea_id == idea.id).order_by(Extract.order.desc())

    return [extract.generic_json(view_def, user_id, permissions) for extract in extracts]
开发者ID:uniteddiversity,项目名称:assembl,代码行数:16,代码来源:idea.py

示例9: get_idea_extracts

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def get_idea_extracts(request):
    idea_id = request.matchdict['id']
    idea = Idea.get_instance(idea_id)
    view_def = request.GET.get('view')

    if not idea:
        raise HTTPNotFound("Idea with id '%s' not found." % idea_id)

    extracts = Extract.db.query(Extract).filter(
        Extract.idea_id == idea.id
    ).order_by(Extract.order.desc())

    if view_def:
        return [extract.generic_json(view_def) for extract in extracts]
    else:
        return [extract.serializable() for extract in extracts]
开发者ID:hellsingblack,项目名称:assembl,代码行数:18,代码来源:idea.py

示例10: put_extract

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def put_extract(request):
    """
    Updating an Extract
    """
    extract_id = request.matchdict['id']
    user_id = authenticated_userid(request)
    discussion_id = int(request.matchdict['discussion_id'])

    if not user_id:
        # Straight from annotator
        token = request.headers.get('X-Annotator-Auth-Token')
        if token:
            token = decode_token(
                token, request.registry.settings['session.secret'])
            if token:
                user_id = token['userId']
    if not user_id:
        user_id = Everyone

    updated_extract_data = json.loads(request.body)
    extract = Extract.get_instance(extract_id)
    if not extract:
        raise HTTPNotFound("Extract with id '%s' not found." % extract_id)

    if not (user_has_permission(discussion_id, user_id, P_EDIT_EXTRACT)
        or (user_has_permission(discussion_id, user_id, P_EDIT_MY_EXTRACT)
            and user_id == extract.owner_id)):
        return HTTPForbidden()

    extract.owner_id = user_id or get_database_id("User", extract.owner_id)
    extract.order = updated_extract_data.get('order', extract.order)
    extract.important = updated_extract_data.get('important', extract.important)
    idea_id = updated_extract_data.get('idIdea', None)
    if idea_id:
        idea = Idea.get_instance(idea_id)
        if(idea.discussion != extract.discussion):
            raise HTTPBadRequest(
                "Extract from discussion %s cannot be associated with an idea from a different discussion." % extract.get_discussion_id())
        extract.idea = idea
    else:
        extract.idea = None

    Extract.db.add(extract)
    #TODO: Merge ranges. Sigh.

    return {'ok': True}
开发者ID:iilab,项目名称:assembl,代码行数:48,代码来源:extract.py

示例11: delete_idea

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def delete_idea(request):
    idea_id = request.matchdict['id']
    idea = Idea.get_instance(idea_id)

    if not idea:
        raise HTTPNotFound("Idea with id '%s' not found." % idea_id)
    if isinstance(idea, RootIdea):
        raise HTTPBadRequest("Cannot delete root idea.")
    num_childrens = len(idea.children)
    if num_childrens > 0:
        raise HTTPBadRequest("Idea cannot be deleted because it still has %d child ideas." % num_childrens)
    num_extracts = len(idea.extracts)
    if num_extracts > 0:
        raise HTTPBadRequest("Idea cannot be deleted because it still has %d extracts." % num_extracts)
    db = Idea.db()
    db.delete(idea)
    request.response.status = HTTPNoContent.code
    return HTTPNoContent()
开发者ID:iilab,项目名称:assembl,代码行数:20,代码来源:idea.py

示例12: create_idea

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def create_idea(request):
    discussion_id = int(request.matchdict["discussion_id"])
    session = Discussion.default_db
    discussion = session.query(Discussion).get(int(discussion_id))
    idea_data = json.loads(request.body)

    new_idea = Idea(short_title=idea_data["shortTitle"], long_title=idea_data["longTitle"], discussion=discussion)

    session.add(new_idea)

    if idea_data["parentId"]:
        parent = Idea.get_instance(idea_data["parentId"])
    else:
        parent = discussion.root_idea
    session.add(IdeaLink(source=parent, target=new_idea, order=idea_data.get("order", 0.0)))

    session.flush()

    return {"ok": True, "@id": new_idea.uri()}
开发者ID:uniteddiversity,项目名称:assembl,代码行数:21,代码来源:idea.py

示例13: test_add_subidea_in_synthesis

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def test_add_subidea_in_synthesis(
        discussion, test_app, synthesis_1, subidea_1_1, test_session):
    new_idea_r = test_app.post(
        '/data/Discussion/%d/views/%d/ideas/%d/children' % (
            discussion.id, synthesis_1.id, subidea_1_1.id),
        {"short_title": "New subidea"})
    assert new_idea_r.status_code == 201
    link = new_idea_r.location
    new_idea = Idea.get_instance(link)
    assert new_idea
    db = discussion.db
    idea_link = db.query(IdeaLink).filter_by(
        target=new_idea, source=subidea_1_1).first()
    assert idea_link
    idea_assoc = db.query(SubGraphIdeaAssociation).filter_by(
        idea=new_idea, sub_graph=synthesis_1).first()
    assert idea_assoc
    idealink_assoc = db.query(SubGraphIdeaLinkAssociation).filter_by(
        sub_graph=synthesis_1, idea_link=idea_link).first()
    assert idealink_assoc
开发者ID:festrade,项目名称:assembl,代码行数:22,代码来源:test_api2.py

示例14: delete_idea

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def delete_idea(request):
    idea_id = request.matchdict['id']
    idea = Idea.get_instance(idea_id)

    if not idea:
        raise HTTPNotFound("Idea with id '%s' not found." % idea_id)
    if isinstance(idea, RootIdea):
        raise HTTPBadRequest("Cannot delete root idea.")
    num_childrens = len(idea.children)
    if num_childrens > 0:
        raise HTTPBadRequest("Idea cannot be deleted because it still has %d child ideas." % num_childrens)
    num_extracts = len(idea.extracts)
    if num_extracts > 0:
        raise HTTPBadRequest("Idea cannot be deleted because it still has %d extracts." % num_extracts)
    for link in idea.source_links:
        link.is_tombstone = True
    idea.is_tombstone = True
    # Maybe return tombstone() ?
    request.response.status = HTTPNoContent.code
    return HTTPNoContent()
开发者ID:assembl,项目名称:assembl,代码行数:22,代码来源:idea.py

示例15: get_idea_extracts

# 需要导入模块: from assembl.models import Idea [as 别名]
# 或者: from assembl.models.Idea import get_instance [as 别名]
def get_idea_extracts(request):
    idea_id = request.matchdict['id']
    idea = Idea.get_instance(idea_id)
    view_def = request.GET.get('view')
    discussion_id = int(request.matchdict['discussion_id'])
    user_id = authenticated_userid(request)
    permissions = get_permissions(user_id, discussion_id)

    if not idea:
        raise HTTPNotFound("Idea with id '%s' not found." % idea_id)

    extracts = Extract.db.query(Extract).filter(
        Extract.idea_id == idea.id
    ).order_by(Extract.order.desc())

    if view_def:
        return [extract.generic_json(view_def, user_id, permissions)
                for extract in extracts]
    else:
        return [extract.serializable() for extract in extracts]
开发者ID:iilab,项目名称:assembl,代码行数:22,代码来源:idea.py


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