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


Python Node.add_validation_method方法代码示例

本文整理汇总了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)
开发者ID:CristianCantoro,项目名称:nodeshot,代码行数:33,代码来源:layer.py

示例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)
开发者ID:Shvend,项目名称:nodeshot,代码行数:32,代码来源:layer.py


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