當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。