本文整理汇总了Python中nodeshot.core.nodes.models.Node.add_validation_method方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add_validation_method方法的具体用法?Python Node.add_validation_method怎么用?Python Node.add_validation_method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nodeshot.core.nodes.models.Node
的用法示例。
在下文中一共展示了Node.add_validation_method方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ValidationError
# 需要导入模块: from nodeshot.core.nodes.models import Node [as 别名]
# 或者: from nodeshot.core.nodes.models.Node import add_validation_method [as 别名]
if not self.pk and not self.layer.new_nodes_allowed:
raise ValidationError(_('New nodes are not allowed for this layer'))
except ObjectDoesNotExist:
# this happens if node.layer is None
return
# TODO: thes features must be tested inside the layer's app code (nodeshot.core.layers.tests)
def node_layer_validation(self):
"""
1. if minimum distance is specified, ensure node is not too close to other nodes;
2. if layer defines an area, ensure node coordinates are contained in the area
"""
try:
minimum_distance = self.layer.minimum_distance
geometry = self.geometry
layer_area = self.layer.area
except ObjectDoesNotExist:
# this happens if node.layer is None
return
# TODO - lower priority: do this check only when coordinates are changing
if minimum_distance > 0:
near_nodes = Node.objects.exclude(pk=self.id).filter(geometry__distance_lte=(geometry, D(m=minimum_distance))).count()
if near_nodes > 0 :
raise ValidationError(_('Distance between nodes cannot be less than %s meters') % minimum_distance)
if layer_area is not None and not layer_area.contains(geometry):
raise ValidationError(_('Node must be inside layer area'))
Node.add_validation_method(new_nodes_allowed_for_layer)
Node.add_validation_method(node_layer_validation)
示例2: ValidationError
# 需要导入模块: from nodeshot.core.nodes.models import Node [as 别名]
# 或者: from nodeshot.core.nodes.models.Node import add_validation_method [as 别名]
ensure new nodes are allowed for this layer
"""
if not self.pk and self.layer and not self.layer.new_nodes_allowed:
raise ValidationError(_('New nodes are not allowed for this layer'))
def nodes_minimum_distance_validation(self):
"""
if minimum distance is specified, ensure node is not too close to other nodes;
"""
if self.layer and self.layer.nodes_minimum_distance:
minimum_distance = self.layer.nodes_minimum_distance
# TODO - lower priority: do this check only when coordinates are changing
near_nodes = Node.objects.exclude(pk=self.id).filter(geometry__distance_lte=(self.geometry, D(m=minimum_distance))).count()
if near_nodes > 0:
raise ValidationError(_('Distance between nodes cannot be less than %s meters') % minimum_distance)
def node_contained_in_layer_area_validation(self):
"""
if layer defines an area, ensure node coordinates are contained in the area
"""
# if area is a polygon ensure it contains the node
if self.layer and isinstance(self.layer.area, Polygon) and not self.layer.area.contains(self.geometry):
raise ValidationError(_('Node must be inside layer area'))
Node.add_validation_method(new_nodes_allowed_for_layer)
Node.add_validation_method(nodes_minimum_distance_validation)
Node.add_validation_method(node_contained_in_layer_area_validation)