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


Python Node.added方法代码示例

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


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

示例1: import_nodes

# 需要导入模块: from nodeshot.core.nodes.models import Node [as 别名]
# 或者: from nodeshot.core.nodes.models.Node import added [as 别名]
    def import_nodes(self):
        """ import nodes into local DB """
        self.message('saving nodes into local DB...')

        saved_nodes = []

        # loop over all old node and create new nodes
        for old_node in self.old_nodes:
            # if this old node is unconfirmed skip to next cycle
            if old_node.status == 'u':
                continue

            try:
                node = Node.objects.get(pk=old_node.id)
            except Node.DoesNotExist:
                node = Node(id=old_node.id)
                node.data = {}

            node.user_id = self.users_dict[old_node.email]['id']
            node.name = old_node.name
            node.slug = old_node.slug
            node.geometry = Point(old_node.lng, old_node.lat)
            node.elev = old_node.alt
            node.description = old_node.description
            node.notes = old_node.notes
            node.added = old_node.added
            node.updated = old_node.updated
            node.data['imported'] = 'true'

            intersecting_layers = node.intersecting_layers
            # if more than one intersecting layer
            if len(intersecting_layers) > 1:
                # prompt user
                answer = self.prompt_layer_selection(node, intersecting_layers)
                if isinstance(answer, int):
                    node.layer_id = answer
                elif answer == 'default' and self.default_layer is not False:
                    node.layer_id = self.default_layer
                else:
                    self.message('Node %s discarded' % node.name)
                    continue
            # if one intersecting layer select that
            elif 2 > len(intersecting_layers) > 0:
                node.layer = intersecting_layers[0]
            # if no intersecting layers
            else:
                if self.default_layer is False:
                    # discard node if no default layer specified
                    self.message("""Node %s discarded because is not contained
                                 in any specified layer and no default layer specified""" % node.name)
                    continue
                else:
                    node.layer_id = self.default_layer

            if old_node.postal_code:
                # additional info
                node.data['postal_code'] = old_node.postal_code

            # is it a hotspot?
            if old_node.status in ['h', 'ah']:
                node.data['is_hotspot'] = 'true'

            # determine status according to settings
            if self.status_mapping:
                node.status_id = self.get_status(old_node.status)

            try:
                node.full_clean()
                node.save(auto_update=False)
                saved_nodes.append(node)
                self.verbose('Saved node %s in layer %s with status %s' % (node.name, node.layer, node.status.name))
            except Exception:
                tb = traceback.format_exc()
                self.message('Could not save node %s, got exception:\n\n%s' % (node.name, tb))

        self.message('saved %d nodes into local DB' % len(saved_nodes))
        self.saved_nodes = saved_nodes
开发者ID:PabloCastellano,项目名称:nodeshot,代码行数:79,代码来源:import_old_nodeshot.py


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