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


Python models.Discussion类代码示例

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


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

示例1: discussion_admin

def discussion_admin(request):
    user_id = authenticated_userid(request)

    if not user_id:
        return HTTPFound(location='/login?next=/admin/discussions/')

    session = User.default_db

    context = dict(
        get_default_context(request),
        discussions=session.query(Discussion))

    if request.method == 'POST':

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

        (topic, slug, name, host, port,
            ssl, folder, password, username, homepage) = (
            g('topic'),
            g('slug'),
            g('mbox_name'),
            g('host'),
            g('port'),
            True if g('ssl') == 'on' else False,
            g('folder'),
            g('password'),
            g('username'),
            g('homepage')
            )

        discussion = Discussion(
            topic=topic,
            slug=slug
        )

        # Could raise an exception if there is no/incorrect scheme passed
        discussion.homepage = homepage
        session.add(discussion)

        create_default_permissions(session, discussion)
        mailbox_class = (
            MailingList if g('mailing_list_address') else IMAPMailbox)
        mailbox = mailbox_class(
            name=name,
            host=host,
            port=int(port),
            username=username,
            use_ssl=ssl,
            folder=folder,
            password=password,
        )

        if(g('mailing_list_address')):
            mailbox.post_email_address = g('mailing_list_address')
        mailbox.discussion = discussion

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

示例2: put_discussion_roles_for_user

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

示例3: discussion_as_graph

 def discussion_as_graph(self, discussion_id):
     from assembl.models import Discussion, AgentProfile
     local_uri = self.local_uri()
     discussion = Discussion.get(discussion_id)
     d_storage_name = self.discussion_storage_name()
     d_graph_iri = URIRef(self.discussion_graph_iri())
     v = get_virtuoso(self.session, d_storage_name)
     discussion_uri = URIRef(
         Discussion.uri_generic(discussion_id, local_uri))
     subjects = [s for (s,) in v.query(
         """SELECT DISTINCT ?s WHERE {
         ?s assembl:in_conversation %s }""" % (discussion_uri.n3()))]
     subjects.append(discussion_uri)
     participant_ids = list(discussion.get_participants(True))
     profiles = {URIRef(AgentProfile.uri_generic(id, local_uri))
                 for id in participant_ids}
     subjects.extend(profiles)
     # add pseudo-accounts
     subjects.extend((URIRef("%sAgentAccount/%d" % (local_uri, id))
                      for id in participant_ids))
     # print len(subjects)
     cg = ConjunctiveGraph(identifier=d_graph_iri)
     self.add_subject_data(v, cg, subjects)
     # add relationships of non-pseudo accounts
     for ((account, p, profile), g) in v.triples((None, SIOC.account_of, None)):
         if profile in profiles:
             cg.add((account, SIOC.account_of, profile, g))
             # Tempting: simplify with this.
             # cg.add((profile, FOAF.account, account, g))
     for (s, o, g) in v.query(
             '''SELECT ?s ?o ?g WHERE {
             GRAPH ?g {?s catalyst:expressesIdea ?o } .
             ?o assembl:in_conversation %s }''' % (discussion_uri.n3())):
         cg.add((s, CATALYST.expressesIdea, o, g))
     return cg
开发者ID:mydigilife,项目名称:assembl,代码行数:35,代码来源:virtuoso_mapping.py

示例4: add_local_role

def add_local_role(request):
    # Do not use check_permissions, this is a special case
    ctx = request.context
    user_id = request.authenticated_userid
    if not user_id:
        raise HTTPUnauthorized()
    discussion_id = ctx.get_discussion_id()
    discussion = Discussion.get(discussion_id)
    user_uri = User.uri_generic(user_id)
    if discussion_id is None:
        raise HTTPBadRequest()
    permissions = get_permissions(user_id, discussion_id)
    json = request.json_body
    if "discussion" not in json:
        json["discussion"] = Discussion.uri_generic(discussion_id)
    requested_user = json.get('user', None)
    if not requested_user:
        json['user'] = requested_user = user_uri
    elif requested_user != user_uri and P_ADMIN_DISC not in permissions:
        raise HTTPUnauthorized()
    if P_ADMIN_DISC not in permissions:
        if P_SELF_REGISTER in permissions:
            json['requested'] = False
            json['role'] = R_PARTICIPANT
            req_user = User.get_instance(requested_user)
            if not discussion.check_authorized_email(req_user):
                raise HTTPForbidden()
        elif P_SELF_REGISTER_REQUEST in permissions:
            json['requested'] = True
        else:
            raise HTTPUnauthorized()
    try:
        instances = ctx.create_object("LocalUserRole", json, user_id)
    except HTTPClientError as e:
        raise e
    except Exception as e:
        raise HTTPBadRequest(e)
    if instances:
        first = instances[0]
        db = first.db
        for instance in instances:
            db.add(instance)
        db.flush()
        # Side effect: materialize subscriptions.
        if not first.requested:
            # relationship may not be initialized
            user = first.user or User.get(first.user_id)
            user.get_notification_subscriptions(discussion_id, True)

        # Update the user's AgentStatusInDiscussion
        user.update_agent_status_subscribe(discussion)

        view = request.GET.get('view', None) or 'default'
        permissions = get_permissions(
            user_id, ctx.get_discussion_id())
        return CreationResponse(first, user_id, permissions, view)
开发者ID:assembl,项目名称:assembl,代码行数:56,代码来源:auth.py

示例5: test_cache_key

def test_cache_key(test_session):
    d = Discussion(
        topic=u"John Doe", slug="johndoe",
        subscribe_to_notifications_on_signup=False,
        creator=None,
        session=test_session)
    fn = test_cache_key
    result = d.generate_redis_key(fn) 
    expected_result = "test_cache_key_" + str(d.id) + "_21_42"
    assert result(d, 21, 42) == expected_result
开发者ID:assembl,项目名称:assembl,代码行数:10,代码来源:test_caching.py

示例6: discussion_edit

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

示例7: save_synthesis

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

示例8: get_user_has_permission

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

示例9: delete_discussion

def delete_discussion(session, discussion_id):
    from assembl.models import Discussion, DiscussionBoundBase
    # First, delete the discussion.
    session.delete(Discussion.get(discussion_id))
    session.flush()
    # See if anything is left...
    classes = DiscussionBoundBase._decl_class_registry.itervalues()
    classes_by_table = {
        cls.__dict__.get('__table__', None): cls for cls in classes}
    # Only direct subclass of abstract
    concrete_classes = set(filter(lambda cls:
        issubclass(cls, DiscussionBoundBase) and (not isabstract(cls))
        and isabstract(cls.mro()[1]),
        classes_by_table.values()))
    tables = DiscussionBoundBase.metadata.sorted_tables
    tables.reverse()
    for table in tables:
        if table not in classes_by_table:
            continue
        cls = classes_by_table[table]
        if cls not in concrete_classes:
            continue
        print 'deleting', cls.__name__
        query = session.query(cls.id)
        conds = cls.get_discussion_conditions(discussion_id)
        assert conds
        cond = and_(*conds)
        v = JoinColumnsVisitor(cls, query, classes_by_table)
        v.traverse(cond)
        query = v.final_query().filter(cond)
        if query.count():
            print "*" * 20, "Not all deleted!"
            session.query(cls).filter(
                cls.id.in_(query.subquery())).delete(False)
开发者ID:iilab,项目名称:assembl,代码行数:34,代码来源:clone_discussion.py

示例10: put_permissions_for_role

def put_permissions_for_role(request):
    discussion_id = request.matchdict['discussion_id']
    role_name = request.matchdict['role_name']
    session = Discussion.db()
    discussion = session.query(Discussion).get(discussion_id)
    if not discussion:
        raise HTTPNotFound("Discussion %s does not exist" % (discussion_id,))
    role = Role.get(name=role_name)
    if not role:
        raise HTTPNotFound("Role %s does not exist" % (role_name,))
    try:
        data = json.loads(request.body)
    except Exception as e:
        raise HTTPBadRequest("Malformed Json")
    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")
    permissions = set(session.query(Permission).filter(name in data).all())
    data = set(data)
    if len(permissions) != len(data):
        raise HTTPBadRequest("Not valid permissions: %s" % (repr(
            data - set((p.name for p in permissions))),))
    known_dp = session.query(DiscussionPermission).join(Permission).filter(
        role=role, discussion=discussion).all()
    dp_by_permission = {dp.permission.name: dp for dp in known_dp}
    known_permissions = set(dp.keys())
    for permission in known_permissions - permissions:
        session.delete(dp_by_permission(permission))
    for permission in permissions - known_permissions:
        session.add(DiscussionPermission(
            role=role, permission=permission, discussion=discussion))
    return {"added": list(permissions - known_permissions),
            "removed": list(known_permissions - permissions)}
开发者ID:hellsingblack,项目名称:assembl,代码行数:34,代码来源:auth.py

示例11: test_simultaneous_ajax_calls

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

示例12: discussion_as_graph

    def discussion_as_graph(self, discussion_id):
        self.ensure_discussion_storage(None)
        from assembl.models import Discussion
        d_storage_name = self.discussion_storage_name()
        d_graph_iri = URIRef(self.discussion_graph_iri())
        v = get_virtuoso(self.session, d_storage_name)
        discussion_uri = URIRef(
            Discussion.uri_generic(discussion_id, self.local_uri()))
        subjects = list(v.query(
            """SELECT DISTINCT ?s WHERE {
            ?s assembl:in_conversation %s }""" % (discussion_uri.n3())))
        subjects.append([discussion_uri])
        # print len(subjects)
        cg = ConjunctiveGraph(identifier=d_graph_iri)
        for (s,) in subjects:
            # Absurdly slow. DISTINCT speeds up a lot, but I get numbers.
            for p, o in v.query(
                'SELECT ?p ?o WHERE { graph %s { %s ?p ?o }}' % (
                        d_graph_iri.n3(), s.n3())):
                    cg.add((s, p, o))

        for (s, o, g) in v.query(
                '''SELECT ?s ?o ?g WHERE {
                GRAPH ?g {?s catalyst:expressesIdea ?o } .
                ?o assembl:in_conversation %s }''' % (discussion_uri.n3())):
            cg.add((s, CATALYST.expressesIdea, o, g))

        # TODO: Add roles

        return cg
开发者ID:iilab,项目名称:assembl,代码行数:30,代码来源:virtuoso_mapping.py

示例13: get_permissions_for_discussion

def get_permissions_for_discussion(request):
    discussion_id = request.matchdict['discussion_id']
    session = Discussion.db()
    discussion = session.query(Discussion).get(discussion_id)
    if not discussion:
        raise HTTPNotFound("Discussion %s does not exist" % (discussion_id,))
    return discussion.get_permissions_by_role()
开发者ID:hellsingblack,项目名称:assembl,代码行数:7,代码来源:auth.py

示例14: get_agents

def get_agents(request, discussion_only=False):
    discussion_id = int(request.matchdict['discussion_id'])
    discussion = Discussion.get(int(discussion_id))
    if not discussion:
        raise HTTPNotFound("Discussion with id '%s' not found." % discussion_id)
    view_def = request.GET.get('view')
    return _get_agents_real(
        discussion, authenticated_userid(request), view_def)
开发者ID:iilab,项目名称:assembl,代码行数:8,代码来源:agent.py

示例15: get_ideas

def get_ideas(request):
    discussion_id = request.matchdict['discussion_id']
    discussion = Discussion.get(id=int(discussion_id))
    if not discussion:
        raise HTTPNotFound("Discussion with id '%s' not found." % discussion_id)
    view_def = request.GET.get('view')
    ids = request.GET.getall('ids')
    return _get_ideas_real(discussion=discussion, view_def=view_def, ids=ids)
开发者ID:hellsingblack,项目名称:assembl,代码行数:8,代码来源:idea.py


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