當前位置: 首頁>>代碼示例>>Python>>正文


Python Node.id方法代碼示例

本文整理匯總了Python中nodeshot.core.nodes.models.Node.id方法的典型用法代碼示例。如果您正苦於以下問題:Python Node.id方法的具體用法?Python Node.id怎麽用?Python Node.id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nodeshot.core.nodes.models.Node的用法示例。


在下文中一共展示了Node.id方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process_streets

# 需要導入模塊: from nodeshot.core.nodes.models import Node [as 別名]
# 或者: from nodeshot.core.nodes.models.Node import id [as 別名]
    def process_streets(self):
        if not self.streets:
            self.message = """
            Street data not processed.
            """
            return False
        # retrieve all items
        items = self.streets

        # init empty lists
        added_nodes = []
        changed_nodes = []
        unmodified_nodes = []

        # retrieve a list of local nodes in DB
        local_nodes_slug = Node.objects.filter(layer=self.layer).values_list('slug', flat=True)
        # init empty list of slug of external nodes that will be needed to perform delete operations
        external_nodes_slug = []
        deleted_nodes_count = 0

        try:
            self.status = Status.objects.get(slug=self.config.get('status', None))
        except Status.DoesNotExist:
            self.status = None

        # loop over every parsed item
        for item in items:
            # retrieve info in auxiliary variables
            # readability counts!
            pk = item['id']
            name = item['properties'].get('LOCATION', '')[0:70]
            address = name
            slug = slugify(name)

            number = 1
            original_name = name
            needed_different_name = False

            while True:
                # items might have the same name... so we add a number..
                # check in DB too
                if slug in external_nodes_slug or Node.objects.filter(slug__exact=slug).exclude(pk=pk).count() > 0:
                    needed_different_name = True
                    number = number + 1
                    name = "%s - %d" % (original_name, number)
                    slug = slug = slugify(name)
                else:
                    if needed_different_name:
                        self.verbose('needed a different name for %s, trying "%s"' % (original_name, name))
                    break

            # geometry object
            geometry = GEOSGeometry(json.dumps(item["geometry"]))

            # default values
            added = False
            changed = False

            try:
                # edit existing node
                node = Node.objects.get(pk=pk)
            except Node.DoesNotExist:
                # add a new node
                node = Node()
                node.id = pk
                node.layer = self.layer
                node.status = self.status
                node.data = {}
                added = True

            if node.name != name:
                node.name = name
                changed = True

            if node.slug != slug:
                node.slug = slug
                changed = True

            if added is True or node.geometry.equals(geometry) is False:
                node.geometry = geometry
                changed = True

            if node.address != address:
                node.address = address
                changed = True

            # perform save or update only if necessary
            if added or changed:
                try:
                    node.full_clean()
                    node.save()
                except ValidationError as e:
                    raise Exception("%s errors: %s" % (name, e.messages))

            if added:
                added_nodes.append(node)
                self.verbose('new node saved with name "%s"' % node.name)
            elif changed:
                changed_nodes.append(node)
                self.verbose('node "%s" updated' % node.name)
#.........這裏部分代碼省略.........
開發者ID:nemesisdesign,項目名稱:nodeshot-citysdk-synchronizers,代碼行數:103,代碼來源:provincerometraffic.py


注:本文中的nodeshot.core.nodes.models.Node.id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。