本文整理汇总了Python中models.Node.save方法的典型用法代码示例。如果您正苦于以下问题:Python Node.save方法的具体用法?Python Node.save怎么用?Python Node.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Node
的用法示例。
在下文中一共展示了Node.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
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: persist_graph
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def persist_graph(request, graph_id):
import pygraphviz as P
import networkx as N
graph = Graph.objects.get(pk=graph_id)
dot_path = graph.dot_file.storage.location + '/' + graph.dot_file.name
G = P.AGraph() # init empty graph
try:
G.read(dot_path) #read file
nodes = G.nodes()
edges = G.edges()
Node.objects.filter(graph__id=graph_id).delete()
Edge.objects.filter(graph__id=graph_id).delete()
for node in nodes:
new_node = Node()
new_node.graph = graph
new_node.name = node
new_node.label = node.attr['label']
new_node.save()
for edge in edges:
new_edge = Edge()
new_edge.graph = graph
new_edge.name = edge
new_edge.save()
except:
return False
return HttpResponse(pygraphviz_graph(request, G)) #response
示例3: create_structureNode
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
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
示例4: test_build_child_tree_path
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
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
)
示例5: post
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def post(self):
if not (session and session.get('uid')):
return jsonify({'error': 'Not logged in'})
node = Node(title=request.form['title'])
node.url = request.form['url']
node.score = 1
node.save()
space = Space.objects(id=ObjectId(request.form['sid']))[0]
space.nodes.append(node)
space.save(cascade=True)
return jsonify({'success':1})
示例6: create_textNode
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def create_textNode(long_title, text="", authors=()):
text_node = Node()
text_node.node_type = Node.STRUCTURE_NODE
text_node.title = long_title
text_node.save()
text_obj = Text()
text_obj.node = text_node
text_obj.text = text
text_obj.save()
for author in authors:
text_obj.authors.add(author)
text_obj.save()
return text_node
示例7: create_structureNode
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def create_structureNode(long_title, text="", authors=()):
structure = Node()
structure.node_type = 'structureNode'
structure.title = long_title
structure.save()
text_obj = Text()
text_obj.node = structure
text_obj.text = text
text_obj.save()
for author in authors:
text_obj.authors.add(author)
text_obj.save()
return structure
示例8: create_structureNode
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def create_structureNode(long_title, text="", authors=(), validate=False):
if validate and not valid_title.match(long_title):
raise ValueError('Invalid title "{}"'.format(long_title))
if validate:
head = general_heading.match(text)
if head is not None:
raise ValueError('Headings are not allowed in text: {}'
.format(head.group()))
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
示例9: _create_or_add_node
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def _create_or_add_node(self, parent, name, users):
node = Node(parentnode=parent, short_name=name, long_name=name.capitalize())
try:
node.full_clean()
node.save()
except ValidationError:
node = Node.objects.get(parentnode=parent, short_name=name)
# allowed roles in node are:
for admin in users['admin']:
node.admins.add(self._create_or_add_user(admin))
if users['ln']:
node.long_name = users['ln'][0]
node.full_clean()
node.save()
vars(self)[node.get_path().replace('.', '_')] = node
return node
示例10: get
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def get(self,request, *args, **kwargs):
parent = None
if kwargs.get('pk',None) is not None:
parent = self.get_object()
children = parent.get_children()
else:
children = Node.objects.filter(parent=None)
if children.count() == 0:
node = Node(name="root")
node.save()
children = [node]
json = []
for child in children:
json.append({
'name' : child.name,
'icon' : 'default',
'loaded' : child.is_leaf_node(),
'pk' : child.pk,
'children' : [],
'parent' : child.parent.pk if child.parent is not None else None
})
if not child.is_leaf_node():
json[-1]['children'] = [{
'name' : "Loading",
'icon' : "loading"
}]
return HttpResponse(simplejson.dumps(json), content_type="application/json")
示例11: setUp
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def setUp(self):
new_york = Node(name='new york', coordinates=Point(40, 73))
austin = Node(name='austin', coordinates=Point(30, 97))
san_fran = Node(name='san fran', coordinates=Point(37, 122))
chicago = Node(name='chicago', coordinates=Point(41, 87))
new_york.save()
austin.save()
san_fran.save()
chicago.save()
Edge(node_src=new_york, node_sink=chicago).save()
Edge(node_src=chicago, node_sink=san_fran).save()
Edge(node_src=new_york, node_sink=austin).save()
Edge(node_src=austin, node_sink=san_fran).save()
Edge(node_src=san_fran, node_sink=new_york).save()
示例12: create_slot
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def create_slot(short_title):
slot = Node()
slot.node_type = 'slot'
slot.title = short_title
slot.save()
return slot
示例13: create_from_path
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def create_from_path(path):
""" Create a Node, Subject, Period, Assignment or AssignmentGroup from
``path``.
Examples::
assignmentgroup = create_from_path(
'ifi:inf1100.spring05.oblig1.student1,student2')
oblig1 = create_from_path(
'ifi:inf1100.spring05.oblig1')
"""
split = path.split(':', 1)
nodes = split[0].split('.')
for nodename in nodes:
node = Node(short_name=nodename, long_name=nodename.capitalize())
try:
node.clean()
node.save()
except:
node = Node.objects.get(short_name=nodename)
last = node
if len(split) != 2:
return last
pathsplit = split[1].split('.')
# Subject
subjectname = pathsplit[0]
subject = Subject(parentnode=node, short_name=subjectname,
long_name=subjectname.capitalize())
try:
subject.clean()
subject.save()
except:
subject = Subject.objects.get(short_name=subjectname)
last = subject
# Period
if len(pathsplit) > 1:
periodname = pathsplit[1]
period = Period(parentnode=subject, short_name=periodname,
long_name=periodname.capitalize(), start_time=datetime.now(),
end_time=datetime.now() + timedelta(10))
try:
period.clean()
period.save()
except:
period = Period.objects.get(parentnode=subject,
short_name=periodname)
last = period
# Assignment
if len(pathsplit) > 2:
assignmentname = pathsplit[2]
assignment = Assignment(parentnode=period, short_name=assignmentname,
long_name=assignmentname.capitalize(), publishing_time=datetime.now())
assignment.clean()
try:
assignment.save()
except:
assignment = Assignment.objects.get(parentnode=period,
short_name=assignmentname)
last = assignment
# Candidates
if len(pathsplit) > 3:
usernames = pathsplit[3].split(',')
users = []
for u in usernames:
user = User(username=u)
try:
user.save()
except:
user = User.objects.get(username=u)
users.append(user)
assignment_group = AssignmentGroup(parentnode=assignment)
assignment_group.clean()
assignment_group.save()
for user in users:
assignment_group.candidates.add(Candidate(student=user))
last = assignment_group
return last
示例14: create_slot
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def create_slot(short_title):
slot = Node(node_type=Node.SLOT, title=short_title)
slot.save()
return slot
示例15: test_skip_tree_path
# 需要导入模块: from models import Node [as 别名]
# 或者: from models.Node import save [as 别名]
def test_skip_tree_path(self):
node = Node()
node.save(skip_tree_path=True)
self.assertEquals('', node.tree_path)