• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.Node类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: post

 def post(self,request,  *args, **kwargs):
     
     # check name is free
     
     if Node.objects.filter(parent=request.POST.get('parent'), name=request.POST.get('name')).count() > 0:
         return HttpResponse("This name already exists", status=400)
     
     node = Node(parent_id=request.POST.get('parent'), name=request.POST.get('name'))
     node.save()
     
     if use_cacheops:
         print 'invalidate'
         invalidate_model(Node)
         node = Node.objects.get(pk=node.pk)
         
     
     return HttpResponse(simplejson.dumps({
                 'name' : node.name,
                 'icon' : 'default',
                 'loaded' : True,
                 'pk' : node.pk,
                 'position' : list(node.parent.get_children()).index(node),
                 'children' : [],
                 'parent' : node.parent.pk if node.parent is not None else None
             }), content_type="application/json", status=201)
开发者ID:Contexte,项目名称:django-tree,代码行数:25,代码来源:views.py


示例2: menu

def menu(abs_path=''):
    base = Node.all().filter('abs_path = ', abs_path).get()
    qs = Node.all().filter('active = ', True).filter('state = ', PUBLISHED)
    l = len(base.abs_path)
    nodes = dict([(n.get_key(), n) for n in qs if n.abs_path.startswith(base.abs_path)])
    node = simple_rec(base, nodes)
    return node
开发者ID:4416,项目名称:hazel-cms,代码行数:7,代码来源:__init__.py


示例3: post

 def post(self, urlname):
     if not self.has_permission:
         return
     if not self.current_user.is_admin:
         return self.redirect_next_url()
     node = Node.get(urlname=urlname)
     if not node:
         return self.redirect_next_url()
     user = self.current_user
     args = self.request.arguments
     try:
         selected = args.get('parent_name')
         print(selected)
     except:
         selected = [n.name for n in node.parent_nodes]
         args = {'name': [node.name], 'urlname': [node.urlname],
                 'description': [node.description], 'style': [node.style]}
     form = NodeEditForm.init(Node.get_node_choices(), selected, args=args,
             node=node)
     if form.validate():
         node = form.save(user, node=node)
         result = {'status': 'success', 'message': '节点修改成功',
                 'node_url': node.url}
         if self.is_ajax:
             return self.write(result)
         self.flash_message(result)
         return self.redirect(node.url)
     if self.is_ajax:
         return self.write(form.result)
     return self.render("node/edit.html", form=form, node=node)
开发者ID:KeenTurbo,项目名称:collipa,代码行数:30,代码来源:node.py


示例4: page_path

def page_path(slug, **kwargs):
    p = Node.all().filter('abs_path = ', slug).get()
    if p is None:
        p = Node.all().filter('slug = ', slug).get()
    if p is None:
        return u''
    return p.get_absolute_url(**kwargs)
开发者ID:4416,项目名称:hazel-cms,代码行数:7,代码来源:__init__.py


示例5: delete

	def delete(self, node_id = None):
		node = Node.query.filter_by(id = node_id).first()
		if node: 
			Node.delete(id = node.id)
			return jsonify(ApiObjects(node.json()))
		else:
			jsonify(ApiObjects())
开发者ID:Hackerfarm,项目名称:techrice,代码行数:7,代码来源:resources.py


示例6: calculate_connected_component

def calculate_connected_component(index, graph, top_artists, talky=False):
    """
	Takes the given graph and computes the following measures:
		- size (number of nodes)
		[- diameter]
		- density
		- degree
		- closeness_centrality
		[- betweenness_centrality]
		[- eccentricity]

	The first three measures are computed for each connected component.
	The remaining ones are computed for each node.

	The result is written to a database (see tricorder.models).
	"""
    is_real_graph = graph.number_of_edges() > 0
    num_artists = 0
    num_top_artists = 0

    # calculate measures (only if we have edges!)
    density = nx.density(graph) if is_real_graph else 0
    # print "diameter..."
    # diameter = nx.diameter(graph) if is_real_graph else 0
    degree = sc.degree_centrality(graph) if is_real_graph else {}
    closeness = sc.closeness_centrality(graph) if is_real_graph else {}
    # betweenness = sc.betweenness_centrality(graph) if is_real_graph else {}
    # print "eccentricity..."
    # eccentricity = sc.eccentricity(graph) if is_real_graph else {}

    # create Node DB entries
    for id, attrs in graph.node.items():
        if attrs["type"] == "artist":
            num_artists += 1
            if attrs["name"] in top_artists:
                num_top_artists += 1
                # ecc = 1/eccentricity[id] if id in eccentricity else 0 # need an extra variable here since division by zero is evil
        Node.create(
            nid=int(id),
            pid=graph.graph["pid"],
            node_type=attrs["type"],
            name=attrs["name"],
            degree=degree.get(id, 0),
            closeness=closeness.get(id, 0),
        )
        # eccentricity=ecc)#, betweenness=betweenness.get(id, 0))

        # create Partition DB entry
    Partition.create(
        pid=graph.graph["pid"],  # diameter=diameter,
        num_nodes=graph.number_of_nodes(),
        num_edges=graph.number_of_edges(),
        num_artists=num_artists,
        num_top_artists=num_top_artists,
        density=density,
    )

    if talky and index % 500 == 0:
        print index
开发者ID:Wolff09,项目名称:nap,代码行数:59,代码来源:calculator.py


示例7: test_automata_without_final_states

    def test_automata_without_final_states(self):
        initial = Node()
        final = Node()
        initial.add_transition('a', final)
        automata = Automata([initial, final], ['a'], initial, [])

        #assert para que haya alguno, la idea es que si no tendría que tirar excepción.
        self.assertTrue(automata.initial == initial)
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:8,代码来源:test_models.py


示例8: get

 def get(self):
     node_id = int(self.get_argument('node_id', 0))
     node = Node.get(id=node_id)
     if node:
         selected = [node.name]
     else:
         selected = []
     form = NodeForm.init(Node.get_node_choices(), selected)
     return self.render("node/create.html", form=form)
开发者ID:ljtyzhr,项目名称:collipa,代码行数:9,代码来源:node.py


示例9: test_is_deterministic_automata__det

    def test_is_deterministic_automata__det(self):
        initial = Node()
        final = Node()
        other_node = Node()
        initial.add_transition('a', final)
        automata = Automata([initial, final, other_node], ['a'], initial, [final])

        self.assertTrue(automata.is_deterministic())
        self.assertFalse(automata.has_lambda())
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:9,代码来源:test_models.py


示例10: setNode

def setNode(stub, raddr):
	fChar = stub[:1]
	if fChar.isalpha():
		fChar = fChar.lower()
	else:
		fChar = "else"

	a = Node(stub = stub, remoteaddrs = raddr, f = fChar)
	a.put()
开发者ID:var,项目名称:cs306,代码行数:9,代码来源:dataaccess.py


示例11: create_structureNode

def create_structureNode(long_title, text="", authors=()):
    structure = Node(node_type=Node.STRUCTURE_NODE, title=long_title)
    structure.save()
    text_obj = Text(node=structure, text=text)
    text_obj.save()
    for author in authors:
        text_obj.authors.add(author)
    text_obj.save()
    return structure
开发者ID:justelex,项目名称:Findeco,代码行数:9,代码来源:factory.py


示例12: add

def add(request, key):
    """ add a new page
        to the set"""
    to = key # lame but it does the trick for now
    blocks = []
    form = PageForm(request.form)
    add  = BlockAddForm(request.form, prefix='_add')

    form.layout.choices =  Layout.get_key_to_path()
    if request.method == 'POST':
        # some logic to find __block elements.
        for key in request.form:
            if key.startswith('__block:'):
                name = key.split('__',2)[1][6:]
                blocks.append((name, BlockForm(request.form, prefix='__block:%s__' % name)))
        if add.validate() and add.add.data is True:
            blocks.append((add.name.data, BlockForm(prefix='__block:%s__' % add.name.data)))
            add = BlockAddForm(prefix='_add')
        elif form.validate() and all([block.validate() for _, block in blocks]):
            name = form.name.data
            slug = form.slug.data
            breadcrumb = form.breadcrumb.data
            state = form.state.data
            active = form.active.data
            if len(slug) < 1:
                slug = slugify(name)
            author = users.get_current_user()
            updated = datetime.now()

            description = form.description.data
            keywords = form.keywords.data
            body = form.body.data
            content_type = form.content_type.data
            if form.layout.data == 'Layout:None':
                layout = None
            else:
                layout = Layout.get(form.layout.data.split(':',1)[1])
            page = Node.add(to=to, name=name, slug=slug, breadcrumb=breadcrumb,
                            updated=updated, author=author, body=body,
                            description=description, keywords=keywords, layout=layout,
                            content_type=content_type,
                            state=state, active=active, type=PAGE)
            done = []
            try:
                for name, block in blocks:
                    b = Block(node=page, name=name, body=block.body.data)
                    b.put()
                    done.append(b)
            except:
                db.delete(done)
                Node.drop(page.get_key())
            if form.save.data is True:
                return redirect(url_for('nut:pages/list_pages'), 301)
            if form.cont.data is True:
                return redirect(url_for('nut:pages/edit', key=page.get_key()), 301)

    return render_template('app:pages/form.html', form=form, add=add, blocks=blocks)
开发者ID:4416,项目名称:hazel-cms,代码行数:57,代码来源:views.py


示例13: test_is_deterministic_node__not_det

    def test_is_deterministic_node__not_det(self):
        tested = Node()
        target1 = Node()
        target3 = Node()
        s = 'a'

        tested.add_transition(s, target1)
        tested.add_transition(s, target3)

        self.assertFalse(tested.is_deterministic())
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:10,代码来源:test_models.py


示例14: test_add_transition__existing_symbol

    def test_add_transition__existing_symbol(self):
        tested = Node()
        target1 = Node()
        target2 = Node()
        s = 'a'

        tested.add_transition(s, target1)
        tested.add_transition(s, target2)

        self.assertEqual(set([target1, target2]), set(tested.transitions[s]))
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:10,代码来源:test_models.py


示例15: test_add_transition__new_symbol

    def test_add_transition__new_symbol(self):
        tested = Node()
        target = Node()
        s = 'a'

        self.assertFalse(s in tested.transitions)
        tested.add_transition(s, target)

        self.assertTrue(s in tested.transitions)
        self.assertEqual([target], tested.transitions[s])
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:10,代码来源:test_models.py


示例16: test_construction_automata__extra_final

    def test_construction_automata__extra_final(self):
        initial = Node()
        final = Node()
        initial.add_transition('a', final)

        states = [initial, final]
        symbols = ['a']

        with self.assertRaises(FinalsNotInStatesException):
            Automata(states, symbols, initial, [final, Node()])
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:10,代码来源:test_models.py


示例17: test_build_child_tree_path

    def test_build_child_tree_path(self):
        node = Node.objects.get(pk=6)
        child_node = Node(parent=node)
        self.assert_empty_tree_path(child_node)
        child_node.save()

        self.assertEquals(
            node.tree_path+PATH_SEPARATOR+child_node.zerro_filled_pk,
            child_node.tree_path
        )
开发者ID:RANUX,项目名称:django-fktree,代码行数:10,代码来源:tests.py


示例18: get

 def get(self):
     node_id = force_int(self.get_argument('node_id', 0), 0)
     node = Node.get(id=node_id)
     if node:
         selected = node.name
     else:
         selected = None
     choices = Node.get_node_choices()
     form = TopicForm.init(choices=choices, selected=selected)
     return self.render("topic/create.html", form=form, node=node)
开发者ID:ljtyzhr,项目名称:collipa,代码行数:10,代码来源:topic.py


示例19: test_add_terminal_node__ejemplo_simple

    def test_add_terminal_node__ejemplo_simple(self):
        q0 = Node('q0')
        q1 = Node('q1')
        q2 = Node('q2')

        q0.add_transition('a', q1)
        q1.add_transition('b', q2)
        q2.add_transition('a', q2)
        q2.add_transition('b', q2)

        symbols = ['a', 'b']
        automata = Automata([q0, q1, q2], symbols, q0, [q2])

        with_terminal_node = add_terminal_node(automata)

        self.assertEqual(automata.symbols, with_terminal_node.symbols)
        self.assertEqual(len(automata.states) + 1, len(with_terminal_node.states))

        q0T = with_terminal_node.state_by_name("q0")
        q1T = with_terminal_node.state_by_name("q1")
        q2T = with_terminal_node.state_by_name("q2")
        qT = with_terminal_node.state_by_name("qT")

        self.assertEqual(symbols, q0T.transitions.keys())
        self.assertEqual([q1T], q0T.transitions['a'])
        self.assertEqual([qT], q0T.transitions['b'])
        self.assertEqual(symbols, q1T.transitions.keys())
        self.assertEqual([qT], q1T.transitions['a'])
        self.assertEqual([q2T], q1T.transitions['b'])
        self.assertEqual(symbols, q2T.transitions.keys())
        self.assertEqual([q2T], q2T.transitions['a'])
        self.assertEqual([q2T], q2T.transitions['b'])
        self.assertEqual(symbols, qT.transitions.keys())
        self.assertEqual([qT], qT.transitions['a'])
        self.assertEqual([qT], qT.transitions['b'])
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:35,代码来源:test_models.py


示例20: test_accept__ejemplo_enunciado

    def test_accept__ejemplo_enunciado(self):
        q0 = Node('q0')
        q1 = Node('q1')
        q2 = Node('q2')
        symbols = ['a', 'b', 'c', 'd', 'e', 'f']

        q0.add_transition('a', q1)
        q1.add_transition('b', q2)
        q1.add_transition('c', q1)
        q2.add_transition('f', q2)

        tested = Automata([q0, q1, q2], symbols, q0, [q1, q2])

        self.assertTrue(tested.accepts("a"))
        self.assertTrue(tested.accepts("ac"))
        self.assertTrue(tested.accepts("accc"))
        self.assertTrue(tested.accepts("ab"))
        self.assertTrue(tested.accepts("acccb"))
        self.assertTrue(tested.accepts("acccbf"))
        self.assertTrue(tested.accepts("acccbfff"))
        self.assertFalse(tested.accepts(""))
        self.assertFalse(tested.accepts("b"))
        self.assertFalse(tested.accepts("c"))
        self.assertFalse(tested.accepts("d"))
        self.assertFalse(tested.accepts("e"))
        self.assertFalse(tested.accepts("f"))
        self.assertFalse(tested.accepts("Z"))
        self.assertFalse(tested.accepts("abb"))
        self.assertFalse(tested.accepts("af"))
        self.assertFalse(tested.accepts("acca"))
开发者ID:llazzaro,项目名称:tleng_tp1,代码行数:30,代码来源:test_ejercicio_b.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Note类代码示例发布时间:2022-05-27
下一篇:
Python models.News类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap