本文整理汇总了Python中models.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
示例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)
示例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)
示例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())
示例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
示例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)
示例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)
示例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())
示例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()
示例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
示例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)
示例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())
示例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]))
示例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])