本文整理汇总了Python中treemap.models.Plot.convert_to_display_units方法的典型用法代码示例。如果您正苦于以下问题:Python Plot.convert_to_display_units方法的具体用法?Python Plot.convert_to_display_units怎么用?Python Plot.convert_to_display_units使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.Plot
的用法示例。
在下文中一共展示了Plot.convert_to_display_units方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assert_plot_length_context_value
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import convert_to_display_units [as 别名]
def assert_plot_length_context_value(self, user, name, value, template_fn=None):
if template_fn is None:
template_fn = self._form_template_with_request_user_for if user else self._form_template_for
plot = Plot(length=12.3, instance=self.instance)
plot.convert_to_display_units()
template = template_fn("plot.length")
self._write_field_template("{{" + name + "}}")
with self.settings(TEMPLATE_DIRS=(self.template_dir,)):
content = template.render(
Context({"request": {"user": user, "instance": self.instance}, "plot": plot})
).strip()
self.assertEqual(content, value)
示例2: ConvertibleTest
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import convert_to_display_units [as 别名]
class ConvertibleTest(OTMTestCase):
def setUp(self):
self.instance = make_instance()
self.user = make_commander_user(self.instance)
self.plot = Plot(instance=self.instance, geom=self.instance.center)
self.plot.save_with_user(self.user)
self.tree = Tree(instance=self.instance, plot=self.plot)
self.tree.save_with_user(self.user)
def test_save_converts_width_when_units_differ(self):
set_attr_on_json_field(
self.instance, 'config.value_display.plot.width.units', 'in')
self.plot.convert_to_display_units()
self.plot.width = 12
self.plot.convert_to_database_units()
self.plot.save_with_user(self.user)
updated_plot = Plot.objects.get(pk=self.plot.pk)
self.assertAlmostEqual(1, updated_plot.width)
def test_save_converts_diameter_when_units_differ(self):
set_attr_on_json_field(
self.instance, 'config.value_display.tree.diameter.units', 'ft')
self.tree.convert_to_display_units()
self.tree.diameter = 1
self.tree.convert_to_database_units()
self.tree.save_with_user(self.user)
updated_tree = Tree.objects.get(pk=self.tree.pk)
self.assertAlmostEqual(12, updated_tree.diameter)
def test_save_does_not_convert_width_when_units_same(self):
set_attr_on_json_field(
self.instance, 'config.value_display.plot.width.units', 'ft')
self.plot.width = 12
self.plot.save_with_user(self.user)
updated_plot = Plot.objects.get(pk=self.plot.pk)
self.assertEqual(12, updated_plot.width)
def test_save_does_not_convert_diameter_when_units_same(self):
set_attr_on_json_field(
self.instance, 'config.value_display.tree.diameter.units', 'in')
self.tree.diameter = 1
self.tree.save_with_user(self.user)
updated_tree = Tree.objects.get(pk=self.tree.pk)
self.assertEqual(1, updated_tree.diameter)