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


Python Node.save方法代码示例

本文整理汇总了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)
开发者ID:Contexte,项目名称:django-tree,代码行数:27,代码来源:views.py

示例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
开发者ID:BGCX067,项目名称:ezride-svn-to-git,代码行数:30,代码来源:views.py

示例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
开发者ID:justelex,项目名称:Findeco,代码行数:11,代码来源:factory.py

示例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
        )
开发者ID:RANUX,项目名称:django-fktree,代码行数:12,代码来源:tests.py

示例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})
开发者ID:ArchanPatel890,项目名称:SpaceBubbles,代码行数:14,代码来源:api.py

示例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
开发者ID:Qwlouse,项目名称:Findeco,代码行数:15,代码来源:factory.py

示例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
开发者ID:FrankWalle,项目名称:Findeco,代码行数:15,代码来源:factory.py

示例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
开发者ID:Qwlouse,项目名称:Findeco,代码行数:18,代码来源:factory.py

示例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
开发者ID:TZer0,项目名称:devilry-django,代码行数:22,代码来源:testhelper.py

示例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")
开发者ID:Contexte,项目名称:django-tree,代码行数:40,代码来源:views.py

示例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()
开发者ID:chjpark14,项目名称:mapcampus,代码行数:20,代码来源:tests.py

示例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
开发者ID:FrankWalle,项目名称:Findeco,代码行数:8,代码来源:factory.py

示例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
开发者ID:Amadiro,项目名称:devilry-django,代码行数:85,代码来源:testhelpers.py

示例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
开发者ID:Qwlouse,项目名称:Findeco,代码行数:6,代码来源:factory.py

示例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)
开发者ID:RANUX,项目名称:django-fktree,代码行数:6,代码来源:tests.py


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