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


Python Discussion.get_instance方法代码示例

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


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

示例1: test_simultaneous_ajax_calls

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def test_simultaneous_ajax_calls(request):
    g = lambda x: request.GET.get(x, None)

    session = User.default_db

    discussion_id = g('discussion_id')
    widget_id = g('widget_id')
    if not discussion_id:
        return HTTPBadRequest(
            explanation="Please provide a discussion_id parameter")
    if not widget_id:
        return HTTPBadRequest(
            explanation="Please provide a widget_id parameter")

    widget_id = int(widget_id)
    discussion_id = int(discussion_id)
    discussion = Discussion.get_instance(discussion_id)

    if not discussion:
        raise HTTPNotFound("Discussion with id '%d' not found." % (
            discussion_id,))

    user_id = authenticated_userid(request)
    assert user_id

    context = dict(
        get_default_context(request),
        discussion=discussion,
        discussion_id=discussion_id,
        widget_id=widget_id)

    return render_to_response(
        'admin/test_simultaneous_ajax_calls.jinja2',
        context,
        request=request)
开发者ID:festrade,项目名称:assembl,代码行数:37,代码来源:views.py

示例2: get_user_has_permission

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def get_user_has_permission(request):
    discussion_id = int(request.matchdict['discussion_id'])
    permission = request.matchdict['permission']
    discussion = Discussion.get_instance(discussion_id)
    if not discussion:
        raise HTTPNotFound("Discussion %d does not exist" % (discussion_id,))
    return a_users_with_permission(discussion_id, permission)
开发者ID:hypnotics,项目名称:assembl,代码行数:9,代码来源:auth.py

示例3: discussion_edit

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def discussion_edit(request):
    discussion_id = int(request.matchdict["discussion_id"])
    discussion = Discussion.get_instance(discussion_id)
    user_id = authenticated_userid(request)
    assert user_id
    permissions = get_permissions(user_id, discussion_id)
    partners = json.dumps(
        [p.generic_json(user_id=user_id, permissions=permissions) for p in discussion.partner_organizations]
    )

    if not discussion:
        raise HTTPNotFound("Discussion with id '%d' not found." % (discussion_id,))

    context = dict(
        get_default_context(request),
        discussion=discussion,
        admin_discussion_permissions_url=request.route_url("discussion_permissions", discussion_id=discussion.id),
        partners=partners,
    )

    if request.method == "POST":

        g = lambda x: request.POST.get(x, None)

        (topic, slug, objectives) = (g("topic"), g("slug"), g("objectives"))

        discussion.topic = topic
        discussion.slug = slug
        discussion.objectives = objectives

    return render_to_response("admin/discussion_edit.jinja2", context, request=request)
开发者ID:rmoorman,项目名称:assembl,代码行数:33,代码来源:views.py

示例4: put_discussion_roles_for_user

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def put_discussion_roles_for_user(request):
    discussion_id = request.matchdict['discussion_id']
    user_id = request.matchdict['user_id']
    discussion = Discussion.get_instance(discussion_id)
    if not discussion:
        raise HTTPNotFound("Discussion %s does not exist" % (discussion_id,))
    user = User.get_instance(user_id)
    if not user:
        raise HTTPNotFound("User id %s does not exist" % (user_id,))
    try:
        data = json.loads(request.body)
    except Exception as e:
        raise HTTPBadRequest("Malformed Json")
    session = Discussion.db()
    if not isinstance(data, list):
        raise HTTPBadRequest("Not a list")
    if data and frozenset((type(x) for x in data)) != frozenset((str,)):
        raise HTTPBadRequest("not strings")
    roles = set(session.query(Role).filter(name in data).all())
    data = set(data)
    if len(roles) != len(data):
        raise HTTPBadRequest("Not valid roles: %s" % (repr(
            data - set((p.name for p in roles))),))
    known_lu_roles = session.query(LocalUserRole).join(Role).filter(
        user=user, discussion=discussion).all()
    lur_by_role = {lur.role.name: lur for lur in known_lu_roles}
    known_roles = set(lur_by_role.keys())
    for role in known_roles - roles:
        session.query.delete(lur_by_role(role))
    for role in roles - known_roles:
        session.add(LocalUserRole(
            user=user, role=role, discussion=discussion))
    return {"added": list(roles - known_roles),
            "removed": list(known_roles - roles)}
开发者ID:hellsingblack,项目名称:assembl,代码行数:36,代码来源:auth.py

示例5: save_synthesis

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def save_synthesis(request):
    synthesis_id = request.matchdict['id']
    discussion_id = int(request.matchdict['discussion_id'])
    if synthesis_id == 'next_synthesis':
        discussion = Discussion.get_instance(discussion_id)
        synthesis = discussion.get_next_synthesis()
    else:
        synthesis = Synthesis.get_instance(synthesis_id)
    if not synthesis:
        raise HTTPBadRequest("Synthesis with id '%s' not found." % synthesis_id)

    synthesis_data = json.loads(request.body)
    user_id = request.authenticated_userid
    permissions = get_permissions(user_id, discussion_id)

    for key in ('subject', 'introduction', 'conclusion'):
        if key in synthesis_data:
            ls_data = synthesis_data[key]
            if ls_data is None:
                continue
            assert isinstance(ls_data, dict)
            current = LangString.create_from_json(
                ls_data, user_id, permissions=permissions)
            setattr(synthesis, key, current)

    Synthesis.default_db.add(synthesis)
    Synthesis.default_db.flush()

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

示例6: delete_discussion

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def delete_discussion(request):
    discussion_id = int(request.matchdict['discussion_id'])
    discussion = Discussion.get_instance(discussion_id)

    if not discussion:
        raise HTTPNotFound(
            "Discussion with id '%s' not found." % discussion_id)

    discussion.delete()
    return HTTPNoContent()
开发者ID:assembl,项目名称:assembl,代码行数:12,代码来源:discussion.py

示例7: get_permissions_for_user

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def get_permissions_for_user(request):
    discussion_id = request.matchdict['discussion_id']
    user_id = request.matchdict['user_id']
    discussion = Discussion.get_instance(discussion_id)
    if not discussion:
        raise HTTPNotFound("Discussion %s does not exist" % (discussion_id,))
    if user_id not in (Authenticated, Everyone):
        user = User.get_instance(user_id)
        if not user:
            raise HTTPNotFound("User id %s does not exist" % (user_id,))
    return a_permissions_for_user(discussion_id, user_id)
开发者ID:hellsingblack,项目名称:assembl,代码行数:13,代码来源:auth.py

示例8: get_discussion

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def get_discussion(request):
    discussion_id = int(request.matchdict['discussion_id'])
    discussion = Discussion.get_instance(discussion_id)
    view_def = request.GET.get('view') or 'default'
    user_id = authenticated_userid(request)
    permissions = get_permissions(user_id, discussion_id)

    if not discussion:
        raise HTTPNotFound(
            "Discussion with id '%s' not found." % discussion_id)

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

示例9: get_discussion

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def get_discussion(request):
    discussion_id = int(request.matchdict['discussion_id'])
    discussion = Discussion.get_instance(discussion_id)
    is_etalab_request = request.matched_route.name == 'etalab_discussion'
    view_def = request.GET.get(
        'view', 'etalab' if is_etalab_request else 'default')
    user_id = request.authenticated_userid or Everyone
    permissions = get_permissions(user_id, discussion_id)

    if not discussion:
        raise HTTPNotFound(
            "Discussion with id '%s' not found." % discussion_id)

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

示例10: post_discussion

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def post_discussion(request):
    discussion_id = int(request.matchdict['discussion_id'])
    discussion = Discussion.get_instance(discussion_id)

    if not discussion:
        raise HTTPNotFound(
            "Discussion with id '%s' not found." % discussion_id)

    discussion_data = json.loads(request.body)

    discussion.topic = discussion_data.get('topic', discussion.slug)
    discussion.slug = discussion_data.get('slug', discussion.slug)
    discussion.objectives = discussion_data.get(
        'objectives', discussion.objectives)

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

示例11: get_sources

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def get_sources(request):
    discussion_id = int(request.matchdict['discussion_id'])
    discussion = Discussion.get_instance(discussion_id)
    view_def = request.GET.get('view') or 'default'

    if not discussion:
        raise HTTPNotFound(
            "Discussion with id '%s' not found." % discussion_id
        )

    user_id = authenticated_userid(request)
    permissions = get_permissions(user_id, discussion_id)

    res = [source.generic_json(view_def, user_id, permissions)
           for source in discussion.sources]
    return [x for x in res if x is not None]
开发者ID:hypnotics,项目名称:assembl,代码行数:18,代码来源:sources.py

示例12: get_synthesis

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def get_synthesis(request):
    synthesis_id = request.matchdict['id']
    if synthesis_id == 'next_synthesis':
        discussion_id = int(request.matchdict['discussion_id'])
        discussion = Discussion.get_instance(discussion_id)
        synthesis = discussion.get_next_synthesis()
    else:
        synthesis = Synthesis.get_instance(synthesis_id)
    if not synthesis:
        raise HTTPNotFound("Synthesis with id '%s' not found." % synthesis_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)

    return synthesis.generic_json(view_def, user_id, permissions)
开发者ID:Lornz-,项目名称:assembl,代码行数:19,代码来源:synthesis.py

示例13: mark_post_read

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def mark_post_read(request):
    discussion_id = int(request.matchdict["discussion_id"])
    discussion = Discussion.get_instance(discussion_id)
    post_id = request.matchdict["id"]
    post = Post.get_instance(post_id)
    if not post:
        raise HTTPNotFound("Post with id '%s' not found." % post_id)
    post_id = post.id
    user_id = authenticated_userid(request)
    if not user_id:
        raise HTTPUnauthorized()
    read_data = json.loads(request.body)
    db = Discussion.db()
    change = False
    with transaction.manager:
        if read_data.get("read", None) is False:
            view = db.query(ViewPost).filter(ViewPost.post_id == post_id).filter(Action.actor_id == user_id).first()
            if view:
                change = True
                db.delete(view)
        else:
            count = db.query(ViewPost).filter(ViewPost.post_id == post_id).filter(Action.actor_id == user_id).count()
            if not count:
                change = True
                db.add(ViewPost(post=post, actor_id=user_id))

    new_counts = []
    if change:
        new_counts = Idea.idea_counts(discussion_id, post_id, user_id)

    return {
        "ok": True,
        "ideas": [
            {
                "@id": Idea.uri_generic(idea_id),
                "@type": db.query(Idea).get(idea_id).external_typename(),
                "num_posts": total_posts,
                "num_read_posts": read_posts,
            }
            for (idea_id, total_posts, read_posts) in new_counts
        ],
    }
开发者ID:hellsingblack,项目名称:assembl,代码行数:44,代码来源:post.py

示例14: save_synthesis

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def save_synthesis(request):
    synthesis_id = request.matchdict['id']
    if synthesis_id == 'next_synthesis':
        discussion_id = int(request.matchdict['discussion_id'])
        discussion = Discussion.get_instance(discussion_id)
        synthesis = discussion.get_next_synthesis()
    else:
        synthesis = Synthesis.get_instance(synthesis_id)
    if not synthesis:
        raise HTTPBadRequest("Synthesis with id '%s' not found." % synthesis_id)

    synthesis_data = json.loads(request.body)

    synthesis.subject = synthesis_data.get('subject')
    synthesis.introduction = synthesis_data.get('introduction')
    synthesis.conclusion = synthesis_data.get('conclusion')

    Synthesis.default_db.add(synthesis)
    Synthesis.default_db.flush()

    return {'ok': True, 'id': synthesis.uri()}
开发者ID:Lornz-,项目名称:assembl,代码行数:23,代码来源:synthesis.py

示例15: mark_post_read

# 需要导入模块: from assembl.models import Discussion [as 别名]
# 或者: from assembl.models.Discussion import get_instance [as 别名]
def mark_post_read(request):
    """Mark this post as un/read. Return the read post count for all affected ideas."""
    discussion_id = int(request.matchdict['discussion_id'])
    discussion = Discussion.get_instance(discussion_id)
    post_id = request.matchdict['id']
    post = Post.get_instance(post_id)
    if not post:
        raise HTTPNotFound("Post with id '%s' not found." % post_id)
    post_id = post.id
    user_id = request.authenticated_userid
    if not user_id:
        raise HTTPUnauthorized()
    read_data = json.loads(request.body)
    db = discussion.db
    change = False
    with transaction.manager:
        if read_data.get('read', None) is False:
            view = db.query(ViewPost).filter_by(
                post_id=post_id, actor_id=user_id,
                tombstone_date=None).first()
            if view:
                change = True
                view.is_tombstone = True
        else:
            count = db.query(ViewPost).filter_by(
                post_id=post_id, actor_id=user_id,
                tombstone_date=None).count()
            if not count:
                change = True
                db.add(ViewPost(post=post, actor_id=user_id))

    new_counts = []
    if change:
        new_counts = Idea.idea_read_counts(discussion_id, post_id, user_id)

    return { "ok": True, "ideas": [
        {"@id": Idea.uri_generic(idea_id),
         "num_read_posts": read_posts
        } for (idea_id, read_posts) in new_counts] }
开发者ID:assembl,项目名称:assembl,代码行数:41,代码来源:post.py


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