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


Python Node.layer_name方法代码示例

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


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

示例1: get_nodes

# 需要导入模块: from nodeshot.core.nodes.models import Node [as 别名]
# 或者: from nodeshot.core.nodes.models.Node import layer_name [as 别名]
 def get_nodes(self, class_name, params):
     """ get nodes """
     # determine if response is going to be JSON or GeoJSON
     if 'geojson' in class_name.lower():
         response_format = 'geojson'
         SerializerClass = OpenLaborGeoSerializer
     else:
         response_format = 'json'
         SerializerClass = OpenLaborSerializer
     
     layer_name = self.layer.name
     cache_key = 'layer_%s_nodes.%s' % (self.layer.id, response_format)
     serialized_nodes = cache.get(cache_key, False)
     
     if serialized_nodes is False:            
         try:
             response = requests.get(
                 self.get_url,
                 verify=self.config.get('verify_SSL', True)
             )
         except requests.exceptions.ConnectionError as e:
             return {
                 'error': _('external layer not reachable'),
                 'exception': list(e.message)
             }
         
         try:
             response.data = json.loads(response.content)
         except json.scanner.JSONDecodeError as e:
             return {
                 'error': _('external layer is experiencing some issues because it returned invalid data'),
                 'exception': list(e)
             }
         
         nodes = []
         
         # loop over all the entries and convert to nodeshot format
         for job in response.data:
             # skip records which do not have geographic information
             if not job.get('latitude', False) or not job.get('longitude', False):
                 continue
             # convert response in nodeshot format
             node_dictionary = self.to_nodeshot(job)
             # create Node model instance (needed for rest_framework serializer)
             node = Node(**node_dictionary)
             node.layer_name = layer_name  # hack to avoid too many queries to get layer name each time
             nodes.append(node)
         
         # serialize with rest framework to achieve consistency
         serialized_nodes = SerializerClass(nodes, many=True).data
         cache.set(cache_key, serialized_nodes, 86400)  # cache for 1 day
     
     return serialized_nodes
开发者ID:CristianCantoro,项目名称:nodeshot,代码行数:55,代码来源:OpenLabor.py


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