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


Python Plot.current_tree方法代码示例

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


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

示例1: commit_row

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import current_tree [as 别名]
    def commit_row(self):
        is_valid = self.validate_row()

        if not is_valid:
            return  # not ready to commit

        if self.status == TreeImportRow.SUCCESS:
            return  # nothing changed so no need to commit

        # Get our data
        data = self.cleaned

        self.convert_units(data, {
            fields.trees.PLOT_WIDTH:
            self.import_event.plot_width_conversion_factor,

            fields.trees.PLOT_LENGTH:
            self.import_event.plot_length_conversion_factor,

            fields.trees.DIAMETER:
            self.import_event.diameter_conversion_factor,

            fields.trees.TREE_HEIGHT:
            self.import_event.tree_height_conversion_factor,

            fields.trees.CANOPY_HEIGHT:
            self.import_event.canopy_height_conversion_factor
        })

        plot_id = data.get(self.model_fields.OPENTREEMAP_PLOT_ID, None)

        # Check for an existing plot, use it if we're not already:
        if plot_id and (self.plot is None or self.plot.pk != plot_id):
            plot = Plot.objects.get(pk=plot_id)
        elif self.plot is not None:
            plot = self.plot
        else:
            plot = Plot(instance=self.import_event.instance)

        self._commit_plot_data(data, plot)

        # TREE_PRESENT handling:
        #   If True, create a tree
        #   If False, don't create a tree
        #   If empty or missing, create a tree if a tree field is specified
        tree = plot.current_tree()
        tree_edited = False
        tree_present = data.get(self.model_fields.TREE_PRESENT, None)
        if tree_present:
            tree_edited = True
            if tree is None:
                tree = Tree(instance=plot.instance)

        if tree_present or tree_present is None:
            self._commit_tree_data(data, plot, tree, tree_edited)

        self.plot = plot
        self.status = TreeImportRow.SUCCESS
        self.save()
开发者ID:nvh3010,项目名称:otm-core,代码行数:61,代码来源:trees.py

示例2: commit_row

# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import current_tree [as 别名]
    def commit_row(self):
        # If this row was already commit... abort
        if self.plot:
            self.status = TreeImportRow.SUCCESS
            self.save()

        # First validate
        if not self.validate_row():
            return False

        # Get our data
        data = self.cleaned

        self.convert_units(data, {
            fields.trees.PLOT_WIDTH:
            self.import_event.plot_width_conversion_factor,

            fields.trees.PLOT_LENGTH:
            self.import_event.plot_length_conversion_factor,

            fields.trees.DIAMETER:
            self.import_event.diameter_conversion_factor,

            fields.trees.TREE_HEIGHT:
            self.import_event.tree_height_conversion_factor,

            fields.trees.CANOPY_HEIGHT:
            self.import_event.canopy_height_conversion_factor
        })

        # We need the import event from treemap.models
        # the names of things are a bit odd here but
        # self.import_event ->
        #   TreeImportEvent (importer) ->
        #     ImportEvent (treemap)
        #
        base_treemap_import_event = self.import_event.base_import_event

        plot_edited = False
        tree_edited = False

        # Initially grab plot from row if it exists
        plot = self.plot
        if plot is None:
            plot = Plot(present=True)

        # Event if TREE_PRESENT is None, a tree
        # can still be spawned here if there is
        # any tree data later
        tree = plot.current_tree()

        # Check for an existing tree:
        if self.model_fields.OPENTREEMAP_ID_NUMBER in data:
            plot = Plot.objects.get(
                pk=data[self.model_fields.OPENTREEMAP_ID_NUMBER])
            tree = plot.current_tree()
        else:
            if data.get(self.model_fields.TREE_PRESENT, False):
                tree_edited = True
                if tree is None:
                    tree = Tree(present=True)

        data_owner = self.import_event.owner

        for modelkey, importdatakey in TreeImportRow.PLOT_MAP.iteritems():
            importdata = data.get(importdatakey, None)

            if importdata:
                plot_edited = True
                setattr(plot, modelkey, importdata)

        if plot_edited:
            plot.last_updated_by = data_owner
            plot.import_event = base_treemap_import_event
            plot.save()

        for modelkey, importdatakey in TreeImportRow.TREE_MAP.iteritems():
            importdata = data.get(importdatakey, None)

            if importdata:
                tree_edited = True
                if tree is None:
                    tree = Tree(present=True)
                setattr(tree, modelkey, importdata)

        if tree_edited:
            tree.last_updated_by = data_owner
            tree.import_event = base_treemap_import_event
            tree.plot = plot
            tree.save()

        self.plot = plot
        self.status = TreeImportRow.SUCCESS
        self.save()

        return True
开发者ID:OpenTreeMap,项目名称:otm-legacy,代码行数:98,代码来源:models.py


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